Recalculating EAXEnvironment into BASS_DX8_REVERB

Started by DeepDigger,

DeepDigger

Dear experts,

How do I precisely convert EAX forest environment (0.111 volume, 3.145 decay, 0.472 damp) into BASS_DX8_REVERB structure (fReverbMix, fReverbTime, fHighFreqRTRatio)?

Thank you.

Ian @ un4seen

It won't be possible to emulate EAX environments with the BASS_FX_DX8_REVERB effect, as it has limited configurability, but you may have more luck with the BASS_FX_DX8_I3DL2REVERB effect. If you look in the DSOUND.H header, you will find presets corresponding to the EAX ones, eg. I3DL2_ENVIRONMENT_PRESET_FOREST. For example, you can use them in a BASS_FXSetParameters call like this:

BASS_DX8_I3DL2REVERB param = { I3DL2_ENVIRONMENT_PRESET_FOREST }; // "forest" preset parameters
BASS_FXSetParameters(revfx, &param); // apply the parameters

Note BASS_FX_DX8_I3DL2REVERB is only available on Windows. Also note that its output is 100% wet. If you want wet/dry control, you will need to implement that yourself. You can do so by using a "dummy" stream to apply the effect on a copy of the data and then mix that with the original data at the wanted levels. The copying/applying/mixing can be done in a DSPPROC callback. It could all look something like this:

BASS_CHANNELINFO info;
BASS_ChannelGetInfo(stream, &info); // get stream info
revstream = BASS_StreamCreate(info.freq, info.chans, info.flags | BASS_STREAM_DECODE, STREAMPROC_DUMMY, 0); // create dummy stream with same format
revfx = BASS_ChannelSetFX(revstream, BASS_FX_DX8_I3DL2REVERB, 0); // set I3DL2 reverb effect on it
BASS_DX8_I3DL2REVERB param = { I3DL2_ENVIRONMENT_PRESET_FOREST }; // "forest" preset parameters
BASS_FXSetParameters(revfx, &param); // apply the parameters
BASS_ChannelSetDSP(stream, ReverbDSP, 0, 0); // set DSP function to apply reverb on main stream

...

void CALLBACK ReverbDSP(HDSP handle, DWORD channel, void *buffer, DWORD length, void *user)
{
float *data = (float*)buffer;
float *temp = new float[length / sizeof(float)]; // temp array
memcpy(temp, data, length); // copy data to temp array
BASS_ChannelGetData(revstream, temp, length); // apply dummy stream's effect(s) to it
for (int a = 0; a < length / sizeof(float); a++)
data[a] = data[a] * dry + temp[a] * wet; // mix the dry and wet data
delete temp;
}

Note this is assuming that the BASS_SAMPLE_FLOAT flag is set on the stream, which I would recommend doing. Please see the documentation for details on the mentioned functions.

DeepDigger

DeepDigger

Could it be an idea for further development of BASS functionality?
It could be a remarkable feature - just to place a sound into specific environment.
 ???

Ian @ un4seen

There are currently no plans for EAX emulation, so I'm afraid it won't be in the next BASS release at least. It would be nice to have though, so I wouldn't totally rule it out for a future release if something can be worked out.

DeepDigger

"Windows 11 24H2 removed the I3DL2REVERB effect, so it should be avoided if you need to run on the latest Windows."
So could you please return to the topic of EAX emulation?

Ian @ un4seen

Unfortunately, there are still no plans for EAX emulation currently. You could try replacing BASS_FX_DX8_I3DL2REVERB with BASS_FX_DX8_REVERB, but it is quite limited. Note that its output includes the input/dry sound, so no need to add that like in the code I posted above.

A better option may be to use a third-party reverb effect, by having the ReverbDSP function feed the data through it. There's no need for the dummy stream (revstream) in that case.