# FFT Spectrum nullPtr

**URL:** https://qa.fmod.com/t/fft-spectrum-nullptr/12242
**Category:** FMOD Engine
**Created:** [January 13, 2016, 5:32pm UTC](https://qa.fmod.com/t/fft-spectrum-nullptr/12242 "2016-01-13T17:32:50Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![international01](https://avatars.discourse-cdn.com/v4/letter/i/c0e974/32.png) [@international01](https://qa.fmod.com/u/international01)
#### Post date: [January 13, 2016, 5:32pm UTC](https://qa.fmod.com/t/fft-spectrum-nullptr/12242/1 "2016-01-13T17:32:50Z")

</div>

Hello there,  
Can you even look at my code something can not be right since .

I always bekomm the error message FFT what nullptr .

```
#pragma comment(lib,"fmod64_vc.lib")

using namespace std;

FMOD::System* fmodSystem;    
FMOD::Sound *music;
FMOD::Channel* musicChannel = 0;
FMOD_RESULT result;
FMOD::DSP *dsp1;
FMOD_DSP_PARAMETER_FFT *fft;

int fmodini()
{
	if (FAILED(result = FMOD::System_Create(&fmodSystem))) {
		MessageBox(NULL, "Failed", "Failed", MB_OK | MB_ICONEXCLAMATION);
	}

	if (FAILED(result = fmodSystem->init(32, FMOD_INIT_NORMAL, NULL))) {
		MessageBox(NULL, "Failed", "Failed", MB_OK | MB_ICONEXCLAMATION);
	}

	if (FAILED(result = fmodSystem->createStream("Hawaii5O.mp3", FMOD_DEFAULT, 0, &music))) {
		MessageBox(NULL, "Failed", "Failed", MB_OK | MB_ICONEXCLAMATION);
	}

	if (FAILED(result = fmodSystem->playSound(music, 0, false, &musicChannel))) {
		MessageBox(NULL, "Failed", "Failed", MB_OK | MB_ICONEXCLAMATION);
	}

	fmodSystem->createDSPByType(FMOD_DSP_TYPE::FMOD_DSP_TYPE_FFT, &dsp1);
	musicChannel->addDSP(FMOD_DSP_PARAMETER_DATA_TYPE_FFT, dsp1);
	dsp1->getParameterData(FMOD_DSP_FFT_SPECTRUMDATA, (void **)fft, 0, 0, 0);

	return 0;
}

```

Always in accessing the variable \* fft I get the error message .

---

<div class="post-metadata">

### Author: ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)
#### Post date: [January 13, 2016, 11:36pm UTC](https://qa.fmod.com/t/fft-spectrum-nullptr/12242/2 "2016-01-13T23:36:58Z")

</div>

As a rule you should check the return code of all FMOD functions.

Channel::addDSP will be returning INVALID\_PARAM because the first argument is wrong. It specifies the position in the DSP chain to add, not the DSP type.

Try

```
result = musicChannel->addDSP(FMOD_CHANNELCONTROL_DSP_HEAD, dsp1);

```

Which places the DSP at the head of the channels effect chain.

---

<div class="post-metadata">

### Author: ![international01](https://avatars.discourse-cdn.com/v4/letter/i/c0e974/32.png) [@international01](https://qa.fmod.com/u/international01)
#### Post date: [January 14, 2016, 4:08pm UTC](https://qa.fmod.com/t/fft-spectrum-nullptr/12242/3 "2016-01-14T16:08:42Z")

</div>

Thanks for the help.  
I have modified the code and have carried out a test  
the result.

float test = FFT \> lenght ;

result = FFT \> lenght \< Unable to read memory \>

result = FFT \> numChannels \< Unable to read memory \>

fft was nullptr.

---

<div class="post-metadata">

### Author: ![international01](https://avatars.discourse-cdn.com/v4/letter/i/c0e974/32.png) [@international01](https://qa.fmod.com/u/international01)
#### Post date: [January 14, 2016, 6:27pm UTC](https://qa.fmod.com/t/fft-spectrum-nullptr/12242/4 "2016-01-14T18:27:10Z")

</div>

OK thanks for the help.  
Have solved the problem .

When you enter this code  
result = dsp1- \> getParameterData ( FMOD\_DSP\_FFT\_SPECTRUMDATA , (void \*\* ) & FFT , 0 , 0 , 0 ) ;

Must be a ( & ) character before the pointer ( \* FFT ) are set .  
Without it does not go with me .

---

<div class="post-metadata">

### Author: ![international01](https://avatars.discourse-cdn.com/v4/letter/i/c0e974/32.png) [@international01](https://qa.fmod.com/u/international01)
#### Post date: [January 14, 2016, 8:56pm UTC](https://qa.fmod.com/t/fft-spectrum-nullptr/12242/5 "2016-01-14T20:56:22Z")

</div>

I need a little help again .

I get all zeros as output .

if (FAILED(result = dsp1-\>getParameterData(FMOD\_DSP\_FFT\_SPECTRUMDATA, (void \*\*)&fft, 0, 0, 0))) {  
MessageBox(NULL, “Failed”, “Failed”, MB\_OK | MB\_ICONEXCLAMATION);  
}

```
for (int channel = 0; channel < fft->numchannels; channel++) {
	for (int lenght = 0; lenght < fft->length; lenght++) {
		fmoddata = fft->spectrum[channel][lenght];
	}
}

result=fmodSystem->update();
```

---

<div class="post-metadata">

### Author: ![international01](https://avatars.discourse-cdn.com/v4/letter/i/c0e974/32.png) [@international01](https://qa.fmod.com/u/international01)
#### Post date: [January 17, 2016, 9:54pm UTC](https://qa.fmod.com/t/fft-spectrum-nullptr/12242/6 "2016-01-17T21:54:22Z")

</div>

> [@](#):
>
> I need a little help again .
> 
> I get all zeros as output .
> 
> if (FAILED(result = dsp1-\>getParameterData(FMOD\_DSP\_FFT\_SPECTRUMDATA, (void \*\*)&fft, 0, 0, 0))) {  
> MessageBox(NULL, “Failed”, “Failed”, MB\_OK | MB\_ICONEXCLAMATION);  
> }
> 
> ```
> for (int channel = 0; channel < fft->numchannels; channel++) {
> for (int lenght = 0; lenght < fft->length; lenght++) {
> fmoddata = fft->spectrum[channel][lenght];
> }
> }
> 
> result=fmodSystem->update();
> 
> ```

Thank you have the problem found .

Did reading the data easy in the message loop in mainthread called and so the data is read continuously , and are no longer zero .

---

<div class="post-metadata">

### Author: ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)
#### Post date: [January 14, 2016, 11:58pm UTC](https://qa.fmod.com/t/fft-spectrum-nullptr/12242/7 "2016-01-14T23:58:44Z")

</div>

You need to let the sound play and read the spectrum continuously.

---

<div class="post-metadata">

### Author: ![international01](https://avatars.discourse-cdn.com/v4/letter/i/c0e974/32.png) [@international01](https://qa.fmod.com/u/international01)
#### Post date: [January 15, 2016, 1:03pm UTC](https://qa.fmod.com/t/fft-spectrum-nullptr/12242/8 "2016-01-15T13:03:38Z")

</div>

Whit this code,I get all zeros.

dsp1-\>setBypass(false);  
dsp1-\>setActive(TRUE);

```
if (FAILED(result = FMOD::System_Create(&fmodSystem))) {
	MessageBox(NULL, "Failed", "Failed", MB_OK | MB_ICONEXCLAMATION);
}

if (FAILED(result = fmodSystem->init(32, FMOD_INIT_NORMAL, NULL))) {
	MessageBox(NULL, "Failed", "Failed", MB_OK | MB_ICONEXCLAMATION);
}

if (FAILED(result = fmodSystem->createStream("Hawaii5O.mp3", FMOD_DEFAULT, 0, &music))) {
	MessageBox(NULL, "Failed", "Failed", MB_OK | MB_ICONEXCLAMATION);
}

if (FAILED(result = fmodSystem->playSound(music, 0,FALSE, &musicChannel))) {
	MessageBox(NULL, "Failed", "Failed", MB_OK | MB_ICONEXCLAMATION);
}
if (FAILED(result = fmodSystem->createDSPByType(FMOD_DSP_TYPE::FMOD_DSP_TYPE_FFT, &dsp1))) {
	MessageBox(NULL, "Failed", "Failed", MB_OK | MB_ICONEXCLAMATION);
}
if (FAILED(result = musicChannel->addDSP(FMOD_DSP_PARAMETER_DATA_TYPE_FFT, dsp1))) {
	MessageBox(NULL, "Failed", "Failed", MB_OK | MB_ICONEXCLAMATION);
}

if (FAILED(result = dsp1->getParameterData(FMOD_DSP_FFT_SPECTRUMDATA, (void **)&fft, 0, 0,0))) {
	MessageBox(NULL, "Failed", "Failed", MB_OK | MB_ICONEXCLAMATION);
}

for (int channel = 0; channel < fft->numchannels; channel++) {
	for (int lenght = 0; lenght < fft->length; lenght++) {
		fmoddata = fft->spectrum[channel][lenght];
	}
}
fmodSystem->update();

```

The sound runs.
