Delegate DSPProcedure
User defined DSP callback function (to be used with ChannelSetDSP(Int32, DSPProcedure, IntPtr, Int32)).
Example
A simple DSP function to swap the left/right channels of a stereo 16-bit channel.
unsafe void SwapDSP(int handle, int channel, IntPtr buffer, int length, IntPtr user)
{
for (var s = (short*)buffer; length != 0; length -= 4, s += 2)
{
var temp = s[0];
s[0] = s[1];
s[1] = temp;
}
}
A panning/balance DSP function for a stereo 16-bit channel.
// panning position, set as you would the ChannelAttribute.Pan attribute
float pan;
unsafe void PanDSP(int handle, int channel, IntPtr buffer, int length, IntPtr user)
{
// no processing neeeded for centre panning
if (pan == 0)
return;
for (var s = (short*)buffer; length != 0; length -= 4, s += 2)
{
// pan left = reduce right
if (pan < 0)
s[1] *= 1 + pan;
// vice versa
else s[0] *= 1 - pan;
}
}
Namespace: System.Dynamic.ExpandoObject
Assembly: ManagedBass.dll
Syntax
public delegate void DSPProcedure(int Handle, int Channel, IntPtr Buffer, int Length, IntPtr User);
Parameters
Int32
Handle
The DSP Handle (as returned by ChannelSetDSP(Int32, DSPProcedure, IntPtr, Int32)). |
Int32
Channel
Channel that the DSP is being applied to. |
IntPtr
Buffer
The pointer to the Buffer to apply the DSP to. The sample data is in standard Windows PCM format - 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). |
Int32
Length
The number of bytes to process. |
IntPtr
User
The User instance data given when ChannelSetDSP(Int32, DSPProcedure, IntPtr, Int32) was called. |
Remarks
A DSP function should obviously be as quick as possible... playing streams, MOD musics and other DSP functions can not be processed until it has finished.
Some functions can cause problems if called from within a DSP (or stream) function. Do not call these functions from within a DSP callback:
Stop(), Free(), MusicLoad(String, Int64, Int32, BassFlags, Int32), CreateStream(Int32, Int32, BassFlags, StreamProcedure, IntPtr) (or any other stream creation functions).
Also, do not call ChannelRemoveDSP(Int32, Int32) with the same DSP Handle as received by the callback, or ChannelStop(Int32), MusicFree(Int32), StreamFree(Int32) with the same channel Handle as received by the callback.
If the FloatingPointDSP 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.