BASS_ChannelLock

Locks a stream, MOD music or recording channel to the current thread.

BOOL BASS_ChannelLock(
    DWORD handle,
    BOOL lock
);

Parameters

handleThe channel handle... a HMUSIC, HSTREAM or HRECORD.
lockLock or unlock the channel... TRUE = lock, FALSE = unlock.

Return value

If successful, TRUE is returned, else FALSE is returned. Use BASS_ErrorGetCode to get the error code.

Error codes

BASS_ERROR_HANDLEhandle is not a valid channel.
BASS_ERROR_ALREADYThe channel is already unlocked.
BASS_ERROR_FREEINGThe channel cannot be locked because it is being freed.

Remarks

Locking a channel blocks other threads from processing it (decoding and related functions) or locking it. Those other threads will have to wait until the channel is unlocked, so it should only be locked briefly. Freeing the channel (in any thread) is also blocked, and when that happens only this function (and BASS_ChannelRef) can subsequently be used to unblock it; other functions will fail with a BASS_ERROR_FREEING error.

Recursive locking is supported. Each lock must be matched by an unlock in the same thread.

Example

Lock a channel to ensure that 2 DSP functions start together.
if (BASS_ChannelLock(channel, true)) { // lock channel
    BASS_ChannelSetDSP(channel, DspProc1, NULL, 0); // set 1st DSP
    BASS_ChannelSetDSP(channel, DspProc2, NULL, 0); // set 2nd DSP
    BASS_ChannelLock(channel, false); // unlock channel
}

See also

BASS_ChannelRef