## Re: [Audacity-nyquist] Problem with Simple Transformations example

 Re: [Audacity-nyquist] Problem with Simple Transformations example From: Roger Dannenberg - 2009-08-11 19:51:32 ```Thanks for your question. Nyquist is correct, but the example and documentation was wrong. (I believe this was developed and tested a long time ago, and probably there was a bug in Nyquist at the time.) Anyway, starting at the last line "(PLAY...)" there is a SUSTAIN transformation on everything. This applies to CHROMATIC-SCALE, which includes TRANSPOSE by PITCH-RISE which is based on RAMP. What's happening is that the SUSTAIN, which was intended to apply only to the durations of OSC-NOTEs, also applies to the RAMP in PITCH-RISE. The initial stretch factor is 0.2, so what would be a 4s ramp is shortened to 4s * 0.2 = 0.8s. If you listen carefully, you'll notice the initial notes are going up in musical 4ths, i.e. 5 semitones, the reciprocal of 0.2. Why does sustain apply to ramps? RAMP might logically be used to construct or control an envelope and you'd want envelopes to scale according to the sustain factor. A fix is shown below: I added (SUSTAIN-ABS 1 ...) to "protect" PITCH-RISE from modification by a SUSTAIN. This is now a good example of how nested environments can easily go awry. Most of the time, anything you write can be stretched or shifted safely and you don't even have to think about it, but when you have continuous controls at different levels of hierarchy, the built-in semantics don't always do "the right thing." -Roger (defun tone-seq () (seqrep (i 16) (stretch 0.25 (osc-note c4)))) (defun pitch-rise () (stretch 4.0 (scale 16 (ramp)))) (defun chromatic-scale () (transpose (sustain-abs 1 (pitch-rise)) (tone-seq))) (play (sustain (stretch 4 (sum 0.2 (ramp))) (chromatic-scale))) John Colket wrote: > Hello, > > I am new to nyquist and was having some difficulties with one of the > examples in the manual under "Simple Transformations" from: > > http://audacity-forum.de/download/edgar/nyquist/nyquist-doc/manual/part4.html#29 > > I start up Audacity, generate 5 seconds of silence, then try to run this > code in the Nyquist prompt: > > (defun tone-seq () (seqrep (i 16) (stretch 0.25 (osc-note c4)))) > (defun pitch-rise () (stretch 4.0 (scale 16 (ramp)))) > (defun chromatic-scale () (transpose (pitch-rise) (tone-seq))) > (play (sustain (stretch 4 (sum 0.2 (ramp))) (chromatic-scale))) > > I am supposed to get a 16 note chromatic scale of varying durations. > Although I do get the varying durations, the pitches are wrong - I get 4 > non-chromatic notes, followed by 12 notes of the same pitch. This is > contrary to what is said in the manual. > > ```

 [Audacity-nyquist] Problem with Simple Transformations example From: John Colket - 2009-08-11 18:45:48 ```Hello, I am new to nyquist and was having some difficulties with one of the examples in the manual under "Simple Transformations" from: http://audacity-forum.de/download/edgar/nyquist/nyquist-doc/manual/part4.html#29 I start up Audacity, generate 5 seconds of silence, then try to run this code in the Nyquist prompt: (defun tone-seq () (seqrep (i 16) (stretch 0.25 (osc-note c4)))) (defun pitch-rise () (stretch 4.0 (scale 16 (ramp)))) (defun chromatic-scale () (transpose (pitch-rise) (tone-seq))) (play (sustain (stretch 4 (sum 0.2 (ramp))) (chromatic-scale))) I am supposed to get a 16 note chromatic scale of varying durations. Although I do get the varying durations, the pitches are wrong - I get 4 non-chromatic notes, followed by 12 notes of the same pitch. This is contrary to what is said in the manual. Note that (play (chromatic-scale)) does seems to work OK. I am running 1.3.8 beta under Windows XP SP3. (Also with Audacity ® 1.3.9-alpha-Aug 10 2009 (Unicode)). I figure I've got misplaced parentheses or something. :) Can anyone tell me what I am doing wrong ? - John ```
 Re: [Audacity-nyquist] Problem with Simple Transformations example From: Roger Dannenberg - 2009-08-11 19:13:57 ```I tried this with Nyquist and hear the same thing. I'll report back when I figure out what's going on. -Roger John Colket wrote: > Hello, > > I am new to nyquist and was having some difficulties with one of the > examples in the manual under "Simple Transformations" from: > > http://audacity-forum.de/download/edgar/nyquist/nyquist-doc/manual/part4.html#29 > > I start up Audacity, generate 5 seconds of silence, then try to run this > code in the Nyquist prompt: > > (defun tone-seq () (seqrep (i 16) (stretch 0.25 (osc-note c4)))) > (defun pitch-rise () (stretch 4.0 (scale 16 (ramp)))) > (defun chromatic-scale () (transpose (pitch-rise) (tone-seq))) > (play (sustain (stretch 4 (sum 0.2 (ramp))) (chromatic-scale))) > > I am supposed to get a 16 note chromatic scale of varying durations. > Although I do get the varying durations, the pitches are wrong - I get 4 > non-chromatic notes, followed by 12 notes of the same pitch. This is > contrary to what is said in the manual. > > > ```
 Re: [Audacity-nyquist] Problem with Simple Transformations example From: Roger Dannenberg - 2009-08-11 19:51:32 ```Thanks for your question. Nyquist is correct, but the example and documentation was wrong. (I believe this was developed and tested a long time ago, and probably there was a bug in Nyquist at the time.) Anyway, starting at the last line "(PLAY...)" there is a SUSTAIN transformation on everything. This applies to CHROMATIC-SCALE, which includes TRANSPOSE by PITCH-RISE which is based on RAMP. What's happening is that the SUSTAIN, which was intended to apply only to the durations of OSC-NOTEs, also applies to the RAMP in PITCH-RISE. The initial stretch factor is 0.2, so what would be a 4s ramp is shortened to 4s * 0.2 = 0.8s. If you listen carefully, you'll notice the initial notes are going up in musical 4ths, i.e. 5 semitones, the reciprocal of 0.2. Why does sustain apply to ramps? RAMP might logically be used to construct or control an envelope and you'd want envelopes to scale according to the sustain factor. A fix is shown below: I added (SUSTAIN-ABS 1 ...) to "protect" PITCH-RISE from modification by a SUSTAIN. This is now a good example of how nested environments can easily go awry. Most of the time, anything you write can be stretched or shifted safely and you don't even have to think about it, but when you have continuous controls at different levels of hierarchy, the built-in semantics don't always do "the right thing." -Roger (defun tone-seq () (seqrep (i 16) (stretch 0.25 (osc-note c4)))) (defun pitch-rise () (stretch 4.0 (scale 16 (ramp)))) (defun chromatic-scale () (transpose (sustain-abs 1 (pitch-rise)) (tone-seq))) (play (sustain (stretch 4 (sum 0.2 (ramp))) (chromatic-scale))) John Colket wrote: > Hello, > > I am new to nyquist and was having some difficulties with one of the > examples in the manual under "Simple Transformations" from: > > http://audacity-forum.de/download/edgar/nyquist/nyquist-doc/manual/part4.html#29 > > I start up Audacity, generate 5 seconds of silence, then try to run this > code in the Nyquist prompt: > > (defun tone-seq () (seqrep (i 16) (stretch 0.25 (osc-note c4)))) > (defun pitch-rise () (stretch 4.0 (scale 16 (ramp)))) > (defun chromatic-scale () (transpose (pitch-rise) (tone-seq))) > (play (sustain (stretch 4 (sum 0.2 (ramp))) (chromatic-scale))) > > I am supposed to get a 16 note chromatic scale of varying durations. > Although I do get the varying durations, the pitches are wrong - I get 4 > non-chromatic notes, followed by 12 notes of the same pitch. This is > contrary to what is said in the manual. > > ```