Blitz3D+ Command Reference

AudioMasterRMS# ( [speaker] )

Parameters

speaker (optional) - speaker index; 0 aggregates all speakers (default)

Description

Returns the master RMS amplitude from the last audio block.

Metering must be enabled with AudioMasterMeter. Returns a linear amplitude from the last audio processing block. Values above 1 are valid. Speaker 0 aggregates all speakers: peak is the maximum, RMS is the square root of the mean squared speaker RMS. Speakers 1..N follow the output speaker-mask bit order: stereo L/R; 5.1 FL/FR/FC/LFE/BL/BR (or SL/SR for the side layout); 7.1 FL/FR/FC/LFE/BL/BR/SL/SR. Disabled meters return 0. Invalid indexes return 0 and set AudioLastError. Successful queries preserve the previous error. Readings are neither peak hold nor LUFS.

Call InitAudioEffects before the first WAV/Ogg playback. Configuration commands return 1 on success or 0 on failure; use AudioLastError for the reason. Finite numeric values and valid handles are required in Debug and Release. Queries preserve errors unless the query itself fails.

Audio effects process decoded WAV and mono/stereo Ogg at an internal 48 kHz. MIDI uses a separate backend. Sound defaults are copied to independent playing channels. Runtime pause freezes sources, tails and transition time; pausing one channel leaves shared tails running. Event waits service transitions and release completed source resources without ChannelPlaying polling. Lightweight completed handles are retained until program shutdown.

The interactive Audio Playground sample demonstrates the whole effects family together.

Requires Extended mode.

See also: AudioMasterPeak, AudioMasterMeter, AudioGroupRMS.

Example

; AudioMasterRMS Example
; ----------------------
; Requires Extended mode.

; Effects must be initialized before the first WAV/Ogg playback
If Not InitAudioEffects() Then RuntimeError AudioLastError$()

Graphics 640,480,0,2
SetBuffer BackBuffer()

; A looping machine hum to hear the effect on
sound=LoadSound("../../../samples/audio/media/machine.wav")
If sound=0 Then RuntimeError "The audio sample media is missing."
LoopSound sound
SoundVolume sound,0.25

; Meters make the audio state visible on screen
RequireAudio AudioMasterMeter(True)
RequireAudio AudioGroupMeter(0,True)

speaker=0

channel=PlaySound(sound)
If channel=0 Then RuntimeError "Unable to play the example sound."

While Not KeyDown(1)

    ; [ / ] choose a speaker index; 0 aggregates all speakers
    If KeyHit(26) And speaker>0 Then speaker=speaker-1
    If KeyHit(27) And speaker<2 Then speaker=speaker+1

    Cls
    Text 0,0,"[ / ] : speaker index   Esc: exit"
    Text 0,20,"AudioMasterRMS("+speaker+") = "+AudioMasterRMS(speaker)
    Text 0,40,"RMS is the average loudness of the last block, not a peak hold"
    Text 0,80,"Group 0 peak: "+AudioGroupPeak(0)+"   RMS: "+AudioGroupRMS(0)
    Text 0,100,"Master peak: "+AudioMasterPeak()+"   RMS: "+AudioMasterRMS()

    Flip

Wend

; Let shared effect tails fade before the program ends
For group=0 To 3
    RequireAudio AudioGroupClearEffects(group)
Next
StopChannel channel
FreeSound sound

End

; Stop with the recorded reason if an audio-effects call fails
Function RequireAudio(success)
    If Not success Then RuntimeError AudioLastError$()
End Function

Index