Release DSP Memory

Hi,

I am having an issue with releasing DSP.

When playing a sound and creating a channel I create a DSP like this:

FMOD::DSP *dsp = 0;
_system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT, &dsp);
dsp->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, pitchShift);
dsp->setParameterFloat(FMOD_DSP_PITCHSHIFT_FFTSIZE, 1024));
channel->addDSP(0, dsp);

Then when the channel stops in the callback I do this:

FMOD::DSP* dsp = nullptr;
FMOD_RESULT result = channel->getDSP(0, &dsp);
if (result == FMOD_OK && dsp != nullptr) {
channel->removeDSP(dsp);
dsp->release();
}

I get no errors, added extra FMOD_RESULT checks and nothing fails. No other DSP are added to the channel, and the DSP count is 1 before and after I call removeDSP. The memory usage just keeps going up as more and more sound effects are played. What am I missing? Thanks!

Was able to somewhat solve it. When the channel finished playing and the callback was called the channel dsp count was 1. However when I checked the DSP in the channel the DSP at index 0 was FMOD_DSP_TYPE_FADER.

So for some reason add fadepoint or delay overwrites the FMOD_DSP_TYPE_PITCHSHIFT I had placed at index 0?

Solved it by saving the pitchshift DSP in an external map linked to the channel, and fetching and releasing the DSP from the map when the channel finished. No more memory leak for now but not sure whats going on internally with adddsp/index.

I haven’t been able to reproduce this issue, and am finding that addDSP, getDSP and removeDSP are all behaving as expected in the latest version of FMOD. I can’t determine what the relationship to fade points would be either. Can you please tell me what version of FMOD you are using?

Hi,

FMOD version 20219.

Things have been stable now that I manually save the DSP in an external map. Maybe I shouldnt add the Pitchshift at index 0?

Code where the channel is setup:

_result = _system->playSound(sound->_sound, getChannelGroup(sfxGroupID, useReverb), true, &channel);
	ERRCHECK(_result);
    
    if (_result == FMOD_OK) {
		channel->setPitch(pitch);
		channel->setVolume(volume);
		if (loop) channel->setLoopCount(-1);
		
		FMOD::DSP *dsp = nullptr;

		if (pitchShift > 0 && pitchShift != 1.0f) {
			_system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT, &dsp);
			dsp->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, pitchShift);

			dsp->setParameterFloat(FMOD_DSP_PITCHSHIFT_FFTSIZE, (increasePitchFFT ? 2048 : 1024));

			channel->addDSP(0, dsp);
		}

Stashing your dsp pointer in a map seems reasonable.

If the FMOD system adds more dsps to the channel (e.g. FMOD_DSP_TYPE_FADER), that will affect the indices of everything in the dsp chain i.e. each time a DSP is added at index 0, it pushes everything else in the DSP chain down the list. Hope that makes sense.

Hi,

For now it works so all good thanks.

Only strange thing with pushing the DSP down the list. This is the code I run when the channel is finished, but it only returned numDSPs = 1 (the Fader). This is before I release the PitchShift via the external map.

    // Release any dsp
	// Get the number of DSPs attached to the channel
	int numDSPs = 0;
	FMOD_RESULT result = channel->getNumDSPs(&numDSPs);

	// Iterate over all DSPs and release them
	for (int i = 0; i < numDSPs; ++i) {
		FMOD::DSP* dsp = nullptr;
		channel->getDSP(i, &dsp);
		if (dsp != nullptr) {
			channel->removeDSP(dsp);
			dsp->release();
		}
	}