Guest User

Untitled

a guest
Nov 22nd, 2026
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.92 KB | Source Code | 0 0
  1. #pragma once
  2.  
  3. #include "CoreMinimal.h"
  4. #include "Sound/SoundEffectSource.h"
  5. #include "MiVOIPSoundEffectSource.generated.h"
  6.  
  7. // ========================================================================
  8. // FMiVOIPSoundEffectSourceSettings
  9. // This is the source effect's setting struct.
  10. // ========================================================================
  11.  
  12. USTRUCT(BlueprintType)
  13. struct FMiVOIPSoundEffectSourceSettings
  14. {
  15.     GENERATED_USTRUCT_BODY()
  16.  
  17.     // Volume attenuation in dB.
  18.     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SourceEffect|Preset", meta = (ClampMin = "-96.0", UIMin = "-96.0", UIMax = "10.0"))
  19.     float VolumeAttenuationDb;
  20.  
  21.     FMiVOIPSoundEffectSourceSettings()
  22.         : VolumeAttenuationDb(0.0f)
  23.     {}
  24. };
  25.  
  26. // ========================================================================
  27. // FMiVOIPSoundEffectSource
  28. // This is the instance of the source effect. Performs DSP calculations.
  29. // ========================================================================
  30.  
  31. class FMiVOIPSoundEffectSource : public FSoundEffectSource
  32. {
  33. public:
  34.     // Called on an audio effect at initialization on main thread before audio processing begins.
  35.     virtual void Init(const FSoundEffectSourceInitData& InInitData) override;
  36.    
  37.     // Called when an audio effect preset is changed
  38.     virtual void OnPresetChanged() override;
  39.  
  40.     // Process the input block of audio. Called on audio thread.
  41.     virtual void ProcessAudio(const FSoundEffectSourceInputData& InData, float* OutAudioBufferData) override;
  42.  
  43. protected:
  44.     // Attenuation of sound in linear units
  45.     float VolumeScale;
  46.  
  47.     int32 NumChannels;
  48. };
  49.  
  50. // ========================================================================
  51. // UMiVOIPSoundEffectSourcePreset
  52. // This code exposes your preset settings and effect class to the editor.
  53. // And allows for a handle to setting/updating effect settings dynamically.
  54. // ========================================================================
  55.  
  56. UCLASS(MinimalAPI, ClassGroup = AudioSourceEffect, meta = (BlueprintSpawnableComponent))
  57. class UMiVOIPSoundEffectSourcePreset : public USoundEffectSourcePreset
  58. {
  59.     GENERATED_BODY()
  60.  
  61. public:
  62.     // Macro which declares and implements useful functions.
  63.     EFFECT_PRESET_METHODS(MiVOIPSoundEffectSource)
  64.  
  65.     // Allows you to customize the color of the preset in the editor.
  66.     virtual FColor GetPresetColor() const override { return FColor(196.0f, 185.0f, 121.0f); }
  67.  
  68.     // Change settings of your effect from blueprints. Will broadcast changes to active instances.
  69.     UFUNCTION(BlueprintCallable, Category = "Audio|Effects")
  70.     void SetSettings(const FMiVOIPSoundEffectSourceSettings& InSettings);
  71.    
  72.     // The copy of the settings struct. Can't be written to in BP, but can be read.
  73.     // Note that the value read in BP is the serialized settings, will not reflect dynamic changes made in BP.
  74.     UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Audio|Effects")
  75.     FMiVOIPSoundEffectSourceSettings Settings;
  76. };
  77.  
Advertisement
Add Comment
Please, Sign In to add comment