BASS.NET API for the Un4seen BASS Audio Library

BassBASS_StreamPutData Method (Int32, Single, Int32)

BASS.NET API for the Un4seen BASS Audio Library
Adds sample data to a "push" stream.

Namespace:  Un4seen.Bass
Assembly:  Bass.Net (in Bass.Net.dll) Version: 2.4.17.5
Syntax

[DllImportAttribute("bass")]
public static int BASS_StreamPutData(
	int handle,
	float[] buffer,
	int length
)

Parameters

handle
Type: SystemInt32
The stream handle (as created with BASS_StreamCreatePush(Int32, Int32, BASSFlag, IntPtr)).
buffer
Type: SystemSingle
The array of float sample data to provide ( = allocate space in the queue buffer so that there is at least length bytes of free space).
length
Type: SystemInt32
The amount of data in bytes! (buffer.Length*4), optionally using the BASS_STREAMPROC_END flag to signify the end of the stream. 0 can be used to just check how much data is queued.

Return Value

Type: Int32
If successful, the amount of queued data is returned, else -1 is returned. Use BASS_ErrorGetCode to get the error code.
Remarks

As much data as possible will be placed in the stream's playback buffer, and any remainder will be queued for when more space becomes available, ie. as the buffered data is played. With a decoding channel, there is no playback buffer, so all data is queued in that case. There is no limit to the amount of data that can be queued, besides available memory. The queue buffer will be automatically enlarged as required to hold the data, but it can also be enlarged in advance. The queue buffer is freed when the stream ends or is reset, eg. via BASS_ChannelPlay(Int32, Boolean) (with restart = TRUE) or BASS_ChannelSetPosition(Int32, Int64, BASSMode) (with pos = 0).

DSP/FX are applied when the data reaches the playback buffer, or the BASS_ChannelGetData(Int32, IntPtr, Int32) call in the case of a decoding channel.

Data should be provided at a rate sufficent to sustain playback. If the buffer gets exhausted, BASS will automatically stall playback of the stream, until more data is provided. BASS_ChannelGetData(Int32, IntPtr, Int32) (BASS_DATA_AVAILABLE) can be used to check the buffer level, and BASS_ChannelIsActive(Int32) can be used to check if playback has stalled. A BASS_SYNC_STALL sync can also be set via BASS_ChannelSetSync(Int32, BASSSync, Int64, SYNCPROC, IntPtr), to be triggered upon playback stalling or resuming.

ERROR CODEDescription
BASS_ERROR_HANDLEhandle is not valid.
BASS_ERROR_NOTAVAILThe stream is not using the push system.
BASS_ERROR_ILLPARAMlength is not valid, it must equate to a whole number of samples.
BASS_ERROR_ENDEDThe stream has ended.
BASS_ERROR_MEMThere is insufficient memory.

Examples

Creating a stream duplicate:
private DSPPROC _dupCallback;
...
// create stream on device 1
Bass.BASS_SetDevice(1);
int orig = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_SAMPLE_LOOP);
Bass.BASS_ChannelPlay(orig, false);
...
// create a clone on device 2
BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(stream);
Bass.BASS_SetDevice(2);
int clone = Bass.BASS_StreamCreatePush(info.freq, info.chans, info.flags, IntPtr.Zero);
// pause source stream to synchonise buffer contents
Bass.BASS_ChannelPause(stream);
int c = Bass.BASS_ChannelGetData(stream, IntPtr.Zero, (int)BASSData.BASS_DATA_AVAILABLE);
byte[] buf = new byte[c];
Bass.BASS_ChannelGetData(stream, buf, c);
Bass.BASS_StreamPutData(clone, buf, c);
// set DSP to copy new data from source stream
_dupCallback = new DSPPROC(DupDSP);
Bass.BASS_ChannelSetDSP(orig, _dupCallback, new IntPtr(clone), 0);
Bass.BASS_ChannelPlay(orig, false); // resume source
Bass.BASS_ChannelPlay(clone, false); // play clone
...
private void DupDSP(int handle, int channel, IntPtr buffer, int length, IntPtr user)
{
  Bass.BASS_StreamPutData(user.ToInt32(), buffer, length);
}
See Also

Reference