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... NULL = the DSP has been removed from the channel. The data is as follows: 8-bit samples are unsigned, 16-bit samples are signed, 32-bit floating-point samples normally range from -1.0 to +1.0 but can be outside that as they are not clipped. |
| length | The number of bytes to process. |
| user | The user instance data given when BASS_ChannelSetDSP or BASS_ChannelSetDSPEx was called. |
The BASS_POS_DSP mode can be used with BASS_ChannelGetPosition to get the channel's position at the start of the data. The BASS_POS_DECODE mode gives the position at the end of the data.
BASS_ChannelRemoveDSP can be used by a DSP function to stop it being called again.
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 needed 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
}
}