Utilities
Misc functions needed in many applications. rescale scales an entire buffer, dBscale converts dB to amplitude, interp4 does 4-point interpolation, raisedcos is a masking waveform, midi2hz/hz2midi convert MIDI note numbers <-> Hz.
Synth.rescale — Functionrescale(maxamp :: Real, samples :: AbstractArray) :: Vector{Float32}Rescales the samples so that the maximum extent fits within the given maxamp (which must be positive). The renderer automatically rescales to avoid clamping.
Synth.dBscale — FunctiondBscale(::Real)
dBscale(::Signal)Converts a dB value to a scaling factor
Synth.interp4 — Functioninterp4(x, x1, x2, x3, x4)Four point interpolation.
xis expected to be in the range[0,1].
This is a cubic function of x such that -
- f(-1) = x1
- f(0) = x2
- f(1) = x3
- f(2) = x4
Synth.raisedcos — Functionraisedcos(x, overlap, scale=1.0f0)A "raised cosine" curve has a rising part that is shaped like cos(x-π/2)+1 and a symmetrically shaped falling part. If the overlap is 0.5, then there is no intervening portion between the rising and falling parts (x is in the range [0,1]). For overlap values less than 0.5, the portion between the rising and falling parts will be clamped to 1.0.
For example, raisedcos(x, 0.25) will give you a curve that will smoothly rise from 0.0 at x=0.0 to 1.0 at x=0.25, stay fixed at 1.0 until x = 0.75 and smoothly decrease to 0.0 at x=1.0.
Synth.midi2hz — Functionmidi2hz(midi::Real)
midi2hz(::Signal)Converts a MIDI note number into a frequency using the equal tempered tuning.
Synth.hz2midi — Functionhz2midi(hz::Real)
hz2midi(::Signal)Converts a frequency in Hz to its MIDI note number in the equal tempered tuning.
Synth.easeinout — Functioneaseinout(t::Float64)For values of t in range [0.0,1.0], this curve rises smoothly from 0.0 and settles smoothly into 1.0. We're not usually interested in its values outside the [0.0,1.0] range.
Synth.curve — Functioncurve(segments :: Vector{Seg}; stop=false)Makes a piece-wise curve given a vector of segment specifications. Each Seg captures the start value, end value, duration of the segment, and the interpolation method to use in between.
If you pass true for stop, it means the curve will be done once all the segments are done. Otherwise the curve will yield the last value forever.
Synth.Seg — TypeSeg(v :: Real, dur :: Float64)A segment that holds the value v for the duration dur.
Seg(v1 :: Real, v2 :: Real, dur :: Float64, interp::Symbol = :linear)Constructs a general segment that takes value from v1 to v2 over dur using the specified interpolator interp.
interp can take on one of [:linear, :exp, :cos, :harmonic]. The default interpolation is :linear.
Synth.circular — Functioncircular(v::AbstractArray{T}) :: Circular{T,AbstractArray{T}}Makes a circular array that handles the modulo calculations.