Moving form nyquist prompt to nyquist plugin

Hi all,

Sorry for this basic question but I am starting with audacity.

In a previous topic, steve gave me some code to give the rms level every 100 ms. I want to customize this in the future (ask for the time window size…) but as I am using it quite a lot on different files, I wanted to insert it in a menu as a plugin.

However after starting, restarting of audacity the plugin is not showing up.

Here is the code

;nyquist plug-in
;version 1
;type analyze
;name " Rms sampling… "
;action " Rms sampling the selection every 100 ms… "

; code given by steve

(let* ((labels ())
      (rmss (rms s))
      (sr (snd-srate rmss)))
  (do ((i 0 (1+ i))
       (val (snd-fetch rmss)(snd-fetch rmss)))
      ((not val) labels)
    (setq val (linear-to-db val))
    (push (list (/ i sr) (format nil "~a" val))

I saved this file as Rms sampling.ny in the plug-ins folder in the Audacity folder.

I don’t understand where is my error? :blush:

Thanks for the help


Audacity 2.0.5 under MacOS 10.9.1

I guess it was a side effect from the MacOS Textedit app.

By default, it is formatting the text as rtf adding certainly some invisible data.

I saved the plugin program after applying the plaintext option and it is showing up now in the correct menu now.

If anyone has a better editor to advise on MacOS, I will consider it with great attention ! :wink:

For Windows I’d recommend Notepad++.
I Googled for a Mac equivalent and the suggestion was TextWrangler
(I don’t use Macs).

“version 1” plug-ins should be compatible with Audacity 1.2.x. Unless you are sure that the plug-in is compatible with such ancient versions of Audacity I’d recommend marking it as “version 3” in the header. The most obvious differences between version 1, 2 and 3 plug-ins are which sort of “widgets” (GUI controls) are supported, but there are other features that have been added over the years that may break backward compatibility.

Also, there is a plug-in naming convention. If the plug-in produces a user interface (for additional user input), then the plug-in name should end with “…”. If the plug-in acts immediately with no GUI or user input, then just the name and no ellipsis (dots). This is consistent with, for example the “Fade Out” effect (no dots) and “Amplify…” (with dots).

Other than that, congratulations with your first plug-in :nerd:

Thanks again Steve

I would like to customize this plugin (changing the time window of analysis, giving additional informations: min, max…).

However, I need to learn more on LISP and Nyquist language.

For LISP, with some C knowdledge, I guess it will be ok. However, for Nyquist, it will be more difficult.

Of course, there is the reference manual but I didn’t see many sites with examples or code snippets. What about any books ?

I will try step by step perhaps asking for some help from the experts in this board section! :unamused:

Nyquist is basically XLisp with an extra data type - a “sound” - and a load of additional built in functions.

There is one tricky concept that you will run into, and that is “behavioral abstraction” the “transformation environment”. You can go quite a long way in Nyquist without worrying about this, so I’d suggest that you ignore that for now and it will become clearer as you get to know Nyquist.

The “additional built in functions” are listed in the Nyquist reference manual in the language reference section: Index

The XLisp manual also has a language reference section which is extremely useful as it contains examples for each XLisp function: XLISP Language Reference

Also the Audacity Nyquist plug-ins reference: Missing features - Audacity Support

The RMS function is described in the Nyquist manual here: Nyquist Functions
(rms sound [rate window-size])
As you can see, the function supports two optional parameters, rate and window-size. If you supply one optional parameter, that will be “rate”. If you supply both optional parameters, the first will be “rate” and the second will be “window size”. See the description in the manual for more details.

In order to allow user input you will need to add a control widget in the plug-in header. For example you could use a “slider widget” (Missing features - Audacity Support).

Try to use meaningful names for variables. Better to be verbose than obscure :wink:

So for example:

;control window-size "Window size" real "milliseconds" 100 1 1000

will give you a variable called “window-size” with a default value of 100, and a minimum slider range of 1, and a maximum slider range of 1000.
Because (in “text right”) it says that the units are milliseconds, you will need to convert that to seconds:

(setq window-size (/ window-size 1000.0))

We know that if we only supply one of the optional parameters, it will be “rate”, and then the window size will be 1/rate seconds, so we need to convert our user input into a “rate” value.

(setq rate (/ window-size))

Note that is we don’t specify the dividend, it is assumed to be 1. Thus (/ val) is exactly the same as (/ 1 val).
One word of caution, “1” is an integer, so if the divisor “val” is an integer the answer will be calculated using integer arithmetic and the answer will always be zero, so only do this if you know for sure that “val” is a float (floating point value), otherwise write it in full as (/ 1.0 val).

So we have rate ( /second), which we can now use in our code, replacing (rms s) with (rms s rate).

Thanks steve

I have a lot to read, test and retest…

I am happy with the analysis around 100 ms. Just to explain that for people who are interested in speech analysis: measuring rms value of the whole file does not make sense in terms of audiology even if it makes sense mathematically. You have to consider the mean duration of a speech phoneme (vowels have a longer duration and a higher energy than consonants).

EG: Imagine I want to develop an hearing test in noise: the patients will have to recognize key words in a sentence with a competing background noise (stationary speech noise, multitalker babble…). The difficulty of the test is relative to the S/N ratio. Classically you have to adjust the RMS level of the speech with the RMS level of the noise in order to obtain a precise SNR. However, you can imagine that with the same RMS you can obtain different results depending on the level of the noise occuring when the speaker says the word. To be more rigourous, one solution is to time lock the speech versus the noise and to measure rms levels but with a time basis adapted to the duration of the word (a vlaue between 50- 200 ms makes sense).

It is perhaps not so clear for non audiologists and a little off topic :blush: but it can be helpful for people interested in that topic.