Skip to main content
Version: 2.x

UOdinCustomEffect

Codec-Effect base for the odin audio pipeline. The effect does nothing by itself.

OdinCustomEffects registered with odin_pipeline_insert_custom_effect are executed in a native library caller thread of that codec pipeline and are blocking pop functions. The corresponding codec push function is not blocked. Heavy computational task in an effect will reduce performance.

Declaration
UCLASS(ClassGroup = Odin, Abstract, BlueprintType, Blueprintable)
class ODIN_API UOdinCustomEffect : public UObject
note

The audio pipeline execution context is started on a pop call, not push.

e.g: encoder/decoder odin_encoder_push -> BLOCKING(encoder audio pipeline/effects -> odin_encoder_pop)

Not affected is, including, but not limited to, IO and Event library threads

Writing your own effect​

Derive from UOdinCustomEffect and override CustomEffect. The pipeline calls it on the thread that pops the audio, not on the game thread: keep it fast, and dispatch anything else (UI, gameplay) to the game thread. Samples are 32-bit float, interleaved if the encoder or decoder is stereo. Set *bIsSilent to true to mark the buffer as silent for the following effects.

MyGainEffect.h
#include "OdinAudio/Effects/OdinCustomEffect.h"

#include "MyGainEffect.generated.h"

UCLASS()
class UMyGainEffect : public UOdinCustomEffect
{
GENERATED_BODY()

public:
UMyGainEffect(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}

virtual void CustomEffect(const TArrayView<float>& InSamples, bool*& bIsSilent,
TOdinCustomEffectUserData<UOdinCustomEffect>* const InUserData) const override
{
if (*bIsSilent)
return;
for (float& Sample : InSamples)
Sample *= Gain;
}

UPROPERTY(BlueprintReadWrite, Category = "Effect")
float Gain = 1.5f;
};

Insert the effect into a pipeline with UOdinPipeline::InsertCustomEffect:

UMyGainEffect* Effect = NewObject<UMyGainEffect>(this);
Encoder->GetOrCreatePipeline()->InsertCustomEffect(0, Effect);

Overview​

Functions​

NameDescription
CustomEffectCustom Effect callbacks with buffer or do nothing if is silent-data.
GetParent
SetParent
RemoveSelfFromParentRemoves the effect from the pipeline it was inserted into.

Properties​

NameDescription
IndexIndex of the effect in its pipeline.
EffectIdID of the effect in its pipeline.

Functions​

CustomEffect​

Virtual · Const

Custom Effect callbacks with buffer or do nothing if is silent-data. Override for a more useful implementation. *Care thread usage or dispatch to another!

virtual void CustomEffect(
const TArrayView<float>& InSamples,
bool*& bIsSilent,
TOdinCustomEffectUserData<UOdinCustomEffect>* const InUserData) const;
ParameterTypeDescription
InSamplesconst TArrayView<float>&raw f32 sample buffer
bIsSilentbool*&flag if sample buffer is considered silent
InUserDataTOdinCustomEffectUserData<UOdinCustomEffect>* constsending effect object (UOdinCustomEffect *)

GetParent​

Const · Inline

TWeakObjectPtr<UOdinPipeline> GetParent() const;

Returns TWeakObjectPtr<UOdinPipeline>

SetParent​

Inline

void SetParent(TWeakObjectPtr<UOdinPipeline> InPipeline);
ParameterTypeDescription
InPipelineTWeakObjectPtr<UOdinPipeline>

RemoveSelfFromParent​

Blueprint: Detach Effect

Removes the effect from the pipeline it was inserted into.

UFUNCTION(BlueprintCallable, Category = "Odin|Audio Pipeline")
bool RemoveSelfFromParent();

Returns bool – True if the effect was removed.

Properties​

Index​

Blueprint: Get

Index of the effect in its pipeline.

UPROPERTY(BlueprintReadOnly, Category = "Odin|Audio Pipeline|State")
int32 Index;

EffectId​

Blueprint: Get

ID of the effect in its pipeline.

UPROPERTY(BlueprintReadOnly, Category = "Odin|Audio Pipeline|State")
int32 EffectId;