0
0

Hi to all, I have a strange behavior in my dsp callback. In the callback I would copy the raw data in a file passed as userdata
Passing a FILE* as userdata I can not listen the output either copying the input to the output.
Here the code of the callback:
[code:2ekyydjn]
FMOD_RESULT F_CALLBACK recDSPCallback(FMOD_DSP_STATE *dsp_state,
float *inbuffer,
float *outbuffer,
unsigned int length,
int inchannels,
int outchannels)
{
assert(inchannels == outchannels);
assert(inbuffer != NULL);
assert(outbuffer != NULL);
assert(dsp_state != NULL);
assert(dsp_state->instance != NULL);
if((inchannels != outchannels) ||
(inbuffer == NULL) ||
(outbuffer == NULL) ||
(dsp_state == NULL) ||
(dsp_state->instance == NULL))
return FMOD_OK; //yeah I’m ok with that

FILE *pFile;
FMOD::DSP *dsp = reinterpret_cast<FMOD::DSP*>(dsp_state->instance);

// assuming i == o
memcpy(outbuffer, inbuffer, length * outchannels * sizeof(float));

signed short *audioBuffer;
audioBuffer = new int16_t[length];

dsp->getUserData((void **)pFile); // If I comment this I can listen the output

pFile = fopen( "RawAudioData.bin", "ab" );

for(unsigned  int i = 0; i < length; i++ )
{
    audioBuffer[i] = (signed short)(inbuffer[i] * 32767.0f);

    // clamp
    if( audioBuffer[i] < -32768 )
    {
        audioBuffer[i] = -32768;
    }
    if( audioBuffer[i] > 32767 )
    {
        audioBuffer[i] = 32767;
    }
}

fwrite( audioBuffer, sizeof(int16_t), length, pFile );
fclose(pFile);
return FMOD_OK;

}[/code:2ekyydjn]

and here the code with the dsp settings:
[code:2ekyydjn]
/* Create the dsp effects */
FMOD_DSP_DESCRIPTION recDSPDesc;

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

strcpy(recDSPDesc.name,  "record DSP unit");
recDSPDesc.channels      = 2;
recDSPDesc.config        = NULL;
recDSPDesc.configheight  = 0;
recDSPDesc.configwidth   = 0;
recDSPDesc.create        = NULL;
recDSPDesc.release       = NULL;
recDSPDesc.reset         = NULL;
recDSPDesc.read          = &recDSPCallback;
recDSPDesc.setposition   = NULL;
recDSPDesc.paramdesc     = NULL;
recDSPDesc.numparameters = 0;
recDSPDesc.setparameter  = NULL;
recDSPDesc.getparameter  = NULL;
recDSPDesc.userdata      = (void *)m_pAudioFile;

result = fmodSystem->createDSP(&recDSPDesc, &recDSP);
HandleError(result, __FILE__, __LINE__);

result = fmodSystem->addDSP(recDSP, 0);
HandleError(result, __FILE__, __LINE__);

recDSP->setBypass(false);
recDSP->setActive(true);[/code:2ekyydjn]

Where are my mistakes
Thank you very much.
Franco

  • You must to post comments
0
0

[quote:195ctd38] dsp->getUserData((void **)pFile); // If I comment this I can listen the output [/quote:195ctd38]
I’m not sure what you’re expecting this line to do since it is followed by fopen. Regardless,it looks like the problem you’re experiencing is because of your type casting.

Try this:
[code:195ctd38]void * userData;
dsp->getUserData(&userData);
pFile = (FILE *) userData;[/code:195ctd38]

Your code will have massive leaks if you don’t free your dynamic "audioBuffer" array. You should add a "delete [] audioBuffer;" after fwrite.

-Pete

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.