DSPPROC callback


User defined DSP callback function.

void CALLBACK DSPProc(
    HDSP handle,
    DWORD channel,
    void *buffer,
    DWORD length,
    void *user
);

Parameters

handleThe DSP handle.
channelChannel that the DSP is being applied to.
bufferPointer 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).
lengthThe number of bytes to process.
userThe user instance data given when BASS_ChannelSetDSP was called.

Remarks

The format of the sample data is as stated by BASS_ChannelGetInfo, except that it will always be floating-point if the BASS_CONFIG_FLOATDSP config option is enabled.

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_MusicFree or BASS_StreamFree with the same channel handle as received by the callback.

Example

A 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 = (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
    }
}

See also

BASS_ChannelSetDSP, BASS_ATTRIB_GRANULE, BASS_CONFIG_FLOATDSP