Question

I wish to use the Nyquist Prompt plugin in Audacity to construct a piece-wise linear waveform of 2048 samples in length. For example, I can generate a square pulse wave by starting with 2048 silent (zero) samples, selecting all, and then invoking the Nyquist Prompt with:

(sum s (pwl
  0 1
  0.5 1
  0.5))

This uses the piece-wise linear (pwl) function to create a waveform that starts at time 0, level 1.0, then linearly interpolates to time 0.5 (half-way across the selection), level 1.0, then immediately jump down to level 0.0, and continue at 0.0 until time 1.0.

This works, however the resulting waveform does not have a sharp one-sample transition (step) at time 0.5, instead it has a linear ramp between 1.0 and 0.0 over ~40 samples. This is not acceptable in this situation.

The conversion here suggests that within Audacity the Nyquist plugin actually runs at a control rate much less than the audio rate, hence the resulting ramp.

I actually wish to create a much more complicated waveform than a square wave, so once this issue is resolved I can continue to construct the full waveform.

My questions are:

  • is it possible to adjust the control rate to match the audio sampling rate, so that I can have sample-accurate control of the pwl function, and
  • how would this be incorporated into a Nyquist Lisp expression that also calls 'pwl' - I'm not very familiar with Lisp at all and don't understand how to execute two statements sequentially. My guess is there's a function to do it...

I would be happy to use Nyquist outside of Audacity if that makes more sense.

Was it helpful?

Solution

The thread I linked to contained the answer I needed. I'll post this here in case it helps someone in the future:

(progv '(*control-srate*) (list *sound-srate*)
  (sum s (pwl
  0 1
  0.5 1
  0.5))
)

This sets the control rate equal to the sound sample rate, thereby allowing the pwl function to draw directly to the target level in a single sample.

Also, it appears that statements in Lisp are made sequential by simply putting the next statement as the last parameter to the previous statement. For example, here the statement to call 'sum' is within a block that is the third parameter to progv. Is that correct and general?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top