User defined DSP callback function.
void CALLBACK DSPProc( HDSP handle, DWORD channel, void *buffer, DWORD length, void *user );
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. |
If the DSP processing requires a particular amount of data, the BASS_ATTRIB_GRANULE attribute can be used to specify that.
A DSP function should be as quick as possible, as any lengthy delays can result in stuttering playback. Some functions can cause problems if called from within a DSP function. Do not call BASS_Stop or BASS_Free from within a DSP callback, and do not call BASS_ChannelStop, BASS_ChannelFree, BASS_MusicFree or BASS_StreamFree with the same channel handle as received by the callback. BASS_ChannelRemoveDSP can be called to stop the DSP function being used any more.
void CALLBACK SwapDSP(HDSP handle, DWORD channel, void *buffer, DWORD length, void *user) { short *s = (short*)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 = (short*)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 } }