BASS.NET API for the Un4seen BASS Audio LibraryBassBASS_ChannelGetData Method (Int32, Int32, 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 int[] to reference the buffer data (Note: an int is 32-bit meaning if we expect to receive 16-bit data stereo a single int value will contain 2 x 16-bit, so a full stereo pair of data)! 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:

public static int BASS_ChannelGetData(
	int handle,
	int[] buffer,
	int length


Type: SystemInt32
The channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD.
Type: SystemInt32
The array (int[]) to receive the data, e.g. when creating the channel stream with default setting, meaning 16-bit samples, an int value contains 2 channels (left and right)!
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_FLOAT flag).

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


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).


The following example assumes that you have created the stream with the BASS_DEFAULT flag. So the buffer will contain 16-bit an array of int - meaning one int (32bit) value will represent a stereo pair (left and right channel).
Dim length As Integer = CInt(Bass.BASS_ChannelSeconds2Bytes(channel, 0.03))
Dim data(length/4 - 1) As Integer  ' 2 x 16-bit and length in is bytes
length = Bass.BASS_ChannelGetData(channel, data, length)
' further processing of length/4 array elements...where each int value represents a stereo pair
int length = (int)Bass.BASS_ChannelSeconds2Bytes(channel, 0.03); // 30ms window
int[] data = new int[length/4]; // 2 x 16-bit and length in is bytes
length = Bass.BASS_ChannelGetData(channel, data, length);
// further processing of length/4 array elements...where each int value represents a stereo pair
See Also