Creates/initializes a playback channel for a sample.
DWORD BASS_SampleGetChannel( HSAMPLE handle, DWORD flags );
handle | Handle of the sample. | ||||||||||||||||||
flags | A combination of these flags.
|
BASS_ERROR_HANDLE | handle is not a valid sample handle. |
BASS_ERROR_NOCHAN | The sample has no free channels, and the BASS_SAMCHAN_NEW flag was specified or no BASS_SAMPLE_OVER flag was. |
BASS_ERROR_TIMEOUT | The sample's minimum time gap (see BASS_SAMPLE) has not yet passed since the last channel was created. |
BASS_ERROR_NOTAVAIL | The BASS_STREAM_AUTOFREE flag cannot be combined with the BASS_STREAM_DECODE flag. |
BASS_ERROR_SPEAKER | The specified SPEAKER flags are invalid. |
Use BASS_SampleGetInfo and BASS_SampleSetInfo 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, BASS_ChannelSet3DAttributes and BASS_ChannelSet3DPosition. BASS_Apply3D should be called before starting playback of a 3D sample, even if you just want to use the default settings.
The number of sample streams (HSTREAM) is unlimited. The number of sample channels (HCHANNEL) is limited to the sample's max value (set during creation or via BASS_SampleSetInfo), and existing channels can be overridden when needed for new ones. 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.
If a sample has a max setting of 1 then a HCHANNEL handle (not HSTREAM) returned will be identical to the HSAMPLE handle (unless disabled via the BASS_CONFIG_SAMPLE_ONEHANDLE config option). This 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 (HCHANNEL) is automatically freed when it is overridden by a new channel, or when stopped by BASS_ChannelStop, BASS_SampleStop or BASS_Stop. If you wish to stop a channel and re-use it, BASS_ChannelPause should be used to pause it instead. Determining whether a channel still exists can be done by trying to use the handle in a function call. A list of all the sample's existing channels can also be retrieved via BASS_SampleGetChannels.
A new sample channel (HCHANNEL) 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.
HCHANNEL channel = BASS_SampleGetChannel(sample, 0); // get a sample channel BASS_ChannelStart(channel); // play it