Delegate StreamProcedure
User stream writing callback delegate (to be used with CreateStream(Int32, Int32, BassFlags, StreamProcedure, IntPtr)).
Namespace: System.Dynamic.ExpandoObject
Assembly: ManagedBass.dll
Syntax
public delegate int StreamProcedure(int Handle, IntPtr Buffer, int Length, IntPtr User);
Parameters
Int32
Handle
The stream that needs writing. |
IntPtr
Buffer
The pointer to the Buffer to write the sample data in. The sample data must be written 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. |
Int32
Length
The number of bytes to write. |
IntPtr
User
The User instance data given when CreateStream(Int32, Int32, BassFlags, StreamProcedure, IntPtr) was called. |
Returns
Int32
The number of bytes written by the function, optionally using the End (StreamProcedure) flag to signify that the end of the stream is reached. |
Remarks
A stream writing function should obviously be as quick as possible, because other streams (and MOD musics) can't be updated until it's finished.
It is better to return less data quickly, rather than spending a long time delivering the amount BASS requested.
Although a STREAMPROC may return less data than BASS requests, be careful not to do so by too much, too often. If the Buffer level gets too low, BASS will automatically stall playback of the stream, until the whole Buffer has refilled.
ChannelGetData(Int32, IntPtr, Int32) DataFlags can be used to check the Buffer level, and ChannelIsActive(Int32) can be used to check if playback has stalled.
A Stalled sync can also be set via ChannelSetSync(Int32, SyncFlags, Int64, SyncProcedure, IntPtr), to be triggered upon playback stalling or resuming.
If you do return less than the requested amount of data, the number of bytes should still equate to a whole number of samples.
Some functions can cause problems if called from within a stream (or DSP) function. Do not call these functions from within a stream callback:
ChannelStop(Int32), Free(), MusicLoad(String, Int64, Int32, BassFlags, Int32), CreateStream(Int32, Int32, BassFlags, StreamProcedure, IntPtr) or any other stream creation functions.
Also, do not call StreamFree(Int32) or ChannelStop(Int32) with the same Handle as received by the callback.
When streaming multi-channel sample data, the channel order of each sample is as follows:
3 channels: left-front, right-front, center.
4 channels: left-front, right-front, left-rear/side, right-rear/side.
6 channels(5.1): left-front, right-front, center, LFE, left-rear/side, right-rear/side.
8 channels(7.1): left-front, right-front, center, LFE, left-rear/side, right-rear/side, left-rear center, right-rear center.