DSPPROC callback
User defined DSP callback function.
void CALLBACK DSPProc( HDSP handle, DWORD channel, void *buffer, DWORD length, void *user );
Parameters
handle | The DSP handle. |
channel | Channel that the DSP is being applied to. |
buffer | Pointer to the sample data to apply the DSP to. The data is as follows: 8-bit samples are unsigned, 16-bit samples are signed, 32-bit floating-point samples range from -1 to +1 (not clipped, so can actually be outside this range). |
length | The number of bytes to process. |
user | The user instance data given when BASS_ChannelSetDSP was called. |
Remarks
A DSP function should be as quick as possible; playing streams and MOD musics, and other DSP functions cannot be processed until it has finished.Some functions can cause problems if called from within a DSP (or stream) function. Do not call BASS_Stop or BASS_Free from within a DSP callback, and do not call BASS_ChannelStop, BASS_MusicFree or BASS_StreamFree with the same channel handle as received by the callback.
If the BASS_CONFIG_FLOATDSP config option is set, then DSP callback functions will always be passed 32-bit floating-point sample data, regardless of what the channels' actual sample format is.
Example
A simple DSP function to swap the left/right channels of a stereo 16-bit channel.void CALLBACK SwapDSP(HDSP handle, DWORD channel, void *buffer, DWORD length, void *user) { short *s=buffer; for (; length; length-=4, s+=2) { short temp=s[0]; s[0]=s[1]; s[1]=temp; } }
A panning/balance DSP function for a stereo 16-bit channel.
float pan; // panning position, set as you would the BASS_ATTRIB_PAN attribute void CALLBACK PanDSP(HDSP handle, DWORD channel, void *buffer, DWORD length, void *user) { short *s=buffer; if (!pan) return; // no processing neeeded for centre panning for (; length; length-=4, s+=2) { if (pan<0) s[1]=s[1]*(1+pan); // pan left = reduce right else s[0]=s[0]*(1-pan); // vice versa } }