Thanks vpd. Nice to see someone modifying the plug-in to suit their needs. That's one of the great things about Nyquist plug-ins

Your code works fine.

A couple of notes from a programming perspective that may be useful for you (or disregard if not

)

- Code: Select all
`(setq selected (/ len *sound-srate*))`

(setq time (min 20 (max 0 selected))) ; 0 < time < 20

(setq bignum (truncate (* time *sound-srate*)))

(setq step (truncate (min bignum LEN))) ; 'peak' requires blocksize and stepsize as integers

As there is no duration control in this version, this code can be simplified:

- Code: Select all
`(setq time 20)`

(setq bignum (truncate (* time *sound-srate*)))

(setq step (truncate (min LEN bignum)))

In fact it could be simplified into one line, but as we need "bignum" and "time" later on for the messages they may as well all be set here.

- Code: Select all
`(defun s-rms (s-in)`

(linear-to-dB (sqrt (peak (snd-avg (mult s-in s-in) step step OP-AVERAGE) bignum))))

(defun x-rms (s-in)

(* (sqrt (peak (snd-avg (mult s-in s-in) step step OP-AVERAGE) bignum)) 100))

We don't really need to calculate the rms level twice (although it really makes very little difference in this case because we are only processing a few seconds of audio).

We could just calculate the rms once as a linear value:

- Code: Select all
`(defun s-rms (s-in)`

(sqrt (peak (snd-avg (mult s-in s-in) step step OP-AVERAGE) bignum)))

(setq rms-lin (s-rms s-in))

Then convert to dB or % as required.

- Code: Select all
`(print (linear-to-db rms-lin))`

(print (* rms-lin 100))