# Confusion about System addDsp

**URL:** <https://qa.fmod.com/t/confusion-about-system-adddsp/11601>\
**Category:** FMOD Engine\
**Created:** [August 12, 2014, 10:49am UTC](https://qa.fmod.com/t/confusion-about-system-adddsp/11601 "2014-08-12T10:49:08Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [August 31, 2014, 12:40am UTC](https://qa.fmod.com/t/confusion-about-system-adddsp/11601/21 "2014-08-31T00:40:57Z")

</div>

actually the real reason you’re having this issue is that the sound is being played at 48khz really, and its a 44khz sound, so not really Dirac related. The point above still stands though. You either have to use a sound that matches the sample rate of your output (resample the wav to 48khz) or set the output to match the sample rate of the sound with System::setSoftwareFormat and set it to 44100 in this case.

---

<div class="post-metadata">

**Author:** ![Keitel](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Keitel](https://qa.fmod.com/u/Keitel)\
**Post date:** [August 31, 2014, 7:08pm UTC](https://qa.fmod.com/t/confusion-about-system-adddsp/11601/22 "2014-08-31T19:08:02Z")

</div>

So I replaced  
FMOD\_System\_GetSoftwareFormat(system, &sampleRate, NULL, NULL);  
with  
sampleRate = 44100;  
FMOD\_System\_SetSoftwareFormat(system, sampleRate, FMOD\_SPEAKERMODE\_DEFAULT, FMOD\_SPEAKERMODE\_DEFAULT);  
but there was no change. The program still played the file one semitone above normal.  
Then I tried to replace  
FMOD\_ChannelGroup\_AddDSP(channelgroup,1, mydsp);  
with  
FMOD\_CHANNEL \*channel[3];  
FMOD\_System\_PlayDSP(system, mydsp, channelgroup, 0, &channel[1]);  
but then there was no sound.

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [September 1, 2014, 12:15am UTC](https://qa.fmod.com/t/confusion-about-system-adddsp/11601/23 "2014-09-01T00:15:58Z")

</div>

Did you call it before FMOD\_System\_Init? I have modified the example do call setSoftwareFormat before init with 44100, and with my other recommendations, it is playing perfectly.

---

<div class="post-metadata">

**Author:** ![Keitel](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Keitel](https://qa.fmod.com/u/Keitel)\
**Post date:** [September 1, 2014, 9:09am UTC](https://qa.fmod.com/t/confusion-about-system-adddsp/11601/24 "2014-09-01T09:09:02Z")

</div>

Yes, now now it plays the file in the right tuning. That’s great. But I still can’t make the System\_PlayDSP command work, when I replace it for the AddDSP command, though the value of the result variable is FMOD\_OK. There is just no sound, and I am not able to see anything wrong with the syntax of the command.

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [September 4, 2014, 3:36am UTC](https://qa.fmod.com/t/confusion-about-system-adddsp/11601/25 "2014-09-04T03:36:25Z")

</div>

Hi Ketil. I’ve checked into this. playDSP would be the best way to do it, but it looks like there is a bug where the dsp is not transferring its channel count to the resampler. I’ll try to get this into a build which goes out in the next day or 2.

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [September 4, 2014, 3:37am UTC](https://qa.fmod.com/t/confusion-about-system-adddsp/11601/26 "2014-09-04T03:37:17Z")

</div>

Another way to fix it is to use process callback instead of read callback, and make sure the process FMOD\_DSP\_PROCESS\_QUERY mode gets the right number of channels back. Using read callback, it is getting 0 channels back at the moment which is the reason for the issue.

---

<div class="post-metadata">

**Author:** ![Keitel](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Keitel](https://qa.fmod.com/u/Keitel)\
**Post date:** [September 11, 2014, 10:54am UTC](https://qa.fmod.com/t/confusion-about-system-adddsp/11601/27 "2014-09-11T10:54:12Z")

</div>

Hi again,

I have recompiled the program with your last Fmod version, but I still have one issue, though I don’t know if it is directly related to Fmod or something else. I have transferred the console application to become a function in a Windows API program, just making the necessary adjustments. When I include the command FMOD\_System\_PlayDSP(systemx, mydsp, channelgroup, 0, &channel[1]) in the function, the program exits with the debug message Native’ has exited with code -1 (0xffffffff). However, when I put a system(“pause”) command after the PlayDSP command it works, but then I also get the additional console application window. I see no reason why the program should exit, as it doesn’t do so when I remove the PlayDSP command. I therefore wonder if you could give me an idea what could be wrong?

Keitel

---

<div class="post-metadata">

**Author:** ![Keitel](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Keitel](https://qa.fmod.com/u/Keitel)\
**Post date:** [September 13, 2014, 7:40pm UTC](https://qa.fmod.com/t/confusion-about-system-adddsp/11601/28 "2014-09-13T19:40:43Z")

</div>

I guess I’ll have to use a thread function. But if I then want to play more than one file like this simultaneously, don’t I then have to make two thread functions?

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [September 14, 2014, 8:45am UTC](https://qa.fmod.com/t/confusion-about-system-adddsp/11601/29 "2014-09-14T08:45:16Z")

</div>

It really sounds to me like your program just exited because you didnt wait for input.  
I dont see why you would need a thread, or think you need threads to play sounds? FMOD has a playsound command, you just call them one after the other.  
The standard way to make a windows program is to respond to messages, or run a main loop in winmain and translate and dispatch the necessary windows messages as they come in (you still need to do this either way), but in between this stuff, call your game code update function, which would be calling fmod functions. Have you written a windows program before? This is starting to get off topic for FMOD Q/A but there are plenty of resources online to get you started.

---

<div class="post-metadata">

**Author:** ![Keitel](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Keitel](https://qa.fmod.com/u/Keitel)\
**Post date:** [September 14, 2014, 2:44pm UTC](https://qa.fmod.com/t/confusion-about-system-adddsp/11601/30 "2014-09-14T14:44:23Z")

</div>

Hi Brett!  
No, no, this must be a misunderstanding. I know how to program in C for Windows and how to make sounds with Fmod. Though I admit that my understanding of the DSP functionalities is somewhat limited. The issue is that I have a function with a playDSP command that I call from the main program. But when I call the function an it reaches the playDSP command, the proram exits. It might be because of some triviality that I have overlooked, but I am not able to see that for now. So if you could take a look at the code of the function below, and see if you can find anything wrong, it would appreciate it very much. The other functions that is called by this function is the same as in the previous examples.

void timestretch(int selection, float time, float pitch, char infileName[]){

```
FMOD_DSP *mydsp;
FMOD_CHANNELGROUP	*channelgroup;
    void *dirac;

userDataStruct state;
state.sReadPosition;
state.sSound;

result = FMOD_System_GetSoftwareFormat(systemx, &sampleRate, NULL, NULL);	
result = FMOD_System_CreateSound(systemx, infileName, FMOD_LOOP_NORMAL, 0, &sound[selection]);
ERRCHECK(result);

state.sReadPosition = 0;
state.sSound = sound[selection];

result = FMOD_Sound_GetLength(sound[selection], &state.sFileNumFrames, FMOD_TIMEUNIT_PCM);

ERRCHECK(result);

result = FMOD_Sound_GetFormat(sound[selection], NULL, NULL, &state.sNumChannels, &state.sNumBits);

ERRCHECK(result);

dirac = DiracCreateInterleaved(kDiracLambdaPreview, kDiracQualityPreview, state.sNumChannels, sampleRate, &diracDataProviderCallback, (void*)&state);

{ 
    static FMOD_DSP_DESCRIPTION dspdesc; 

    memset(&dspdesc, 0, sizeof(FMOD_DSP_DESCRIPTION)); 

    strcpy(dspdesc.name, "My first DSP unit");      
	
	dspdesc.numinputbuffers = 0;                
    
	dspdesc.read = &myDSPCallback; 
            dspdesc.userdata = (void *)dirac; 

    result = FMOD_System_CreateDSP(systemx, &dspdesc, &mydsp); 
    ERRCHECK(result); 
    } 

FMOD_System_Update(systemx);

result = FMOD_System_GetMasterChannelGroup(systemx, &channelgroup);

ERRCHECK(result);

result = FMOD_System_PlayDSP(systemx, mydsp, channelgroup, 0, &channel[1]);

   ERRCHECK(result);	

   FMOD_System_Update(systemx);

```

}

Thanks in advance.

Keitel

---

<div class="post-metadata">

**Author:** ![Keitel](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Keitel](https://qa.fmod.com/u/Keitel)\
**Post date:** [September 29, 2014, 6:02pm UTC](https://qa.fmod.com/t/confusion-about-system-adddsp/11601/31 "2014-09-29T18:02:00Z")

</div>

> [@](#):
>
> Hi Brett!  
> No, no, this must be a misunderstanding. I know how to program in C for Windows and how to make sounds with Fmod. Though I admit that my understanding of the DSP functionalities is somewhat limited. The issue is that I have a function with a playDSP command that I call from the main program. But when I call the function an it reaches the playDSP command, the proram exits. It might be because of some triviality that I have overlooked, but I am not able to see that for now. So if you could take a look at the code of the function below, and see if you can find anything wrong, it would appreciate it very much. The other functions that is called by this function is the same as in the previous examples.
> 
> void timestretch(int selection, float time, float pitch, char infileName){
> 
> ```
> FMOD_DSP *mydsp;
> FMOD_CHANNELGROUP	*channelgroup;
> void *dirac;
> 
> userDataStruct state;
> state.sReadPosition;
> state.sSound;
> 
> result = FMOD_System_GetSoftwareFormat(systemx, &sampleRate, NULL, NULL);	
> result = FMOD_System_CreateSound(systemx, infileName, FMOD_LOOP_NORMAL, 0, &sound[selection]);
> ERRCHECK(result);
> 
> state.sReadPosition = 0;
> state.sSound = sound[selection];
> 
> result = FMOD_Sound_GetLength(sound[selection], &state.sFileNumFrames, FMOD_TIMEUNIT_PCM);
> 
> ERRCHECK(result);
> 
> result = FMOD_Sound_GetFormat(sound[selection], NULL, NULL, &state.sNumChannels, &state.sNumBits);
> 
> ERRCHECK(result);
> 
> dirac = DiracCreateInterleaved(kDiracLambdaPreview, kDiracQualityPreview, state.sNumChannels, sampleRate, &diracDataProviderCallback, (void*)&state);
> 
> { 
> static FMOD_DSP_DESCRIPTION dspdesc; 
> 
> memset(&dspdesc, 0, sizeof(FMOD_DSP_DESCRIPTION)); 
> 
> strcpy(dspdesc.name, "My first DSP unit");      
> 	
> dspdesc.numinputbuffers = 0;                
>     
> dspdesc.read = &myDSPCallback; 
> dspdesc.userdata = (void *)dirac; 
> 
> result = FMOD_System_CreateDSP(systemx, &dspdesc, &mydsp); 
> ERRCHECK(result); 
> } 
> 
> FMOD_System_Update(systemx);
> 
> result = FMOD_System_GetMasterChannelGroup(systemx, &channelgroup);
> 
> ERRCHECK(result);
> 
> result = FMOD_System_PlayDSP(systemx, mydsp, channelgroup, 0, &channel[1]);
> 
> ERRCHECK(result);	
> 
> FMOD_System_Update(systemx);
> 
> ```
> 
> }
> 
> Thanks in advance.
> 
> Keitel

When debugging with the above code; I get the following error message:

Unhandled exception at 0x75c8812f (KernelBase.dll) in DhruvaNada2.exe: Microsoft C++ exception: std::bad\_alloc at memory location 0x0026f068…

Keitel

---

<div class="post-metadata">

**Author:** ![Keitel](https://avatars.discourse-cdn.com/v4/letter/k/e5b9ba/32.png) [@Keitel](https://qa.fmod.com/u/Keitel)\
**Post date:** [October 8, 2014, 8:20am UTC](https://qa.fmod.com/t/confusion-about-system-adddsp/11601/32 "2014-10-08T08:20:40Z")

</div>

I made the “state” variable into a global variable and then it worked. I therefore consider the case solved. Thanks for all help and support.  
-Keitel

[Previous page](https://qa.fmod.com/t/confusion-about-system-adddsp/11601.md?page=1)
