Namespace: Un4seen.Bass.Misc
Assembly: Bass.Net (in Bass.Net.dll) Version: 2.4.17.5
public abstract void DSPCallback( int handle, int channel, IntPtr buffer, int length, IntPtr user )
Parameters
- handle
- Type: SystemInt32
The DSP handle. - channel
- Type: SystemInt32
Channel that the DSP is being applied to. - buffer
- Type: SystemIntPtr
The buffer to apply the DSP to. The sample 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
- Type: SystemInt32
The number of BYTES to process. - user
- Type: SystemIntPtr
The user instance data given (see User).
You might use the ChannelBitwidth to determine if the sample data received is 8-, 16- or 32-bit. ChannelNumChans and ChannelSampleRate might be used to retrieve additional information about the channel being used.
Make sure to handle the IsBypassed property in order to support a bypass feature.
Some functions can cause problems if called from within a DSP (or stream) function. Do not call these functions from within a DSP callback:
BASS_Stop, BASS_Free, BASS_MusicLoad(String, Int64, Int32, BASSFlag, Int32), BASS_StreamCreate(Int32, Int32, BASSFlag, STREAMPROC, IntPtr) (or any other stream creation functions).
Also, do not call BASS_ChannelRemoveDSP(Int32, Int32), BASS_ChannelSetDSP(Int32, DSPPROC, IntPtr, Int32), BASS_ChannelStop(Int32), BASS_MusicFree(Int32), BASS_StreamFree(Int32) with the same channel handle as received by the callback.
It is clever to NOT alloc buffer data (e.g. a float[]) everytime within the callback method, since ALL callbacks should be really fast! And if you would do a 'float[] data = new float[]' every time here...the GarbageCollector would never really clean up that memory. Sideeffects might occure, due to the fact, that BASS will call this callback too fast and too often...you might also declare the callback function as 'unsafe' and use native pointer assignements for fast processing. However, this is not always the case, so in most examples it'll work just fine - but if you got problems - try moving any memory allocation things outside any callbacks.
In a derived class you might call RaiseNotification at the end of your processing, in order to fire the Notification. By doing so all subscribers will get notified, that the DSP processing has been done - e.g. in order to update a UI thread.