Basic signals

These are commonly used operators that either make signals directly or transform signals in some way. Some key concepts to pay attention to include fanout and feedback.

Synth.konstFunction
konst(v::Real)

Makes a constant valued signal. Useful with functions that accept signals but we only want to use a constant value for it.

source
Synth.clipFunction
clip(dur :: Float64, s :: Signal)

Clips the given signal to the given duration. Usually you'd use a "soft" version of this like a raised cosine or ADSR, but clip could be useful on its own.

source
Synth.sigfunFunction
sigfun(f::Function) :: SigFun

Treats a simple function of time (in seconds) as a signal.

source
Synth.fanoutFunction
fanout(s :: Signal)

A signal, once constructed, can only be used by one "consumer" via structure composition. In some situations, we want a signal to be plugged into multiple consumers (to make a signal flow DAG). For these occasions, make the signal fanout by calling fanout on it and use the aliasble signal everywhere you need it instead. Note that fanout is an idempotent operator (i.e. if s = fanout(sig), then fanout(s) = s).

Constraint

It only makes sense to make a single fanout version of a signal. Repeated evaluation of a signal is avoided by fanout by storing the recently computed value for a given time. So it assumes that time progresses linearly.

Terminology

The word "alias" has two meanings - one in the context of signals where frequency shifting it can cause wrap around effects in the spectrum due to sampling, and in the context of a programming language where a value referenced in multiple data structures is said to be "aliased". It is in the latter sense that we use the word fanout in this case.

source
Synth.feedbackFunction
feedback()

Constructs a feedback node which can be connected to a signal later on after construction. This is intended to be used in feedback loops and introduces a single sample delay to prevent infinite recursion.

You can later on connect a signal to the feedback point by calling connect(::Signal,::Feedback). Just as fanout is used to make DAG signal flow graphs possible, feedback is used to make graphs with loops possible.

source
Synth.connectFunction
connect(s :: Signal, fb :: Feedback)

Connects a signal to a feedback point.

source
Synth.clockFunction
clock(speed :: Real, t_end :: Real = Inf)
clock(speed :: Signal, t_end :: Real = Inf)

Constructs different kinds of clocks. Clocks can be speed controlled. Clocks used for audio signals should be made using the clock constructor and those for scheduling purposes using clock_bpm.

source
Synth.clock_bpmFunction
clock_bpm(tempo_bpm=60.0, t_end :: Real = Inf) :: Signal
clock_bpm(tempo_bpm :: Signal, t_end :: Real = Inf) :: Signal

Constructs different kinds of clocks. Clocks can be speed controlled. Clocks used for audio signals should be made using the clock constructor and those for scheduling purposes using clock_bpm.

source
Base.clampFunction
clamp(sig::Signal, minval::Real, maxval::Real)
clamp(sig::Stereo{L,R}, minval::Real, maxval::Real) where {L <: Signal, R <: Signal}

Clamps the given signal to the give minimum and maximum values. Supports stereo signals and clamps the individual channels.

source
Synth.mixFunction
mix(w1 :: Real, s1 :: Signal, w2 :: Real, s2 :: Signal)

Creates a mixed signal from the two given signals, using the two constant weights. This is the basis of the support for + and - between signals. This and modulate remove some unnecessary combinations and reduce them down to simpler forms where possible.

source
Synth.modulateFunction
modulate(m :: Signal, s :: Signal)

Basically performs multiplication between two signals and is the basis of * operator support. This and mix together implement some expression simplifications that remove unnecessary combinations.

source
Synth.krateFunction
krate(rate_hz :: Float64, s :: Signal)

Short for "control-rate limited" signal. Useful with signals that vary slowly but are computationally expensive to do at audio rates. Same idea as in the original CSound and in many audio synthesis kits.

Produces a signal that will evaluate the given signal at a much lower sampling interval and linearly interpolate between the values to reduce computation. The given signal will effectively be "sampled" at the lower given interval. For example, krate(100.0, sinosc(0.5f0, 10.0f0)) will construct a 10Hz sine that is sampled only 100 times a second and interpolated, instead of having to calculate sines 48000 times a second.

source