How to simulate analog VU meter response to audio?

I'd like to simulate the movement of an analog VU meter dial as shown below and often found on stereos and other music monitoring equipment.

I just learned through this article by Rod Elliot (ESP) and Wikipedia that the response of a VU meter is standardized and designed to measure the perceived loudness of audio signals.

A VU meter is designed to have a relatively slow response. It is driven from a full-wave averaging circuit defined to reach 99% full-scale deflection in 300ms and overshoot not less than 1% and not more than 1.5%. Since a VU meter is optimised for perceived loudness it is not a good indicator of peak (transient) performance. Nominal sensitivity for 0VU is 1.228V RMS, and the impedance is 3.9k.

I'm playing with music visualization and data processing and a measure of perceived loudness is precisely what I need. I also like the analog nature of the response.

I'd like to implement this in an algorithm in Python (for an entire music file) and later perhaps in Processing (live processing in batches). The underlying implementation will probably be very similar.

How can I generate the response from raw audio data to match the specifications of a VU meter?

• this is called meter ballistics. it's a form of a low-pass filter on the output of either squaring or absolute value (rectified) of the data. – robert bristow-johnson Jun 13 '18 at 0:24

if you have input signal as vector of floating point numbers, try following code. It won't behave as real VU meter, but by modifying two constants you should get something very similar. Visualize the value of C in logarithmical scale

// memory element (can be imagined as capacitor)
c = 0
kCharge = 0.1
kDischarge = 0.001

for each sample x:
{
// rectify the signal
x1 = abs(x)

if x1 > c then
{
// charge
c = c * (1-kCharge) + x1*kCharge
} else
{
// discharge
c = c * (1-kDischarge)
}
}