“Peak” computes the maximum *absolute* value of the sound within the first “maxlen” samples.

“Absolute” values ignores the sign (+ or -) and looks only at the value, so the absolute value of -3 (minus three) is just “3”.

In the case of your code “peak” is calculating the peak value of the input sounds (aref s 0) and (aref s 1).

Looking at a simple example, let’s say that we have a mono track with a peak amplitude of 0.8 (linear scale).

The audio from the track will be passed to Nyquist in the global variable “s”.

**(peak s 1000000)** will compute the maximum absolute value and return the number “0.8” assuming that the peak is within the first 1000000 samples.

(/ val) is the same as (/ 1 val)

so **(/ (peak s 1000000))** equates to 1/0.8

If we then multiply the sound “s” by (/ (peak s 1000000) the resulting peak value =

“*original peak value*” x 1/“*original peak value*” = 0.8/0.8 = 1

In other words we can normalize the peak amplitude to 1.0 linear scale (= 0 dB) by multiplying the *sound* by 1/“*peak amplitude of the sound*”.

**ny:all** is a built-in value, which in Audacity Nyquist is equal to 1 billion (1000000000)

```
(mult s (/ (peak s ny:all)))
```

##
This code will normalize a mono track to 0 dB (provided that the computer has enough free RAM for the track audio).

\

Ok so far?

With a small modification you your code you could calculate the filtered audio first and then normalize to 0 dB:

```
;control channel "pick a channel to be lowpassed" choice "Left, Right" 0
;control lowpass "Pick Lowpass Frequency" real "Hz" 200 0 13000
;control highpass "Pick Highpass Frequency" real "Hz" 500 0 2000
;; filter audio
(case channel
(0 (setf (aref s 0)(lp (aref s 0) lowpass))
(setf (aref s 1)(hp (aref s 1) highpass)))
(1 (setf (aref s 0)(hp (aref s 0) highpass))
(setf (aref s 1)(lp (aref s 1) lowpass))))
(setq bignum 10000000)
;; normalize channels
(vector
(mult
(/ (peak (aref s 0) bignum))
(aref s 0))
(mult
(/ (peak (aref s 1) bignum))
(aref s 1)))
```

If you prefer to normalize to some value other than 1.0, replace **(/ (peak (aref s 1) bignum))** with **(/ NewAmp (peak (aref s 1) bignum))** where **NewAmp** is the target amplitude. For example, to normalize to -3 dB

```
(mult <sound> (/ (db-to-linear -3.0) (peak <sound> bignum))
```

If you want the output audio to have the same amplitude as the input audio, you would need to compute the peak level of the audio before filtering and the peak level of the audio after filtering, so for the left channel:

```
(setq bignum 10000000)
(setq OldAmp (peak (aref s 0) bignum)
; ....
; filter (aref s 0)
; ....
(setq NewAmp (peak (aref s 0) bignum)
; ....
(mult (/ OldAmp NewAmp)(aref s 0))
```