Cabbage Logo
Back to Cabbage Site

Help how to create a decibel level meter?

Need to create a RMS an Peak meter in dBFS scale. any idea? thanks

Maybe this is start? Meters are just displayed using sliders but I’m sure you can come up with something prettier using images or gentables.

<Cabbage>
form caption("Untitled") size(400, 310), colour(58, 110, 182), pluginID("def1")
vslider bounds(25,5, 20, 300), channel("meter"), range(-90, 0, -90)
vslider bounds(75,5, 20, 300), channel("meter_peak"), range(-90, 0, -90)

    </Cabbage>
    <CsoundSynthesizer>
    <CsOptions>
    -n -d -+rtmidi=NULL -M0 -m0d 
    </CsOptions>
    <CsInstruments>
    ; Initialize the global variables. 
    sr = 44100
    ksmps = 8
    nchnls = 2
    0dbfs = 1


    instr 1
     aInL	inch	1
     krms	rms		aInL					; scan rms
     kdb	=		dbfsamp(krms)			; convert to db
     kpeak	init	-90						; initialise peak value
     if metro(0.5)==1 then					; reset peak hold
      kpeak	=	-90
     endif
     kpeak	=		kdb>kpeak?kdb:kpeak		; compare stored peak value with current db value
     kpeakP	port	kpeak,0.05				; smooth changes of peak value
      if metro(16)==1 then					; peg update of widgets
     	chnset	kdb,"meter"
     	chnset	kpeakP,"meter_peak"
     endif
    endin

    </CsInstruments>
    <CsScore>
    ;causes Csound to run for about 7000 years...
    f0 z
    ;starts instrument 1 and runs it for a week
    i1 0 [60*60*24*7] 
    </CsScore>
    </CsoundSynthesizer>

Hey there,

If anyone is interested, here’s a metering simulation using checkboxes.

Metering.csd (6.5 KB)

Description in comment header.

Cheers!

That looks nice. Here’s another approach that uses tables. It could be reduced even further if I hadn’t bothered with indicators for when peak amplitude is reached. Let me know if you have any questions about, it’s not very well commented! Metering2.csd (1.7 KB)

This looks cool! Quite a low footprint on this. Also, why does colour gradient not work when table size is greater than 2? It says so in the manual too, but I just wanted to know the reason.

Because I limited it to 2 for the purpose of VU meters. Cabbage2 will probably just have a dedicated VU meter widget. Everything will be better in Cabbage 2! :wink:

Hi…The best audio to measure in my opinion is white noise because its full-frequency. It’s also worth moving around a bit and take readings at different spots. Sometimes the room can cause standing waves and frequencies almost silent at one spot can be much louder even a foot away.

printed circuit board