jarikomppa / soloud

Free, easy, portable audio engine for games
http://soloud-audio.com
Other
1.69k stars 270 forks source link

Freeverb setParam doesn't change parameters. #316

Closed janEntikan closed 2 years ago

janEntikan commented 3 years ago

Bit of a newbie here, beware there is a good chance this is my own wrong-doing.

I'm trying to set the freeverb's parameters but no matter what values I pass the effect stays the same. Here's the code I'm using. Note that setting parameters on other filters (like Echo) seem to work fine for me.

#include <cstdio>
#include "soloud/soloud.h"
#include "soloud/soloud_speech.h"
#include "soloud/soloud_freeverbfilter.h"
#include "soloud/soloud_thread.h"

int main() {
    SoLoud::Soloud gSoloud;
    SoLoud::Bus gBus;
    SoLoud::Speech gSpeech;
    SoLoud::FreeverbFilter gFreeverb;

    gBus.setFilter(0, &gFreeverb);

    float frozen = 0;
    float room_size = 0.1;
    float damp = 0.1;
    float width = 1;

    printf("Setting reverb: %d\n",gFreeverb.setParams(frozen, room_size, damp, width));

    gSpeech.setText("I like peanutbutter and jelly sandwiches");
    gSpeech.setParams(2600, 14, 2, KW_SAW);

    gSoloud.init();
    gSoloud.play(gBus);
    gBus.play(gSpeech);

    while (gSoloud.getActiveVoiceCount() > 0) {
        SoLoud::Thread::sleep(1);
    }

    gSoloud.deinit();
    return 0;
}
Green-Sky commented 3 years ago

You are changing the values for the Filter AFTER the Filter-Instance has been created. You either want to call gFreeverb.setParams() before gBus.setFilter(0, &gFreeverb), OR if you want to be able to change Filter parameters on the fly, so on an Instance, you need to go through gSound.setFilterParameter(). iirc