I made a custom DSP to write the final sound output to disk in wav form. The main output (sound coming from speakers) has none of this popping sound, but when I play back the wav written to disk from this DSP, I hear them when using other DSPs (high pass, reverb, equalizer) or simply changing pitch. If I don’t use these effects there is no problem. It is strange because the main out shares almost the same output. The only difference comes from converting floats to shorts, which I do as follows:

FMOD_RESULT F_CALLBACK saverCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels)
FMOD::DSP *thisdsp = (FMOD::DSP *)dsp_state->instance;
MySystem *slf = nil;
thisdsp->getUserData((void **)&slf);

memcpy(outbuffer, inbuffer, length * inchannels * 4); 

short *data = (short *)malloc(length * 4);
for (unsigned int sample = 0; sample < length; sample++) 

    // Save to temporary buffer for later batch fwrite in separate thread
    data[sample * 2] = (short)(inbuffer[sample * 2] * 32767.0f);
    data[sample * 2 + 1] = (short)(inbuffer[sample * 2 + 1] * 32767.0f);

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSNumber *num = [NSNumber numberWithUnsignedInt:length];
NSArray *array = [NSArray arrayWithObjects:[NSValue valueWithPointer:data], num, nil];

NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:slf selector:@selector(writeFile:) object:array];
[opQueue addOperation:op];
[op release];

[pool release];

return FMOD_OK;


writeFile: simply uses unbuffered fwrite to write data to disk sequentially (the operation queue is set to run only 1 operation at a time).

Help is appreciated.

  • You must to post comments

I suspect that some of the float data is outside the range -1.0 to 1.0. If that is the case FMOD would clamp those values inside the mixer, whereas your code would cause them to wrap around (making a pop). Try clamping the floats before converting them to shorts.

Something like this:
[code:2p17khhj]inline float clamp(float val, float min, float max)
if (val < min) return min;
if (val > max) return max;
return val;

[code:2p17khhj] data[sample * 2] = (short)(clamp(inbuffer[sample * 2], -1.0f, 1.0f) * 32767.0f);
data[sample * 2 + 1] = (short)(clamp(inbuffer[sample * 2 + 1], -1.0f, 1.0f); * 32767.0f); [/code:2p17khhj]

  • You must to post comments

Thanks, this is exactly what was happening. :)

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.