Audio utility code for working with buffers (double)
(!*! func & args)
Returns a reference (instance of IDeref) that when deref'd, will call the
given function and args. Note that apply!*! is used to call the function
with the arguments, so arguments that are instances of IDeref (i.e. atoms)
will first be derefenced before the function is applied.
Returns an IDeref that when derefed, returns the r-argument. Used for
passing atoms and other references as arguments for events, so that the event
function will receive the atom/ref itself and not its value. (This is due to
events using apply!*!, which derefs any args before applying its function.)
Returns true if alloc is available. Note: may update current alloc num when called.
Returns number of current allocs.
(with-allocator x afn)
Decorates afn with dealloc-on-done afn, which decrements alloc count when afn is done.
(apply!*! func args)
(apply!*! func arg & args)
(apply-stereo func afn & args)
Applies function func individually to each channel of a stereo audio function.
Merges result back into a stereo audio function signal.
Utility function to pass through if it is a function, or
wrap within a const if it is a number
Get the channel count for a buffer
Resets double-array to 0.0. Works with double and double.
(concat-drain! v r)
Initializes a *buffer-size*-sized buffer with the given value,
returns a function that will return that buffer on each call
Creates a single-channel audio buffer with optional default value
Creates a single-channel or multi-channel buffer
Keeps track of current allocations for limiting max-number. Warning: Depends on audio functions
exiting by returning nil to keep track of deallocations. .
(dealloc-on-done atm afn)
(duration-processor dur done-arr afn)
(fill out start f)
Fills double buf with values. Initial value is set to value from double start,
then f called like iterate with the value. Last value is stored back into the start.
Returns buf at end.
(gen-recur & args)
(generator bindings afn-bindings body yield-form)
Creates an audio-function.
* Bindings are for values that will be automatically saved and loaded between calls
* afn-bindings are for setting var name to use when indexing a sample from the buffer generated
by the audio-function
* body should do processing and recur with newly calculated values
* yield-form should be (yield value-to-return)
(get-channel afn index)
Returns a single channel from a multi-channel signal, generated by afn.
Checks if afn returns nil. Note: afn should be wrapped with pink.util/shared
macro if being used by muliple get-channels.
(hold-until delay-time start-value end-value)
Audio function that emits a given start value for duration, then
emits end-value. duration is given in seconds. end-value may be a
double or audio function; if the latter, the audio function will be
called to process once the hold time is complete.
(let-s bindings & body)
Macro that decorates bindings with (shared) to simplify instrument building.
(limit afn min-val max-val)
Clamp values asig betwen min-val and max-val (block-based audio function)
(limit1 v min-val max-val)
Clamps value v betwen min-val and max-val
(map-d out f x)
(map-d out f x y)
(map-d out f x y z)
(map-d out f x y z a)
(map-d out f x y z a b)
(map-d out f x y z a b c)
Maps function f across double buffers and writes output to out buffer
(map-d-impl out f & buffers)
(merge-signals afn1 afn2)
Merge output of two audio functions into a single stereo signal.
(mix-buffers src dest)
Mix src audio buffer into dest audio buffer, taking into account
differences in channel counts
Returns if buffer is multi-channel
(native-operator f a)
(not== a b)
Use for fast comparison of double != double, or long != long.
Based on Zach Tellman's primitive-math not==
(operator f a)
takes in func and list of generators funcs, map operator across the result buffers
Returns function that reads from atom and returns a buffer. Useful for mutable data derived from external source such as MIDI or OSC
Trys to call a function, returns the func's return value or
nil if an exception was caught.
(with-buffer-size buffer-size & bindings)
Run code with given buffer-size. Uses binding to bind *buffer-size* during
initialization-time as well as performance-time. Returns an audio function
that will appropriately fill a buffer of *buffer-size* size with repeated calls
to the code of buffer-size size.
(with-duration dur body)
(with-signals [sigsvec afn] & body)
Destructures signals from multi-channel audio func. Returns an audio function.
Does wrap afn with shared macro so that afn generates only once per buffer time.
(with-signals [[hp lp _ _] (statevar afn 5000 0.8) ]
(some-calc hp lp))