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... 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.
lengthThe number of bytes to process.
userThe user instance data given when BASS_ChannelSetDSP or BASS_ChannelSetDSPEx was called.

Remarks

The format of the sample data is as stated by BASS_ChannelGetInfo unless different was requested with BASS_ChannelSetDSPEx or 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. The processing should be as quick as possible, as any lengthy delays can result in stuttering playback.

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.

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 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
    }
}

See also

BASS_ChannelSetDSP, BASS_ChannelSetDSPEx, BASS_ATTRIB_GRANULE, BASS_CONFIG_FLOATDSP