Nyquist beginner -- how to copy *warp* from one wave to another

So, I’m a programmer, but just beginning to grapple with the concepts in nyquist (using SAL), and ran into this:

I’m generating waves of fixed lengths, and have a calculated waveform in a variable of say 3 seconds in length. I then wish to do something with that wave, for instance frequency modulate it

But:

hzosc(2000) * myWave

will give a 1 second wave (assuming no selection, and I think because warp of the hzosc() call is 1 second.

Whereas:

hzosc(2000) ~~ 20 * myWave

will give the required 3 second waveform, but is wasteful in resources, hardcoded, and breaks when myWave exceeds 20seconds…

So… how to set the warp of the hzsoc() call to be the length of warp in myWave? Or am I not understanding the concepts correctly?

Thankyou.

I’m not very familiar with SAL as I always use LISP syntax for Nyquist.

Handling warp correctly is one of the more difficult aspects of Nyquist, but fortunately it is rare that you need to deal with it directly.

There is an important difference between stand alone Nyquist (which is what the Nyquist manual refers to), and Nyquist in Audacity:

In Audacity, time is handled differently for “process” type effects than for “analyze” or “generate” type plug-ins (https://wiki.audacityteam.org/wiki/Nyquist_Plug-in_Headers#type)

For “analyze” and “generate” type effects, 1 unit of time = 1 second (in other words, the local environment uses “absolute” time). Thus:

;type generate
(osc 72 3)

will generate a 3 second tone.

In the case of “process” effects, 1 unit of time = the length of the selection. Thus:

;type process
(osc 72 3)

will generate a tone that is 3 times longer than the selection.

If you need to use “absolute” time in a process type plug-in, you can do so using the ABS-ENV command:

;type process
(abs-env (osc 72 3))

Thankyou Steve!

I may go to LISP, I can translate, but I write SAL at the moment, as I come from a C heritage. :slight_smile:

I understand this differences you mention, but they don’t answer my question: I’ve programmatically created a wave of arbitary length - I don’t know the length (in absolute time) that I want to use.

;type generate
(abs-env (osc 72 x))

I’m trying to derive the “x” to use in this, given a waveform passed to a procedure in a variable.

Does this help:

;type generate

(setf tone (osc 70 3)) ;a 3 second tone

;Find the length of "tone"
(setf duration (/ (snd-length tone ny:all) *sound-srate*))

(mult tone (stretch duration (hzosc 2)))

or more generally:

;type generate

(setf tone (osc 70 3)) ;a 3 second tone

(defun modulate (sig hz)
  (let ((dur (/ (snd-length sig ny:all)(snd-srate sig))))
    (mult sig (osc (hz-to-step hz) dur))))

(modulate tone 4)

Perfect, thankyou.

I’d seen snd-length() but thought there was another way - in that I thought there was a WARP structure associated with the wave that I could access - rather than calculating the whole wave in memory.

Generally it would be preferable to create the sound in a way that the length is known.