BASS.NET API for the Un4seen BASS Audio LibraryBassBASS_SampleGetChannel Method BASS.NET API for the Un4seen BASS Audio Library
Creates/initializes a playback channel for a sample.

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

[DllImportAttribute("bass.dll", CharSet = CharSet.Unicode)]
public static int BASS_SampleGetChannel(
	int handle,
	bool onlynew


Type: SystemInt32
Handle of the sample to play.
Type: SystemBoolean
Do not recycle/override one of the sample's existing channels?

Return Value

Type: Int32
If successful, the handle of the new channel is returned, else 0 is returned. Use BASS_ErrorGetCode to get the error code.

Use BASS_SampleGetInfo(Int32, BASS_SAMPLE) and BASS_SampleSetInfo(Int32, BASS_SAMPLE) to set a sample's default attributes, which are used when creating a channel. After creation, a channel's attributes can be changed via BASS_ChannelSetAttribute(Int32, BASSAttribute, Single), BASS_ChannelSet3DAttributes(Int32, BASS3DMode, Single, Single, Int32, Int32, Int32) and BASS_ChannelSet3DPosition(Int32, BASS_3DVECTOR, BASS_3DVECTOR, BASS_3DVECTOR). BASS_Apply3D should be called before starting playback of a 3D sample, even if you just want to use the default settings.

If a sample has a maximum number of simultaneous playbacks of 1 (the max parameter was 1 when calling BASS_SampleLoad(String, Int64, Int32, Int32, BASSFlag) or BASS_SampleCreate(Int32, Int32, Int32, Int32, BASSFlag)), then the HCHANNEL handle returned will be identical to the HSAMPLE handle. That means you can use the HSAMPLE handle with functions that usually require a HCHANNEL handle, but you must still call this function first to initialize the channel.

A sample channel is automatically freed when it's overridden by a new channel, or when stopped manually via BASS_ChannelStop(Int32), BASS_SampleStop(Int32) or BASS_Stop. If you wish to stop a channel and re-use it, it should be paused (BASS_ChannelPause(Int32)) instead of stopped. Determining whether a channel still exists can be done by trying to use the handle in a function call, eg. BASS_ChannelGetAttribute(Int32, BASSAttribute, Single).

When channel overriding has been enabled via a BASS_SAMPLE_OVER flag and there are multiple candidates for overriding (eg. with identical volume), the oldest of them will be chosen to make way for the new channel.

The new channel will have an initial state of being paused (BASS_ACTIVE_PAUSED). This prevents the channel being claimed by another call of this function before it has been played, unless it gets overridden due to a lack of free channels.

All of a sample's channels share the same sample data, and just have their own individual playback state information (volume/position/etc).

ERROR CODEDescription
BASS_ERROR_HANDLEhandle is not a valid sample handle.
BASS_ERROR_NOCHANThe sample has no free channels... the maximum number of simultaneous playbacks has been reached, and no BASS_SAMPLE_OVER flag was specified for the sample or onlynew = .
BASS_ERROR_TIMEOUTThe sample's minimum time gap (BASS_SAMPLE) has not yet passed since the last channel was created.


Play a sample with it's default settings:
Dim sample As Integer = Bass.BASS_SampleLoad("test.wav", 0L.ToUInt32(), 0, 1, BASSFlag.BASS_DEFAULT)
Dim channel As Integer = Bass.BASS_SampleGetChannel(sample, False) ' get a sample channel
Bass.BASS_ChannelPlay(channel, False) ' play it
int sample = Bass.BASS_SampleLoad("test.wav", 0L, 0, 1, BASSFlag.BASS_DEFAULT);
int channel = Bass.BASS_SampleGetChannel(sample, false); // get a sample channel
Bass.BASS_ChannelPlay(channel, false); // play it
See Also