BASS.NET API for the Un4seen BASS Audio LibraryBassBASS_ChannelGetData Method (Int32, Int16, Int32)BASS.NET API for the Un4seen BASS Audio Library
Retrieves the immediate sample data of a sample channel, stream, MOD music, or recording channel. This overload uses a managed short[] to reference the buffer data as 16-bit values - each element will represent one channel in this case! SHOULD ONLY BE USED, if the stream was created WITHOUT BASS_SAMPLE_FLOAT or BASS_SAMPLE_8BITS!

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

[DllImportAttribute("bass.dll", CharSet = CharSet.Unicode)]
public static int BASS_ChannelGetData(
	int handle,
	short[] buffer,
	int length
)

Parameters

handle
Type: SystemInt32
The channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD.
buffer
Type: SystemInt16
The array (short[]) to receive the data, e.g. when creating the channel stream with default setting, meaning 16-bit samples!
length
Type: SystemInt32
Number of bytes wanted, and/or the following flags (BASSData):
BASS_DATA_AVAILABLEQuery the amount of data the channel has buffered. This flag is primarily of use when recording, and can't be used with decoding channels as they do not have playback buffers. buffer can be when using this flag.

Return Value

Type: Int32
If an error occurs, -1 is returned, use BASS_ErrorGetCode to get the error code.

When requesting sample data, the number of bytes written to buffer will be returned (not necessarily the same as the number of bytes read).

When using the BASS_DATA_AVAILABLE flag, the number of bytes in the channel's buffer is returned.

Remarks

This function can only return as much data as has been written to the channel's buffer, so it may not always be possible to get the amount of data requested, especially if you request large amounts. If you really do need large amounts, then increase the buffer lengths (BASS_CONFIG_BUFFER). The BASS_DATA_AVAILABLE flag can be used to check how much data a channel's buffer contains at any time, including when stopped or stalled.

When requesting data from a "decoding channel" (BASS_STREAM_DECODE or BASS_MUSIC_DECODE was used at creation), there are no intermediate buffers involved, so as much data as is available can be decoded in one go.

When retrieving sample data, the returned data is in the 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). That's unless the BASS_DATA_FLOAT flag is used, in which case, the sample data will be converted to 32-bit floating-point (if it isn't already).

This function is most useful if you wish to visualize (eg. spectrum analyze) the sound.

ERROR CODEDescription
BASS_ERROR_HANDLEhandle is not a valid channel.
BASS_ERROR_ENDEDThe channel has reached the end.
BASS_ERROR_NOTAVAILThe BASS_DATA_AVAILABLE flag was used with a decoding channel.
BASS_ERROR_BUFLOSTShould not happen... check that a valid window handle was used with BASS_Init(Int32, Int32, BASSInit, IntPtr, IntPtr).

Examples

The following example assumes that you have created the stream with the BASS_DEFAULT flag. So the buffer will contain 16-bit values...as an array of short values.
VB
' a 30ms window in bytes to be filled with sample data
Dim length As Integer = CInt(Bass.BASS_ChannelSeconds2Bytes(channel, 0.03))

' first we need a mananged object where the sample data should be placed
' length is in bytes, so the number of floats to process is length/2
Dim data(length/2 -1) As Short

' get the sample data
length = Bass.BASS_ChannelGetData(channel, data, length)
// a 30ms window in bytes to be filled with sample data
int length = (int)Bass.BASS_ChannelSeconds2Bytes(channel, 0.03);

// first we need a mananged object where the sample data should be placed
// length is in bytes, so the number of shorts to process is length/2
short[] data = new short[length/2];

// get the sample data
length = Bass.BASS_ChannelGetData(channel, data, length);
See Also

Reference