0
0

Hi,
I would write the raw audio data that I catch in a dso callback in a file, but I have some problems.
I pass the FILE* as user data to the callback so:

[code:1gxqy0e3]FILE* m_pAudioFile;
..more code...
recDSPDesc.userdata = (void *)m_pAudioFile;[/code:1gxqy0e3]

and in the callback:

[code:1gxqy0e3]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);
dsp->getUserData((void **)pFile);

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

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

pFile = fopen( &quot;RawAudioData.bin&quot;, &quot;ab&quot; );

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

    // clamp
    if( audioBuffer[i] &lt; -32768 )
    {
        audioBuffer[i] = -32768;
    }
    if( audioBuffer[i] &gt; 32767 )
    {
        audioBuffer[i] = 32767;
    }
}

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

delete[] audioBuffer; 

return FMOD_OK;

}[/code:1gxqy0e3]

I open the file as binary file. The strange behaviour is that seems that in the created file there’s no number. If I do a "more nameOfTheFile.bin" I see lots of strange symbols as ascii code, instead if I do a cout of every sample I can see a number as expected..

Where is my mistake? Is urgent and I’ll appreciate any help.

Regards,
Franco

  • You must to post comments
0
0

You’ve written out the audio data in a binary form. I’m confused, are you expecting to see the numerical value of every sample written out as an integer?

In that case, I would recommend opening the file in ascii mode (though you could still keep it in binary mode if you want, I think), and do:
[code:2ak9i73i]fprintf(pFile, "%d", audioBuffer[i])[/code:2ak9i73i]
inside of the loop. (For that matter, you could probably skip creating the buffer if you do that.) You can then adjust the formatting to whatever you want (comma-separated, each entry on a new line, whatever…)

Hope that helps.

  • You must to post comments
0
0

[quote="Adiss":ols1vzpo]You’ve written out the audio data in a binary form. I’m confused, are you expecting to see the numerical value of every sample written out as an integer?

In that case, I would recommend opening the file in ascii mode (though you could still keep it in binary mode if you want, I think), and do:
[code:ols1vzpo]fprintf(pFile, "%d", audioBuffer[i])[/code:ols1vzpo]
inside of the loop. (For that matter, you could probably skip creating the buffer if you do that.) You can then adjust the formatting to whatever you want (comma-separated, each entry on a new line, whatever…)

Hope that helps.[/quote:ols1vzpo]

Hi Adiss,
the problem is that. I also tried to open the file in text mode,
[code:ols1vzpo]pFile = fopen( "RawAudioData.out", "at" ); [/code:ols1vzpo]
but the content of the file doesn’t change. May be under Linux is not possible write a file in text mode

  • You must to post comments
0
0

just as a debugging measure, have you tried displaying the values in a console window? I always try that first to get the formatting I want, then I convert it to file output. Im sure writing in text mode is very possible in linux.

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.