# Release DSP Memory

**URL:** https://qa.fmod.com/t/release-dsp-memory/21036
**Category:** FMOD Engine
**Created:** [December 27, 2023, 5:58am UTC](https://qa.fmod.com/t/release-dsp-memory/21036 "2023-12-27T05:58:08Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![SeditQui](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@SeditQui](https://qa.fmod.com/u/SeditQui)
#### Post date: [December 27, 2023, 5:58am UTC](https://qa.fmod.com/t/release-dsp-memory/21036/1 "2023-12-27T05:58:08Z")

</div>

Hi,

I am having an issue with releasing DSP.

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

```auto
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:

```auto
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!

---

<div class="post-metadata">

### Author: ![SeditQui](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@SeditQui](https://qa.fmod.com/u/SeditQui)
#### Post date: [December 27, 2023, 7:37pm UTC](https://qa.fmod.com/t/release-dsp-memory/21036/2 "2023-12-27T19:37:27Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)
#### Post date: [January 1, 2024, 9:56pm UTC](https://qa.fmod.com/t/release-dsp-memory/21036/3 "2024-01-01T21:56:42Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![SeditQui](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@SeditQui](https://qa.fmod.com/u/SeditQui)
#### Post date: [January 3, 2024, 1:30pm UTC](https://qa.fmod.com/t/release-dsp-memory/21036/4 "2024-01-03T13:30:27Z")

</div>

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:

```auto
_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);
		}

```

---

<div class="post-metadata">

### Author: ![Andrew](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/andrew/32/261_2.png) [@Andrew](https://qa.fmod.com/u/Andrew)
#### Post date: [January 4, 2024, 1:04am UTC](https://qa.fmod.com/t/release-dsp-memory/21036/5 "2024-01-04T01:04:17Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![SeditQui](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@SeditQui](https://qa.fmod.com/u/SeditQui)
#### Post date: [January 4, 2024, 11:05am UTC](https://qa.fmod.com/t/release-dsp-memory/21036/6 "2024-01-04T11:05:16Z")

</div>

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.

```auto
    // 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();
		}
	}

```
