Re: [Audacity-nyquist] (osc pitch [duration table phase])
A free multi-track audio editor and recorder
Brought to you by:
aosiniao
|
From: Roger D. <rb...@cs...> - 2010-11-29 17:01:09
|
This is in nyquist/lib/spectrum.lsp:
(defun raised-cosine ()
(scale 0.5
(sum (const 1)
(lfo (/ 1.0 (get-duration 1)) 1 *sine-table* 270))))
Quick explanation: a raised-cosine is a smooth envelope you get from
1-cos(x) over one period. Note that the "-" flips the negative-going
cosine curve to a positive pulse, and the offset makes it start and
return to zero. Is this what you are trying to do? The duration here is
given by the environment (so in Audacity, the duration would be that of
the selection). Specifically, the duration is the second argument, 1, to
LFO but this is scaled by the duration from the environment. The
frequency is scaled to 1/dur to get one period. For this, (GET-DURATION
1) returns the duration, and this is converted from period to frequency
by division. The waveform is *SINE-TABLE* and the initial phase of the
sine table is 270. (I could have used an initial phase of 90 to get
Cosine, but 270 gives us negative Cosine, which is what we want.)
The output is at the default control sample rate (probably 2205Hz). You
could run this in (control-srate-abs 44100 (raised-cosine)) to get a
different sample rate.
-Roger
On 11/29/10 11:14 AM, Johnny Rosenberg wrote:
> I'm trying to learn some basics of Nyquist for creating Audacity effects.
> Of course there are a lot of things that I don't understand yet, but here
> is what I need to know at the moment:
>
> I want to create a cosine (actually two – one 0-180° and one 180-360°). I
> already figured out that there is no cosine function available, so I guess
> I need to fiddle with a sine wave somehow.
>
> Actually, what I'm trying to achieve, is something like k·(½cos(x)+½),
> where x=0-180° and 180-360° respectively, but once I figure out the cos(x)
> thing I guess the rest shouldn't be too hard to do. Let's just say that I
> want to create a cos wave from 180° to 360° for now.
>
> So I searched a bit among the pre-defined functions in the Nyquist manual
> and found a few that I guess could come in handy in this case:
>
> (sine freq time)
> (osc pitch [duration table phase])
>
> Let's say that the available variables are the following:
> time=5 ms (I guess that the sine function needs the time in seconds, so
> let's say the actual value of time is 0.005). This is the time from 180°
> to 360° of the final cosine wave (270-450° of a sine wave), so I guess we
> should send 2*time to the sine function. The sine wave should of course be
> at least 1¼ period, that is 450°, to make this possible.
>
> freq=100 Hz – that is 1/(2*time)
>
> duration=5 ms, right?
>
> phase=270°
>
> pitch=(hz-to-step 1/time/4) or what?
>
> What else I don't understand is that table thing. How do I handle that?
>
> It would be nice if someone could write some simple code that illustrates
> how to use those functions I mentioned above.
>
>
|