steam-audio
steam-audio copied to clipboard
[C API] IPLDirectEffect fades in from silence
I'm experiencing an issue where sounds that I play in my game with the direct effect applied appear to fade in from silence. It is to my understanding that IPLDirectEffect
does internal smooth ramping of the input parameters over time. It appears that applying the effect for the first time on a newly created IPLDirectEffect
will cause it to ramp the parameters from whatever its initial state is, causing an unwanted fade in. Is there any way to make the effect "snap" to the input parameters the first time it is applied? A cheesy workaround I discovered is to, after first creating the effect, apply it multiple times on temporary buffers, to the get the internal state ramped up enough to the point where it's no longer noticeable, before applying the effect on the actual sound data.
Here's some code demonstrating the problem:
#include <phonon.h>
#include <iostream>
#include <assert.h>
int
main(int argc, char *argv[]) {
IPLContextSettings ctx_settings{};
ctx_settings.version = STEAMAUDIO_VERSION;
ctx_settings.simdLevel = IPL_SIMDLEVEL_AVX2;
IPLContext ctx = nullptr;
IPLerror err = iplContextCreate(&ctx_settings, &ctx);
assert(!err);
IPLAudioSettings audio_settings{};
audio_settings.samplingRate = 44100;
audio_settings.frameSize = 1024;
IPLDirectEffectSettings effect_settings{};
effect_settings.numChannels = 1;
IPLDirectEffect effect = nullptr;
err = iplDirectEffectCreate(ctx, &audio_settings, &effect_settings, &effect);
assert(!err);
IPLAudioBuffer in_buffer;
IPLAudioBuffer out_buffer;
err = iplAudioBufferAllocate(ctx, 1, 1024, &in_buffer);
assert(!err);
err = iplAudioBufferAllocate(ctx, 1, 1024, &out_buffer);
assert(!err);
for (int i = 0; i < 1024; ++i) {
in_buffer.data[0][i] = 100.0f;
}
IPLDirectEffectParams params{};
params.flags = IPL_DIRECTEFFECTFLAGS_APPLYDISTANCEATTENUATION;
params.distanceAttenuation = 1.0f;
for (int i = 0; i < 20; ++i) {
iplDirectEffectApply(effect, ¶ms, &in_buffer, &out_buffer);
std::cout << "First sample in out buffer: " << out_buffer.data[0][0] << "\n";
}
return 0;
}