signal/osc
src/signal/osc.tur
defn
sine
(sine [freq :float phase :float])
sine-wave oscillator Signal Function.
Parameters
| freq | frequency in Hz | |
| phase | initial phase offset in radians |
Returns
An SF: ignores its input signal and emits sin(2*pi*freq*t + phase).
Example
(sine 440.0 0.0)
defn
square
(square [freq :float dutycycle :float])
square-wave oscillator Signal Function.
Parameters
| freq | frequency in Hz | |
| dutycycle | duty cycle in [0, 1] |
Returns
An SF emitting +1.0 for the on-portion of each cycle, -1.0 otherwise.
Example
(square 220.0 0.5)
defn
sawtooth
(sawtooth [freq :float])
sawtooth-wave oscillator Signal Function.
Parameters
| freq | frequency in Hz |
Returns
An SF emitting a rising ramp in [0.0, 1.0).
Example
(sawtooth 110.0)
defn
triangle
(triangle [freq :float])
triangle-wave oscillator Signal Function.
Parameters
| freq | frequency in Hz |
Returns
An SF that rises from -1.0 to 1.0 over the first half of each cycle and falls back to -1.0 over the second.
Example
(triangle 440.0)
defn
pm-sine
(pm-sine [freq :float])
phase-modulated sine: sin(2*pi*freq*t + m(t)).
Parameters
| freq | carrier frequency in Hz |
Returns
SF Sample Sample: modulator (radians) -> modulated carrier.
Example
((pm-sine 440.0) ((gain 2.0) ((sine 110.0 0.0) (constant 0.0))))
defn
fm-sine
(fm-sine [sample-rate :float freq :float])
frequency-modulated sine: instantaneous frequency freq + m(t).
Parameters
| sample-rate | the rate the result will be sampled at, in Hz | |
| freq | carrier frequency in Hz |
Returns
SF Sample Sample: modulator (Hz) -> modulated carrier.
Example
((fm-sine 48000.0 440.0) ((gain 220.0) ((sine 110.0 0.0) (constant 0.0))))
Internal definitions
__dsp_sin-- compute sine of angle in radians.__dsp_fmod-- compute floating-point modulo.__fm_alloc-- allocate an FM phase cell: [phase, previous freq, started].__fm_step-- advance the FM phase by one sample and return its sine.