0
0

Since I’d like to play audio while recording, I used the recordtodisk example.
I can record the wav file, but it plays back with static instead of the actual sound. Also the sound is stopped after a few second. Any help is appreciated. Heres the code I modified:

[code:2wjjnqzl]
FMOD_RESULT F_CALLBACK myDspRecorderCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels)
{
unsigned int userdata = 0;
char name[256] = {0};
FMOD::DSP *thisdsp = (FMOD::DSP *)dsp_state->instance;

/* 
 This redundant call just shows using the instance parameter of FMOD_DSP_STATE and using it to 
 call a DSP information function. 
 */
thisdsp->getInfo(name, 0, 0, 0, 0);
thisdsp->getUserData((void **)&userdata);

unsigned int *bufferToWrite; 
bufferToWrite = new unsigned int[length];

//This loop assumes inchannels = outchannels, which it will be if the DSP is created with '0' 
//as the number of channels in FMOD_DSP_DESCRIPTION.  
///Specifying an actual channel count will mean you have to take care of any number of channels coming in,
//but outputting the number of channels specified.  Generally it is best to keep the channel 
// count at 0 for maximum compatibility.

for (unsigned int sample = 0; sample < length; sample++) 
{ 
    //Feel free to unroll this.

    for (int chan = 0; chan < outchannels; chan++)
    {

        // This DSP filter just halves the volume! 
        // Input is modified, and sent to output.

        outbuffer[(sample * inchannels) + chan] = inbuffer[(sample * inchannels) + chan]  * 0.5f;

        unsigned int theIndex= inbuffer[(sample * inchannels) + chan];
        bufferToWrite[theIndex] = inbuffer[theIndex]   * 32767.0f;

        if( bufferToWrite[theIndex] < -32768 ) 
        { 
            bufferToWrite[theIndex] = -32768; 
        } 
        if( bufferToWrite[theIndex] > 32767 ) 
        { 
            bufferToWrite[theIndex] = 32767; 
        } 
    }
} 

memcpy(outbuffer, inbuffer, length * inchannels * sizeof(float)); 
fwrite(outbuffer, sizeof(float), length * inchannels, outFileForMix); 

dataLengthRecord += length * inchannels;

delete[] bufferToWrite; 

return FMOD_OK; 

}
[/code:2wjjnqzl]

  • You must to post comments
0
0

this code looks pretty bizarre

unsigned int theIndex= inbuffer[(sample * inchannels) + chan];

you’re converting pcm sound data into an index that you then use to reference your bufferToWrite buffer? I’m suprised that doesnt crash.

  • You must to post comments
0
0

also if your buffertowrite is signed short, then that comparison wont work. You would have to clamp in floating point mode between -1 and +1 first, then multiply by 32767.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.