audio_dsp
(sys:load “libs/core/audio_dsp.xtm”)
Introduction
Section titled “Introduction”The audio_dsp package provides core dsp utilities, helper functions and generators for audio.
NOTE: SAMPLE is a type alias for float. However, it also tells you that this function expects a value between 0.0 and 1.0
Useful Math Functions
Section titled “Useful Math Functions”dsp_randn
Section titled “dsp_randn”dsp_randn:[float]*Returns
Section titled “Returns”- SAMPLE : A random number between 0.0 and 1.0
Description
Section titled “Description”This returns a Gaussian distributed random number between 0.0 and 1.0
It uses the Marsaglia algorithm (http://c-faq.com/lib/gaussian.html).
parabolicSineHP
Section titled “parabolicSineHP”parabolicSineHP:[SAMPLE,SAMPLE]*Parameters
Section titled “Parameters”- x:SAMPLE : The x value for a Parabolic Sine function.
Returns
Section titled “Returns”- SAMPLE : The y value for this function.
Description
Section titled “Description”A highly accurate implemntation of the Parabolic Sine function. If accuracy is less important than speed, there is also a low quality implementation of this function available to you.
parabolicSineLP
Section titled “parabolicSineLP”parabolicSineLP:[SAMPLE,SAMPLE]*Parameters
Section titled “Parameters”- x:SAMPLE : The x value for a Parabolic Sine function.
Returns
Section titled “Returns”- SAMPLE : The y value for this function.
Description
Section titled “Description”A low quality, but fast, implemntation of the Parabolic Sine function. If accuracy is more important than speed, there is a highly accurate implementation of this function available to you.
fasttan
Section titled “fasttan”fasttan:[SAMPLE,SAMPLE]*Parameters
Section titled “Parameters”- x:SAMPLE : The x value for a tan function.
Returns
Section titled “Returns”- SAMPLE : The y value for this function.
Description
Section titled “Description”A fast implemntation of tan.
TODO What are the compromises in using this? Is there a range of acceptable values.
fasttanh
Section titled “fasttanh”fasttanh:[SAMPLE,SAMPLE]*Parameters
Section titled “Parameters”- x:SAMPLE : The x value for a tanh function.
Returns
Section titled “Returns”- SAMPLE : The y value for this function.
Description
Section titled “Description”A fast implemntation of tanh.
TODO What are the compromises in using this? Is there a range of acceptable values.
fastsin
Section titled “fastsin”fastsin:[SAMPLE,SAMPLE]*Parameters
Section titled “Parameters”- x:SAMPLE : The x value for a tanh function. X must be within the range -PI <= X <= PI
Returns
Section titled “Returns”- SAMPLE : The y value for this function.
Description
Section titled “Description”A fast implementation of sin. When calling this function make sure that you adjust x so that it lies within the range -PI <= X <= PI
DSP Functions
Section titled “DSP Functions”integrator_c
Section titled “integrator_c”This is currently wrong, so I’m going to describe how it as if the bug was fixed.
integrator_c:[[SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE] : The leaky integrator closure.
Closure Parameters
Section titled “Closure Parameters”- x:SAMPLE : The signal we wish to integrate.
Closure Return Value
Section titled “Closure Return Value”- SAMPLE : The current sum.
Description
Section titled “Description”TODO Cuurrently this has a bug, so fix it.
This function returns a leaky integrator closure.
Example
Section titled “Example”TODO Show how to create it and then used it.
Oscillators (Aliasing)
Section titled “Oscillators (Aliasing)”These oscillators are useful for control level modulation, or situations where you’re not worried about aliasing. Otherwise use the band-limited oscillators described in the next section.
sin_c:[[SAMPLE,SAMPLE,SAMPLE]*,SAMPLE]*TODO I feel this should probably have sin in there somewhere.
Parameters
Section titled “Parameters”- phase:SAMPLE : The initial phase (radians) for the oscillator.
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE]* : The Sin Oscillator closure.
Closure Parameters
Section titled “Closure Parameters”- amp:SAMPLE : Amplitude of the oscillator.
- freq:SAMPLE : Current frequency of the oscillator.
Closure Return Value
Section titled “Closure Return Value”- SAMPLE : The output signal for the oscillator.
Description
Section titled “Description”This function creates an aliasing Sine oscillator.
Example
Section titled “Example”TODO One example should be a cosine.
saw_c:[[SAMPLE,SAMPLE,SAMPLE]*,SAMPLE]*saw_c:[[SAMPLE,SAMPLE,SAMPLE]*,SAMPLE,i1]*Parameters
Section titled “Parameters”- mod:SAMPLE : The initial phase where 0 <= mod <=1
- inverted:i1 optional : If #t then the saw tooth is inverted. The default is #f (i.e. a normal rising saw tooth).
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE]* : The Saw Tooth Oscillator closure.
Closure Parameters
Section titled “Closure Parameters”- amp:SAMPLE : Amplitude of the oscillator.
- freq:SAMPLE : Current frequency of the oscillator.
Closure Return Value
Section titled “Closure Return Value”- SAMPLE : The output signal for the oscillator.
Description
Section titled “Description”This function creates an aliasing Sawtooth oscillator.
Example
Section titled “Example”TODO One example should be an inverted saw tooth.
pulse_c
Section titled “pulse_c”pulse_c:[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*,SAMPLE]*Parameters
Section titled “Parameters”- mod:SAMPLE : The initial phase where 0 <= mod <=1
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The Pulsewave Oscillator closure.
Closure Parameters
Section titled “Closure Parameters”- amp:SAMPLE : Amplitude of the oscillator.
- freq:SAMPLE : Current frequency of the oscillator.
- pw:SAMPLE : The pulse width where 0 <= pw <= 1.0
Closure Return Value
Section titled “Closure Return Value”- SAMPLE : The output signal for the oscillator.
Description
Section titled “Description”This function creates an aliasing pulsewave oscillator.
Example
Section titled “Example”TODO
tri_c:[[SAMPLE,SAMPLE,SAMPLE]*,SAMPLE]*Parameters
Section titled “Parameters”- mod:SAMPLE : The initial phase where 0 <= mod <=1
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE]* : The Triangle Oscillator closure.
Closure Parameters
Section titled “Closure Parameters”- amp:SAMPLE : Amplitude of the oscillator.
- freq:SAMPLE : Current frequency of the oscillator.
Closure Return Value
Section titled “Closure Return Value”- SAMPLE : The output signal for the oscillator.
Description
Section titled “Description”This function creates an aliasing triangle oscillator.
Example
Section titled “Example”TODO
Anti-Aliased Oscillators
Section titled “Anti-Aliased Oscillators”These oscillators are anti-aliased, but consume more resources. Use these for audio signals, but they’re probably overkill for most control signals (unless you’re modulating at audio rate).
blsaw_c
Section titled “blsaw_c”blsaw_c:[[SAMPLE,SAMPLE,SAMPLE]*,SAMPLE]*blsaw_c:[[SAMPLE,SAMPLE,SAMPLE]*,SAMPLE,i1]*blsaw_c:[[SAMPLE,SAMPLE,SAMPLE]*,SAMPLE,i1,i1]*Parameters
Section titled “Parameters”- mod:SAMPLE : The initial phase where 0 <= mod <=1
- inverted:i1 optional : If #t then the saw tooth is inverted. The default is #f (i.e. a normal rising saw tooth).
- high_cpu optional : If set to true this will use a better, but slower, algorithm. The default value is #f.
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE]* : The Saw Tooth Oscillator closure.
Closure Parameters
Section titled “Closure Parameters”- amp:SAMPLE : Amplitude of the oscillator.
- freq:SAMPLE : Current frequency of the oscillator.
Closure Return Value
Section titled “Closure Return Value”- SAMPLE : The output signal for the oscillator.
Description
Section titled “Description”This function creates an anti-aliased Sawtooth oscillator. It is implemented using the BLEP method.
Example
Section titled “Example”TODO One example should be an inverted saw tooth.
blpulse_c
Section titled “blpulse_c”blpulse_c:[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*,SAMPLE,i1]*Parameters
Section titled “Parameters”- mod:SAMPLE : The initial phase where 0 <= mod <=1
- highcpu:i1 optional : If set to true this will use a better, but slower, algorithm. The default value is #t (TODO really?).
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The Pulsewave Oscillator closure.
Closure Parameters
Section titled “Closure Parameters”- amp:SAMPLE : Amplitude of the oscillator.
- freq:SAMPLE : Current frequency of the oscillator.
- pw:SAMPLE : The pulse width where 0 <= pw <= 1.0
Closure Return Value
Section titled “Closure Return Value”- SAMPLE : The output signal for the oscillator.
Description
Section titled “Description”This function creates an anti-aliased pulsewave oscillator.
It uses the sum of saws method.
Example
Section titled “Example”TODO
bltri_c
Section titled “bltri_c”bltri_c:[[SAMPLE,SAMPLE,SAMPLE]*,SAMPLE]*Parameters
Section titled “Parameters”- mod:SAMPLE : The initial phase where 0 <= mod <=1
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE]* : The triangle oscillator closure.
Closure Parameters
Section titled “Closure Parameters”- amp:SAMPLE : Amplitude of the oscillator.
- freq:SAMPLE : Current frequency of the oscillator.
Closure Return Value
Section titled “Closure Return Value”- SAMPLE : The output signal for the oscillator.
Description
Section titled “Description”This function creates an anti-aliased triangle oscillator. TODO - uses which method?
Example
Section titled “Example”TODO
Noise Generators
Section titled “Noise Generators”white_c
Section titled “white_c”white_c:[[SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE]* : White noise closure.
Closure Return Value
Section titled “Closure Return Value”- SAMPLE : The output signal for the oscillator.
Description
Section titled “Description”This function creates a white noise generator. The white noise is gaussian distributed (see dsp_randn).
Example
Section titled “Example”TODO
pink_c
Section titled “pink_c”pink_c:[[SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE]* : Pink noise closure.
Closure Return Value
Section titled “Closure Return Value”- SAMPLE : The output signal for the oscillator.
Description
Section titled “Description”This function creates a pink noise generator. The pink noise is generated using Paul Kellet’s economy method: http://www.firstpr.com.au/dsp/pink-noise/
Example
Section titled “Example”TODO
Interpolators
Section titled “Interpolators”LinTerp
Section titled “LinTerp”LinTerp:[SAMPLE,SAMPLE,SAMPLE,SAMPLE,SAMPLE,SAMPLE]*Parameters
Section titled “Parameters”- x1:SAMPLE : The x value before the interpolated value.
- x2:SAMPLE : The x value after the interpolated value.
- y1:SAMPLE : The y value before the interpolated value.
- y1:SAMPLE : The y value after the interpolated value.
- x:SAMPLE : The x that we want an interpolated value for.
Returns
Section titled “Returns”- SAMPLE : interpolated
yvalue.
Description
Section titled “Description”Given the points (x1,y1) and (x2,y2) this will return the interpolated value y when given an x that lies between x1 and x2.
Example
Section titled “Example”hermite_interp
Section titled “hermite_interp”hermite_interp:[SAMPLE,SAMPLE,SAMPLE,SAMPLE,SAMPLE,SAMPLE]*Parameters
Section titled “Parameters”- fractional:SAMPLE : position within the interval
[x0, x1], in the range 0.0 to 1.0. - y1:SAMPLE : the sample immediately before the interval (i.e.
x[n-1]). - x0:SAMPLE : the sample at the start of the interval; returned when
fractionalis 0.0. - x1:SAMPLE : the sample at the end of the interval; returned when
fractionalis 1.0. - x2:SAMPLE : the sample immediately after the interval (i.e.
x[n+2]).
Returns
Section titled “Returns”- SAMPLE : interpolated
yvalue.
Description
Section titled “Description”Four-point cubic Hermite interpolation. Interpolates between x0 and x1,
using the surrounding samples y1 and x2 to shape the curve.
Example
Section titled “Example”($ (hermite_interp 0.5 0.0 1.0 2.0 3.0)) ;; returns 1.5
Conversion Utilities
Section titled “Conversion Utilities”midi2frq
Section titled “midi2frq”midi2frq:[float,float]*Parameters
Section titled “Parameters”- float : A midi note number
Returns
Section titled “Returns”- float : A frequency in herz
Description
Section titled “Description”Converts a midi value to a frequency value. E.g. given 60 it will return the value 261.6 Hz
Example
Section titled “Example”> ($ (midi2frq 60.0))261.625549frq2midi
Section titled “frq2midi”frq2midi:[float,float]*Parameters
Section titled “Parameters”- float : A frequency in herz
Returns
Section titled “Returns”- float : A midi note number
Description
Section titled “Description”Converts a frequency value to a midi value. E.g. given 261.6 it will return the value 60.
Example
Section titled “Example”> ($ (midi2frq 261.625549))60bpm2hz
Section titled “bpm2hz”bpm2hz:[float,float]*Parameters
Section titled “Parameters”- float : Beats per Minute
Returns
Section titled “Returns”- float : A frequency in herz
Description
Section titled “Description”Converts a value in beats per minute to a frequency in herz.
Example
Section titled “Example”> ($ (bpm2hz 60))1.000hz2bpm
Section titled “hz2bpm”hz2bpm:[float,float]*Parameters
Section titled “Parameters”- float : A frequency in herz
Returns
Section titled “Returns”- float : Beats per minute
Description
Section titled “Description”Converts a value in herz to beats per minute.
Example
Section titled “Example”> ($ (hz2bpm 1.000))60.000amp2db
Section titled “amp2db”amp2db:[float,float]*Parameters
Section titled “Parameters”- float : Volume amplitude Amps where 0.0 < Amps <= 1.0
Returns
Section titled “Returns”- float : Volume in decibels where -inf < db <= 0.0
Description
Section titled “Description”A utility function that converts between Extempore’s model of volume amplitude and decibels.
Amplitude in Extempore is a linear scale between 0.0 and 1.0, where 0.0 is silence and 1.0 is the maximum value.
Example
Section titled “Example”> ($ (amp2db 0.5))-6.0206db2amp
Section titled “db2amp”db2amp:[float,float]*Parameters
Section titled “Parameters”- float : Volume in decibels where -inf < db <= 0.0
Returns
Section titled “Returns”- float : Volume amplitude Amps where 0.0 < Amps <= 1.0
Description
Section titled “Description”A utility function that converts from decibels (where 0.0 is the maximum possible volume) to Extempore’s model of volume amplitude and decibels.
Amplitude in Extempore is a linear scale between 0.0 and 1.0, where 0.0 is silence and 1.0 is the maximum value.
Example
Section titled “Example”> ($ (db2amp -6.0206))0.5Envelope Followers
Section titled “Envelope Followers”These are closures that are useful for monitoring and manipulating volume.
rms_c:[[SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE]* : The closure we will use for our DSP chain.
Closure Parameters
Section titled “Closure Parameters”- SAMPLE : current sound sample from input source.
Closure Environment
Section titled “Closure Environment”- db:SAMPLE : The RMS value for the current FRAME. Note that this is in decibels.
Returns
Section titled “Returns”- SAMPLE : The input value (e.g. the signal is passed straight through)
Description
Section titled “Description”This function creates a closure that takes a signal and calculates the RMS value for it.
The RMS value is calculated every frames (e.g. the global variable FRAMES which
defines extempore’s block size) and placed in the closure’s environment as the
value db.
The signal is passed through the closure unchanged. This allows you to easily place it in a dsp chain without worrying about the signal.
DB is (RMS is +3db - i.e. dBFS with sine 1.0 at 0.0db) - need a better explaination TODO.
Example
Section titled “Example”TODO
Envelopes
Section titled “Envelopes”gainf::[SAMPLE,i64,i64,SAMPLE]*Parameters
Section titled “Parameters”- time:i64 : elapsed time since the envelope curve was triggered. The curve starts at time 0.
- width:i64 : the duration of the envelope curve in TODO.
- power:float : This controls the curve of the envelope curve. The envelope curve can be flat, linear or have a quadratic curve.
Returns
Section titled “Returns”- SAMPLE : The current value of the generated envelope curve. TODO RANGE?
Description
Section titled “Description”Generates an envelope curve. The envelope curve has duration width, and given
a time value between 0 and width TODO will return a value from within the
curve.
TODO The value will always be between 0 and 1.0
The power parameter determines the shape of the curve. Positive values will
give you a curve that goes up, negative values a curve that goes down.
Power Values
Section titled “Power Values”If you want an envelope that descends, rather than ascends, use a negative power value.
- 0.0 -> 1.0 : The output will always be
power. E.g., if you setpowerto 0.5, you will always get an output of 0.5. - 1.01 -> 2.0 : This will give you an ascending line from 0 to the mantissa
TODO check. So 1.5 will give you an ascending line from
0.0to0.5over timewidth. - 2.01 and higher : These will give you ascending curves of increasing steepness. If the value is negative this will give you a descending curve that is the mirror of the ascending curve.
Example
Section titled “Example”TODO. Needs several probably.
Multi Channel (E.G. Stero)
Section titled “Multi Channel (E.G. Stero)”panner
Section titled “panner”panner::[SAMPLE,i64,SAMPLE]*Parameters
Section titled “Parameters”- channel:i64 : The channel that you want the correct value for.
- pan:SAMPLE : The stereo pan, where 0.0 is on the left, 0.5 is the middle and 1.0 is the right.
Returns
Section titled “Returns”- SAMPLE : The properly panned value for this channel TODO how does it calculate this?
;; given current channel ;; and pan value [0.0-1.0] ;; returns value betwee n [0.0-1.0] ;; uses CHANNELS
Description
Section titled “Description”Given a sample input and a desired pan level this function will calculate
the correct output for the desired channel.
TODO How is this calculated?
Example
Section titled “Example”TODO. Needs several probably.
Signal Functions
Section titled “Signal Functions”hann:[SAMPLE,i64,i64,i64]*Parameters
Section titled “Parameters”- time:i64 : elapsed time since this function started (0 is the start time)
- width:i64 : Width of the hann window in TODO time periods
- repeat:i64 : repeat period. 1 is immediately, 2 is after a single cycle, 5 is after 4 cycles. TODO 0 should be never repeat.
Returns
Section titled “Returns”- SAMPLE - A value between 0.0 and 1.0, where 1.0 is the peak of the hann windows.
Description
Section titled “Description”This generates a repeating hann window signal. Use repeat to define the
repititon pattern. 0 for non-repeating, 1 for continuous, 2 for every
other cycle, etc.
Examples
Section titled “Examples”TODO
Code Update
Section titled “Code Update”Could remove entirely hann by simply setting the the repeat to 0.0
impulse
Section titled “impulse”impulse::[SAMPLE,i64,i64]*Parameters
Section titled “Parameters”- time:i64 : time in samples starting from 0.
- apex:i64 : time in samples after 0 when the impulse should be fired
(TODO Note it can’t be 0 - which is odd). Until
apexis reached the output will be 0.
Returns
Section titled “Returns”- SAMPLE - A value between 0.0 and 1.0 for the impulse value
Description
Section titled “Description”This generates an impulse of 1.0 that begins at time period apex and outputs 1.0 for a single sample period. After it is activated it will exponentially decay to 0.
Examples
Section titled “Examples”TODO
DSP Utility
Section titled “DSP Utility”poly_blep
Section titled “poly_blep”poly_blep:[float,float,float,i1]*Parameters
Section titled “Parameters”- pos:SAMPLE : TODO
- inc:SAMPLE : TODO
- height:SAMPLE : TODO
- rising_edge:i1 : TODO
Returns
Section titled “Returns”- SAMPLE : TODO
Description
Section titled “Description”A polynomial bandlimited step function. TODO
blep_n
Section titled “blep_n”blep_n:[float,float*,float,float,float,float,i1,float,i1]*Parameters
Section titled “Parameters”- table:SAMPLE* : TODO
- tablenlen:SAMPLE : length of table.
- mod:SAMPLE : TODO
- inc:SAMPLE : TODO
- height:SAMPLE : TODO
- rising:i1 : TODO
- num_points:SAMPLE : TODO
- interp:i1 : TODO
Returns
Section titled “Returns”- SAMPLE : TODO
Description
Section titled “Description”TODO
Miscellaneous
Section titled “Miscellaneous”print_audio_state
Section titled “print_audio_state”print_audio_state:[void]*Description
Section titled “Description”Prints the status of the soundcard to the command line.
Filters
Section titled “Filters”Many of the functions that create a filter closure expect an enumeration value. These are defined below:
- LPF1 : Low Pass Filter, 1 pole.
- LPF2 : Low Pass Filter, 2 poles.
- LPF4 : Low Pass Filter, 4 poles.
- HPF1 : High Pass Filter, 1 pole.
- HPF2 : High Pass Filter, 2 poles.
- HPF4 : High Pass Filter, 4 poles.
- BPF1 : Band Pass Filter, 1 pole.
- BPF2 : Band Pass Filter, 2 poles.
- BPF4 : Band Pass Filter, 4 poles.
lpf_1p_c
Section titled “lpf_1p_c”lpf_1p_c::[[SAMPLE,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE]* : The low pass filter closure.
Closure Parameters
Section titled “Closure Parameters”- x:SAMPLE : input sample that we are filtering
- g:SAMPLE : positions the pole on the unit axis (0.0 -> 1.0)
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”A simple 1 pole filter. g moves the pole along the axis. TODO - check that you’re remembering this correctly.
va_onepole
Section titled “va_onepole”va_onepole::[[SAMPLE,SAMPLE,SAMPLE]*,i32]*Parameters
Section titled “Parameters”- type:i32 : The type of filter that is being created. You choices are LPF1 (for a low pass filter) and HPF1 (for a high pass filter).
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE]* : The filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering
- freq:SAMPLE : filter cutoff frequency.
- q:SAMPLE : filter ‘q’ value
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”A virtual analog modelled 1 pole filter. This can either be a low pass filter, or a high pass filter.
Based upon Will Pirkle’s implementation.
moog_ladder
Section titled “moog_ladder”moog_ladder::[[SAMPLE,SAMPLE,SAMPLE]*,i32]*Parameters
Section titled “Parameters”- type:i32 : The type of filter that is being created. You choices are LPF2 and LPF4 (for a low pass filter), BPF2 and BPF4 (for a band pass filter) and HPF2 and HPF4 (for a high pass filter).
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE]* : The filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering
- freq:SAMPLE : filter cutoff frequency.
- q:SAMPLE : filter ‘q’ value
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”The legendary Moog filter. This can serve as a low pass, band pass and high pass filter. [TODO would be good to reference which one of the many designs this is, and it’s performance generally].
svf_c::[[|6,float|*,float,float,float,|6,float|*]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,|6,float|*]* : The filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- cutoff:SAMPLE : filter cutoff frequency.
- res:SAMPLE : Filter resonance (q).
- outarray:|6,float|* : Memory location to store the output.
Closure Returns
Section titled “Closure Returns”- |6,float|* : The output from the different components of this filter: |low pass, band pass, high pass, notch filter, peak filter, allpass filter|
Description
Section titled “Description”An analog modelled state variable filter. State variable filters produce multiple filter responses from the same circuitry.
This design follows: http://www.cytomic.com/files/dsp/SvfLinearTrapOptimised2.pdf. The ‘using v1 to compute v2’ version.
lpf_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- cutoff:SAMPLE : filter cutoff frequency.
- res:SAMPLE : Filter resonance (q).
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO - more info. Essentially this is a state variable filter version of a low pass filter. Not sure if this is analog modelled, or not.
lpf_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- cutoff:SAMPLE : filter cutoff frequency.
- res:SAMPLE : Filter resonance (q).
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO - more info. Essentially this is a state variable filter version of a low pass filter. Not sure if this is analog modelled, or not.
lpf2_c
Section titled “lpf2_c”lpf2_c:[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- cutoff:SAMPLE : filter cutoff frequency.
- res:SAMPLE : Filter resonance (q).
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO - more info. Essentially this is a state variable filter version of a low pass filter. Not sure if this is analog modelled, or not.
This is less efficient that lpf_c, but this one could be run on two processors. Currently this is probably more interesting rather than useful.
hpf_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- cutoff:SAMPLE : filter cutoff frequency.
- res:SAMPLE : Filter resonance (q).
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO - more info. Essentially this is a state variable filter version of a high pass filter. Not sure if this is analog modelled, or not.
hpf_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- cutoff:SAMPLE : filter cutoff frequency.
- res:SAMPLE : Filter resonance (q).
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO - more info. Essentially this is a state variable filter version of a high pass filter. Not sure if this is analog modelled, or not.
apf_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- cutoff:SAMPLE : filter cutoff frequency.
- res:SAMPLE : Filter resonance (q).
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO - more info. Essentially this is a state variable filter version of an all pass filter. Not sure if this is analog modelled, or not.
notch_c
Section titled “notch_c”notch_c:[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- cutoff:SAMPLE : filter cutoff frequency.
- res:SAMPLE : Filter resonance (q).
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO - more info. Essentially this is a state variable filter version of a notch filter. Not sure if this is analog modelled, or not.
peak_c
Section titled “peak_c”peak_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- cutoff:SAMPLE : filter cutoff frequency.
- res:SAMPLE : Filter resonance (q).
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO - more info. Essentially this is a state variable filter version of a peak filter. Not sure if this is analog modelled, or not.
bell_c
Section titled “bell_c”bell_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- cutoff:SAMPLE : filter cutoff frequency.
- q:SAMPLE : Filter resonance (q).
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO - more info. Essentially this is a state variable filter version of a bell filter. Not sure if this is analog modelled, or not.
TODO: From the code. Q is usually around 0.5 gain is either a boost up to +5.0db or a reduction down to -24.0db. Little cryptic…
lshelf_c
Section titled “lshelf_c”lshelf_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- cutoff:SAMPLE : filter cutoff frequency.
- q:SAMPLE : Filter resonance (q).
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO - more info. Essentially this is a state variable filter version of a low shelf filter. Not sure if this is analog modelled, or not.
TODO: From the code. Q is usually around 0.5 gain is either a boost up to +5.0db or a reduction down to -24.0db. Little cryptic…
hshelf_c
Section titled “hshelf_c”hshelf_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- cutoff:SAMPLE : filter cutoff frequency.
- q:SAMPLE : Filter resonance (q).
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO - more info. Essentially this is a state variable filter version of a high shelf filter. Not sure if this is analog modelled, or not.
TODO: From the code. Q is usually around 0.5 gain is either a boost up to +5.0db or a reduction down to -24.0db. Little cryptic…
skf_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- cutoff:SAMPLE : filter cutoff frequency.
- q:SAMPLE : Filter resonance (q).
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”A low pass filter of the Sallen Key type.
TODO - more info probably.
Implemented using Andy Simper’s Sallen Key LPF http://cytomic.com/files/dsp/SkfLinearTrapOptimised2.pdf
delay_apf_c
Section titled “delay_apf_c”delay_apf_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*,i64]*Parameters
Section titled “Parameters”- delay:i64 : Delay time for this delay line.
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE]* : The all pass filter closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- apf_gain:SAMPLE : TODO What this actually does :)
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”All pass filter implemented using a delay.
Delays
Section titled “Delays”tap delays will also end up here.
Comb Filters
Section titled “Comb Filters”delay_c
Section titled “delay_c”delay_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*,i64]*Parameters
Section titled “Parameters”- delay:i64 : Delay time for this delay line.
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The delay closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- wet:SAMPLE : how much of the input signal should be mixed with the delay.
0.0 will give you 100% of
in1.0 will give you 100% of the delay (TODO Actually it doesn’t do this, but shouldn’t it?) - feedback:SAMPLE : Feedback. In theory this should be how much of the out signal gets mixed into the delay with in. But that doesn’t seem to be what’s going on.
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”Non interpolated delay line. TODO: Work out how this actually works and check that it’s correct (it probably is). It’s possible that this is actually a comb filter, in which case I think the name should be comb_c, and just rely upon it having a non-fractional delay maybe? It is confusing.
comb_c
Section titled “comb_c”comb_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*,i64]*Parameters
Section titled “Parameters”- delay:i64 : Delay time for this delay line.
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The delay closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- delay:SAMPLE : TODO Dig out the DSP books…
- mix:SAMPLE : how much of the input signal should be mixed with the delay.
0.0 will give you 100% of
in1.0 will give you 100% of the delay (TODO Actually it doesn’t do this, but shouldn’t it?) - fb:SAMPLE : Feedback. In theory this should be how much of the out signal gets mixed into the delay with in. But that doesn’t seem to be what’s going on.
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”Interpolated comb filter. You can use fractional delay amounts and it will do the necessary math to give you the intended result.
comb_lpf_c
Section titled “comb_lpf_c”comb_lpf_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*,i64]*Parameters
Section titled “Parameters”- delay:i64 : Delay time for this delay line.
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The delay closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- delay:SAMPLE : TODO Dig out the DSP books…
- mix:SAMPLE : how much of the input signal should be mixed with the delay.
0.0 will give you 100% of
in1.0 will give you 100% of the delay (TODO Actually it doesn’t do this, but shouldn’t it?) - fb:SAMPLE : Feedback. In theory this should be how much of the out signal gets mixed into the delay with in. But that doesn’t seem to be what’s going on.
- cof:SAMPLE : cutoff frequency for the low pass.
- res:SAMPLE : resonance amount (TODO Q?)
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO: Interpolated comb filter with a low pass filter. I’m not sure why this is necessary, other than as a building block for other ugens. Feels redundant.
comb_lpf_1p_c
Section titled “comb_lpf_1p_c”comb_lpf_1p_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*,i64]*Parameters
Section titled “Parameters”- delay:i64 : Delay time for this delay line.
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The delay closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- delay:SAMPLE : TODO Dig out the DSP books…
- combg:SAMPLE : TODO dunno
- lpfg:SAMPLE : low pass filter gain (see lpf I guess).
- cof:SAMPLE : cutoff frequency for the low pass.
- res:SAMPLE : resonance amount (TODO Q?)
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO: Interpolated comb filter with a simple 1 pole low pass filter. I’m not sure why this is necessary, other than as a building block for other ugens. Feels redundant.
comb_apf_c
Section titled “comb_apf_c”comb_apf_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*,i64]*Parameters
Section titled “Parameters”- delay:i64 : Delay time for this delay line.
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The ugen closure.
Closure Parameters
Section titled “Closure Parameters”- x:SAMPLE : input sample that we are filtering.
- delay:SAMPLE : TODO Dig out the DSP books…
- apf:gain : The all pass filter gain.
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO: Interpolated comb filter with a simple all pass filter filter. I’m not sure why this is necessary, other than as a building block for other ugens. Feels redundant.
delay_apf_c
Section titled “delay_apf_c”delay_apf_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*,i64]*Parameters
Section titled “Parameters”- delay:i64 : Delay time for this delay line.
Returns
Section titled “Returns”- [SAMPLE,SAMPLE,SAMPLE]* : The delay closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : input sample that we are filtering.
- gain:SAMPLE : TODO Dig out the DSP books and work out what gain is doing here.
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO Assume this is an all pass filter that uses delay. Need to check.
Reverb
Section titled “Reverb”Add the stereo reverb because that’s a thing.
Effects
Section titled “Effects”Flanger
Section titled “Flanger”flanger_c
Section titled “flanger_c”flanger_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE,SAMPLE,SAMPLE,SAMPLE,SAMPLE]*,i64]*Parameters
Section titled “Parameters”- delay:i64 : Max delay time for this flanger.
Returns
Section titled “Returns”- flanger_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE,SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The flanger closure.
Closure Parameters
Section titled “Closure Parameters”- x:SAMPLE : The thing we’re TODO I guess the channel? Seems a little inflexible
- in:SAMPLE : input? TODO
- out:SAMPLE : output? TODO
- delay:SAMPLE : delay in milliseconds
- range:SAMPLE : range in miliseconds
- feedback:SAMPLE : 0..1 (TODO what do this do?)
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO Describe what a flanger does. Probably.
Chorus
Section titled “Chorus”chorus_c
Section titled “chorus_c”chorus_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE,SAMPLE]*,SAMPLE]*Parameters
Section titled “Parameters”- phase:SAMPLE : TODO Definition
Returns
Section titled “Returns”- [[SAMPLE,SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The flanger closure.
Closure Parameters
Section titled “Closure Parameters”- x:SAMPLE : The thing we’re TODO I guess the channel? Seems a little inflexible
- in:SAMPLE : input? TODO
- out:SAMPLE : output? TODO
- feedback:SAMPLE : 0..1 (TODO what do this do?) feedbacks the output into the next signal almost certainly.
Closure Returns
Section titled “Closure Returns”- SAMPLE : filtered output sample.
Description
Section titled “Description”TODO Describe what a chorus does. Probably.
Delays
Section titled “Delays”tap_delay_c
Section titled “tap_delay_c”tap_delay_c::[[float,float]*,i64,i64]*Parameters
Section titled “Parameters”- max_delay:i64 : Max length of this tap delay (e.g. 64)
- num_taps:SAMPLE :
Returns
Section titled “Returns”- [[SAMPLE,SAMPLE,SAMPLE,SAMPLE,SAMPLE]* : The flanger closure.
Closure Parameters
Section titled “Closure Parameters”- x:SAMPLE : The input sample
Closure Returns
Section titled “Closure Returns”- SAMPLE : processed output
Description
Section titled “Description”TODO Describe what a tap delay does. I feel this could be done more flexibly just by creating a general purpose delay line that can easily be accessed. Also needs some more controls (decay, etc).
Reverb
Section titled “Reverb”reverb_c
Section titled “reverb_c”reverb_c::[[i64,SAMPLE,SAMPLE,float,float,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [[i64,SAMPLE,SAMPLE,float,float,SAMPLE,SAMPLE]* : The flanger closure.
Closure Parameters
Section titled “Closure Parameters”- chan:i64 : The channel of the input (TODO need a better way of handling)
- x:SAMPLE : The input sample
- size:SAMPLE : roomsize from 0.0 to 1.0
- predelay:float : milliseconds. Can go as high as 2 seconds, but 40 milliseconds is a good starting point.
- absorb:SAMPLE : Amount of high frequency damping (simulating wall absorbtion). 0.0 to 1.0 6: mix:SAMPLE : 0.0 dry to 1.0 wet
Closure Returns
Section titled “Closure Returns”- SAMPLE : processed output
Description
Section titled “Description”A reverb. TODO describe topology, type, etc. Need more reverb.
reverb_st_c
Section titled “reverb_st_c”reverb_st_c::[[i64,SAMPLE,SAMPLE,float,float,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [[i64,SAMPLE,SAMPLE,float,float,SAMPLE,SAMPLE]* : The flanger closure.
Closure Parameters
Section titled “Closure Parameters”- chan:i64 : The channel of the input (TODO need a better way of handling)
- x:SAMPLE : The input sample
- size:SAMPLE : roomsize from 0.0 to 1.0
- predelay:float : milliseconds. Can go as high as 2 seconds, but 40 milliseconds is a good starting point.
- absorb:SAMPLE : Amount of high frequency damping (simulating wall absorbtion). 0.0 to 1.0
- mix:SAMPLE : 0.0 dry to 1.0 wet
Closure Returns
Section titled “Closure Returns”- SAMPLE : processed output
Description
Section titled “Description”A reverb for stereo signal. A kludge apparently. TODO find out why.
Bit Crusher
Section titled “Bit Crusher”crusher_c
Section titled “crusher_c”crusher_c::[[SAMPLE,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [[SAMPLE,SAMPLE,SAMPLE]* : The bit crusher closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : The input sample
- bits:SAMPLE : bit size after processing (TODO why is this a float?)
Closure Returns
Section titled “Closure Returns”- SAMPLE : processed output
Description
Section titled “Description”A ‘dodgy’ bitcrusher (TODO why dodgy)
Sample and Hold
Section titled “Sample and Hold”hold3_c
Section titled “hold3_c”hold3_c::[[SAMPLE,SAMPLE,SAMPLE]*]*Returns
Section titled “Returns”- [[SAMPLE,SAMPLE,SAMPLE]* : The sample and hold closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : The input sample
- h:SAMPLE : if h > 0.0 then continue to play the last held sample
Closure Returns
Section titled “Closure Returns”- SAMPLE : processed output
Description
Section titled “Description”Sample and hold. TODO description.
Amp Distortion
Section titled “Amp Distortion”distort_c
Section titled “distort_c”distort_c::[[SAMPLE]*]*Parameters
Section titled “Parameters”- gain:SAMPLE : How much gain to apply to the input (TODO think this should be a closure parameter)
Returns
Section titled “Returns”- [[SAMPLE]* : The distortion closure.
Closure Parameters
Section titled “Closure Parameters”- in:SAMPLE : The input sample
Closure Properties
Section titled “Closure Properties”- gain:SAMPLE : How much gain to apply to the input
- lim:SAMPLE : the level at which this should start to distort. (0.0-1.0)
Closure Returns
Section titled “Closure Returns”- SAMPLE : processed output
Description
Section titled “Description”A very basic distortion ugen.
Saturation
Section titled “Saturation”Envelopes etc
Section titled “Envelopes etc”fade_c
Section titled “fade_c”fade_c::[[SAMPLE,SAMPLE,SAMPLE,SAMPLE]*]*Description
Section titled “Description”TODO: This function doesn’t make sense to me. I feel there is a better way of achieving a linen. Shouldn’t it have a gate? and why not pass in the time, rather than it having it’s own internal sense of that?
Ring Modulation
Section titled “Ring Modulation”Synths
Section titled “Synths”Granulator
Section titled “Granulator”This feels a little too complex for this file.
Mixing
Section titled “Mixing”panner_c
Section titled “panner_c”TODO maybe come back to this, but seems confusing as currently presented. need channels independent of sound for these to work well.
Why are there mix closures and functions?