BASS_ChannelGetLevel


Retrieves the level (peak amplitude) of a sample, stream, MOD music, or recording channel.

DWORD BASS_ChannelGetLevel(
    DWORD handle
);

Parameters

handleThe channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD.

Return value

If an error occurs, -1 is returned, use BASS_ErrorGetCode to get the error code. If successful, the level of the left channel is returned in the low word (low 16 bits), and the level of the right channel is returned in the high word (high 16 bits). If the channel is mono, then the low word is duplicated in the high word. The level ranges linearly from 0 (silent) to 32768 (max). 0 will be returned when a channel is stalled.

Error codes

BASS_ERROR_HANDLEhandle is not a valid channel.
BASS_ERROR_NOPLAYThe channel is not playing.
BASS_ERROR_ENDEDThe decoding channel has reached the end.
BASS_ERROR_BUFLOSTShould not happen... check that a valid window handle was used with BASS_Init.

Remarks

This function measures the level of the channel's sample data, not its level in the final output mix, so the channel's volume (BASS_ATTRIB_VOL attribute) and panning (BASS_ATTRIB_PAN) does not affect it. The effect of any DSP/FX set on the channel is present in the measurement, except for DX8 effects when using the "With FX flag" DX8 effect implementation.

For channels that are more than stereo, the left level will include all left channels (eg. front-left, rear-left, center), and the right will include all right (front-right, rear-right, LFE). If there are an odd number of channels then the left and right levels will include all channels. If the level of each individual channel is required, that is available from BASS_ChannelGetLevelEx.

20ms of data is inspected to calculate the level. When used with a decoding channel, that means 20ms of data needs to be decoded from the channel in order to calculate the level, and that data is then gone, eg. it is not available to a subsequent BASS_ChannelGetData call.

More flexible level retrieval is available with BASS_ChannelGetLevelEx.

Example

Get the left and right levels of a stereo channel.
DWORD level, left, right;
level=BASS_ChannelGetLevel(channel);
left=LOWORD(level); // the left level
right=HIWORD(level); // the right level

See also

BASS_ChannelGetData, BASS_ChannelGetLevelEx, BASS_ChannelIsActive