Plugin I coded gaves me the error "Nyquist returned 44100"

Hi, people!
I’m coding a plugin in Nyquist. The idea is very simple, but actually I’m newbie in the LISP language and Nyquist at all…
The idea is to add some harmonics to the audio, on each time sample. Based on the current pitch of the sample. Have anyone ever coded it yet and released? I’m stuck…
There are two questions I’d like to ask:

  1. I’m assuming I could use the returned snd-fetch value as the pitch… Is it a mistake? If so, can I retrieve the pitch of the sound samples, somehow?
  2. Why Nyquist returns 44100? It must be the sample rate, and not a SOUND that is returning from the code…
    Finally, here’s the code (still not documented yet, but it’s very small):
;nyquist plug-in
;version 1
;type process
;name "APedrodx"
;action "TODO..."
;info "TODO..."

(defun mkwave ()
	(setf *table* (sim (scale 0.5  (build-harmonic 1.0 2048))
				 (scale 0.25  (build-harmonic 2.0 2048))
				 (scale 0.125 (build-harmonic 3.0 2048))
				 (scale 0.062 (build-harmonic 4.0 2048))))
	(setf *table* (list *table* (hz-to-step 1) T))

(defun note (time pitch dur)
	(at time (osc pitch dur *table*))

(cond ((not (boundp '*mkwave*))
	(setf *mkwave* t))
(setf my-srate (snd-srate s))
(setf my-ret
	(do ((n 1 (+ n 1)) (v (snd-fetch s) (setf v (snd-fetch s))) (my-s (snd-copy s) (sim (cue my-s) (note (/ n my-srate) v 0.1))))
		((not v) my-s)

Thanks in advance, people!

Could you save me some time and talk me through your final “do” loop.

Thanks, stevethefiddle!

(do ((n 1 (+ n 1)) (v (snd-fetch s) (setf v (snd-fetch s))) (my-s (snd-copy s) (sim (cue my-s) (note (/ n my-srate) v 0.1))))
      ((not v) my-s)

The idea (the one I want to) is to return a SOUND to Audacity.
So, the loop initializes and sets 3 (three) variables, throughout the loop. These variables are n, v, and my-s.
I really don’t know if this statement is, as well, working.
But, here we go. v will fetch the amplitude (which I desire to be as the pitch as well, but don’t know) of the sound sample on each iteration of the ‘do’. Then, the (my-s (snd-copy s) (sim (cue my-s) (note (/ n my-srate) v 0.1))) statement initializes my-s as a copy of the sound selected in Audacity, and, on each iteration, adds a few harmonics with the (sim (cue my-s) (note (/ n my-srate) v 0.1)) statement.
Please, note the ‘v’ variable used in the ‘note’ function call. This is supposed to be the pitch of the harmonics…
Anyway, I might be missing something on the overall syntax…
Thanks for the help!!
EDIT - the loop exits when we ran out of samples (I based on the Silence Marker plugin to learn some tricks…)

Hi, stevethefiddler!
I probably discovered what I’m doing wrong.
When I’m adding a few harmonics to my-s, I should NOT like “incrementing” this sound, (e.g., (setf my-s (sim my-s (note (…))))).
I should try to create a new sound, and set like this (setf new-s (sim my-s (note (…)))).
Wherever, I have some questions, can you please answer to me?

  1. What is the range of the sample values, as stored in the Audacity audio files (the same obtained from snd-fetch)? What do they mean (are really the amplitude of the sound)?
  2. I checked the reference of Nyquist, and found a fundamental frequency estimation function (pitch) (yin), and tried on Audacity. It didn’t work. Does Audacity support this function? Please, note I might not have the latest Audacity version… Do they updated recently?

Anyway, thanks for the support!!

I’m not an expert with Nyquist, but I may be able to give a few pointers:

“Do” loops - a simple example which will hopefully make the syntax a bit more clear:

;; (do (binding...) (texpr rexpr...) expr...)
;; "Binding" using a list of the form: (sym init [step]) where:
;;   sym - is the symbol to bind
;;   init - is the initial value of the symbol
;;   step - is a step expression

(setf result s) ; initialising "result" as the sound

;The loop construct
(do  ((j 1 (+ j 1))) ; This is the "binding"
((= j 10)) ; This is the "test expression"
(setf result (mult 0.9 result)) ; the loop body - in this case, just scaling the sound repeatedly


The amplitude of sound values (as returned by (setf v (snd-fetch s)) are between +1 and -1 (the same as the vertical scale on the track) - they are the actual numerical values of the individual samples.

I don’t think that Nyquist in Audacity includes the function “yin”

Nyquist does not get updated in Audacity very often, and even then they only tend to be quite minor changes.

The Nyquist experts seem to hang out at the Audacity Nyquist Mailing List, which can be found here:

Thanks, stevethefiddle!
Your information was very useful…
If I code any plugin that make some effect interesting, I’d like the community to enjoy it as well… :slight_smile:

You’re welcome. It’s good to see some interest in Nyquist. It’s a fantastic, but it seems mostly neglected, feature of Audacity.
I’ve got a few Nyquist projects of my own on the go at the moment. I hope to be able to reveal some results early in the new year.