Hi All,

Quick question. I’ve got a custom DSP setup that I want to use for writing it’s incoming data to a wav file. I’ve found and used the "writeWavHeader" function from the recordtodisk example in the fmod download. I can’t get the format of how to write everything in the read callback correct though.

So far i’ve successfully gotten "writeWavHeader" working, and implemented the custom DSP so it’s read callback is executing. And I am writing content to the file but the file plays back as white noise.

I was also reading in the documentation that to get the real length in bytes of the inbuffer that I have to multiply (length * inchannels * 4). Is that right?

Here’s my code ( you can see that the commented out sections are what I’ve tried) :

FMOD_RESULT F_CALLBACK fmodDSPProcess(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels) {
FMOD::DSP * dsp = (FMOD::DSP *)dsp_state->instance;
BMAudioProcessing2 * ap;
FMOD::System * system;

unsigned int realLength = (length * inchannels * outchannels) * 4;
NSLog(@"realLength: %iu",realLength);
NSLog(@"inchannels: %i, outchannels: %i, length: %i",inchannels,outchannels,length);

for(unsigned int sample = 0; sample < length; sample++) {
    for(int chan=0; chan<outchannels; chan++) {
        outbuffer[(sample * outchannels) + chan] = inbuffer[(sample * inchannels) + chan];

        //Seems like to much work to write 4 bytes at a time in a huge loop
        //if(ap->_loggingRecording) {
        //  size_t written = fwrite( (float *)&inbuffer[(sample * inchannels) + chan] ,sizeof(float),1, ap->_recordingFile);
        //  NSLog(@"wrote: %lu",written);

//I Thought this would work.. 
//if(ap->_loggingRecording) {
//  size_t written = fwrite(inbuffer,realLength,1,ap->_recordingFile);
//  NSLog(@"write: %iu, wrote: %lu",realLength,written);

return FMOD_OK;


Any help would be much appreciated. Thanks!

Also here’s the full file if seeing everything would help.


  • You must to post comments

actually I got it. turned out the wav header was incorrect vs what was actually in the file.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.