Moving form nyquist prompt to nyquist plugin

Using Nyquist scripts in Audacity.
Post and download new plug-ins.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Post Reply
chris2lamb
Posts: 22
Joined: Thu Jan 09, 2014 2:58 pm
Operating System: Please select

Moving form nyquist prompt to nyquist plugin

Post by chris2lamb » Thu Jan 23, 2014 3:51 pm

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

Code: Select all

;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))
          labels)))
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? :oops:

Thanks for the help

Chris

Audacity 2.0.5 under MacOS 10.9.1

chris2lamb
Posts: 22
Joined: Thu Jan 09, 2014 2:58 pm
Operating System: Please select

Re: Moving form nyquist prompt to nyquist plugin

Post by chris2lamb » Thu Jan 23, 2014 4:28 pm

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 ! ;)

steve
Site Admin
Posts: 80679
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Moving form nyquist prompt to nyquist plugin

Post by steve » Thu Jan 23, 2014 5:09 pm

For Windows I'd recommend Notepad++.
I Googled for a Mac equivalent and the suggestion was TextWrangler https://itunes.apple.com/gb/app/id40401 ... Id=1736887
(I don't use Macs).
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

steve
Site Admin
Posts: 80679
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Moving form nyquist prompt to nyquist plugin

Post by steve » Thu Jan 23, 2014 5:27 pm

"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 :geek:
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

chris2lamb
Posts: 22
Joined: Thu Jan 09, 2014 2:58 pm
Operating System: Please select

Re: Moving form nyquist prompt to nyquist plugin

Post by chris2lamb » Fri Jan 24, 2014 7:27 am

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! :roll:

steve
Site Admin
Posts: 80679
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Moving form nyquist prompt to nyquist plugin

Post by steve » Fri Jan 24, 2014 12:44 pm

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: http://www.cs.cmu.edu/~rbd/doc/nyquist/indx.html

The XLisp manual also has a language reference section which is extremely useful as it contains examples for each XLisp function: http://www.audacity-forum.de/download/e ... -index.htm

Also the Audacity Nyquist plug-ins reference: http://wiki.audacityteam.org/wiki/Nyqui ... _Reference

chris2lamb wrote:I would like to customize this plugin (changing the time window of analysis, giving additional informations: min, max...)
The RMS function is described in the Nyquist manual here: http://www.audacity-forum.de/download/e ... l#index381
(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" (http://wiki.audacityteam.org/wiki/Nyqui ... der_Widget).

Try to use meaningful names for variables. Better to be verbose than obscure ;)

So for example:

Code: Select all

;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:

Code: Select all

(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.

Code: Select all

(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).
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

chris2lamb
Posts: 22
Joined: Thu Jan 09, 2014 2:58 pm
Operating System: Please select

Re: Moving form nyquist prompt to nyquist plugin

Post by chris2lamb » Mon Jan 27, 2014 5:18 pm

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 :oops: but it can be helpful for people interested in that topic.

Post Reply