Retrieves the level of a sample, stream, MOD music, or recording channel.

BOOL BASS_ChannelGetLevelEx(
    DWORD handle,
    float *levels,
    float length,
    DWORD flags


handleThe channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD.
levelsAn array to receive the levels.
lengthThe amount of data to inspect to calculate the level, in seconds. The maximum is 1 second, except for decoding channels. Less data than requested may be used if the full amount is not available, eg. if the channel's playback buffer is shorter.
flagsA combination of these flags.
BASS_LEVEL_MONOGet a mono level. If neither this or the BASS_LEVEL_STEREO flag is used then a separate level is retrieved for each channel.
BASS_LEVEL_NOREMOVEDo not remove the inspected data from a recording channel's buffer. This is automatic if the recording channel is using a RECORDPROC callback function. This flag is ignored on other channel types.
BASS_LEVEL_RMSGet the RMS level. Otherwise the peak level.
BASS_LEVEL_STEREOGet a stereo level. The left level will be from the even channels, and the right level will be from the odd channels. If there are an odd number of channels then the left and right levels will both include all channels.
BASS_LEVEL_VOLPANApply the current BASS_ATTRIB_VOL and BASS_ATTRIB_PAN values to the level reading.

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_ILLPARAMlength is not valid.
BASS_ERROR_NOPLAYThe channel is not playing.
BASS_ERROR_ENDEDThe decoding channel has reached the end.


This function operates in the same way as BASS_ChannelGetLevel but has greater flexibility on how the level is measured. The levels are not clipped, so may exceed +/-1.0 on floating-point channels.

When the BASS_LEVEL_NOREMOVE flag is used to prevent the inspected data being removed from a recording channel's buffer, any DSP/FX set on it will not be present in the level reading, as they are only applied when the data leaves the recording buffer.


Replicate BASS_ChannelGetLevel but with floating-point levels.
float levels[2];
BASS_ChannelGetLevelEx(handle, levels, 0.02, BASS_LEVEL_STEREO);

Get a mono RMS level reading in decibels using 50ms of data.

float level;
BASS_ChannelGetLevelEx(handle, &level, 0.05, BASS_LEVEL_MONO | BASS_LEVEL_RMS); // get the level
float dblevel = (level > 0 ? 20 * log10(level) : -HUGE_VAL); // translate it to dB

Get a peak level reading for each channel using 20ms of data.

BASS_ChannelGetInfo(handle, &ci);
float *levels = (float*)malloc(ci.chans * sizeof(float)); // allocate an array for each channel's level
BASS_ChannelGetLevelEx(handle, levels, 0.02, 0); // get the levels

See also

BASS_ChannelGetData, BASS_ChannelGetLevel, BASS_ChannelIsActive