BASS.NET API for the Un4seen BASS Audio LibraryBassBASS_ChannelGetData Method (Int32, Byte, 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 byte[] to reference the buffer data! SHOULD ONLY BE USED, if the stream was created with 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,
	byte[] buffer,
	int length
)

Parameters

handle
Type: SystemInt32
The channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD.
buffer
Type: SystemByte
The array (byte[]) to receive the data, e.g. when creating the channel with BASS_SAMPLE_8BITS!
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_FLOAT flag).

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_SAMPLE_8BITS flag. So the buffer will contain 8-bit values...as an array of byte.
VB
Dim length As Integer = CInt(Bass.BASS_ChannelSeconds2Bytes(channel, 0.03))
Dim data(length - 1) As Byte
length = Bass.BASS_ChannelGetData(channel, data, length)
int length = (int)Bass.BASS_ChannelSeconds2Bytes(channel, 0.03); // 30ms window
byte[] data = new byte[length]; // 8-bit are bytes
length = Bass.BASS_ChannelGetData(channel, data, length);
See Also

Reference