FMOD_RESULT F_CALLBACK myDSPCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int *outchannels) { FMOD_RESULT result; char name[256]; unsigned int userdata; FMOD::DSP *thisdsp = (FMOD::DSP *)dsp_state->instance; /* This redundant call just shows using the instance parameter of FMOD_DSP_STATE to call a DSP information function. */ result = thisdsp->getInfo(name, 0, 0, 0, 0); ERRCHECK(result); result = thisdsp->getUserData((void **)&userdata); ERRCHECK(result); if (delayBuffer == NULL) delayBuffer = (float*)malloc(bufferSize * sizeof(float)); /* 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 samp = 0; samp < length; samp++) { /* 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[(samp * *outchannels) + chan] = inbuffer[(samp * inchannels) + chan] * 0.2f; delayBuffer[((sampleCount * *outchannels) + chan) % bufferSize] = inbuffer[(samp * inchannels) + chan]; int delayBufferPosition = (((sampleCount - delay) * inchannels) + chan) % bufferSize; if (delayBufferPosition >= 0) { outbuffer[(samp * *outchannels) + chan] = delayBuffer[delayBufferPosition]; } else { outbuffer[(samp * *outchannels) + chan] = 0; } } sampleCount++; } return FMOD_OK; }
FMOD_RESULT F_CALLBACK myDSPCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels) { unsigned int count, userdata; int count2; char name[256]; 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); /* 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 (count = 0; count < length; count++) { /* Feel free to unroll this. */ for (count2 = 0; count2 < outchannels; count2++) { /* This DSP filter just halves the volume! Input is modified, and sent to output. */ outbuffer[(count * outchannels) + count2] = inbuffer[(count * inchannels) + count2] * 0.2f; } } return FMOD_OK; }