Models
This section describes code snippets available in the Synth.Models module.
Synth.Models.additive — Functionadditive(f0,
amps :: AbstractVector{Union{Real,Signal}},
detune_factor :: Signal = konst(1.0f0))Simple additive synthesis. amps is a vector of Float32 or a vector of signals. f0 is a frequency value or a signal that evaluates to the frequency. The function constructs a signal with harmonic series based on f0 as the fundamental frequency and amplitudes determined by the array amps.
Synth.Models.basicvocoder — Methodbasicvocoder(sig, f0, N, fnew; bwfactor = 0.2, bwfloor = 20.0)A simple vocoder for demo purposes. Takes $N$ evenly spaced frequencies $k f_0$ and moves them over to a new set of frequencies $k f_{\text{new}}$ using a heterodyne filter. The bwfactor setting gives the fraction of the inter-frequency bandwidth to filter in. The bandwidth has a floor given by bwfloor in Hz.
Synth.Models.chirp — Methodchirp(amp, startfreq, endfreq, dur;
shapename::Union{Val{:line},Val{:expon}} = Val(:line))A "chirp" is a signal whose frequency varies from a start value to a final value over a period of time. The shape of the change can be controlled using the shapename keyword argument.
Synth.Models.chorus — Methodchorus(sig::Signal, rate::Signal, depth::Signal, deltime::Signal, amt::Signal)sigis the signal being chorusedrateis the delay oscillator's rate - usually a few Hzdepthis the extent of the "chorusing" - also of the order of 1deltimeis delay time being picked for the chorus.amtis the "wetness" amount - range 0.0 to 1.0
Synth.Models.comb — Functioncomb(filter, sig, freq, gain = 0.6)Applies a comb filter to the given signal sig where the freq dictates the length of the delay line and gain gives the gain of the output of the delay line. The given filter is a function that is called with the delay tap signal in case it needs to be filtered in some way. If you omit the filter argument, it is equivalent to providing the identity function. This is a feedback based comb filter.
- The minimum value of
freqsupported is 1.0. To permit lower values, set theminfreqkeyword argument appropriately.
WARNING: Be careful with the gain argument as higher values can result in runaway positive feedback. To help mitigate such runaway effects, a hpf and limiter are in the loop.
Synth.Models.drumkit — Methoddrumkit(kit::AbstractString, dir::AbstractString) :: DrumKit
drumkit(kit::AbstractString) :: DrumKitLoads a "standard" drum kit consisting of a kick, hihat, snare and three toms. kit gives the name of the kit to load and maps to the name of a directory under the given dir. If dir is omitted, then the kits included within Synth.jl are scanned.
Usage:
using Synth.Models: drumkit
k = drumkit("Techno")
play(track([hit(k.kick, 0.5), rest(0.5), hit(k.snare, 0.5)]), 2.0)See also hit
Synth.Models.flanger — Methodflanger(sig::SignalWithFanout, rate::Signal, depth::Signal, del::Signal, fb::Signal, amt::Signal)Simulates two time varying versions of the same signal being mixed together to create the tape deck flanging effect.
sigis the signal to be flangedrateis the oscillator rate for the flanging - usually a few Hzdepthis the depth of the oscillator, which determines the delay range - also usually of the order of 1delis the delay offset around which the flanging is happening.fbis the amount of feedback (range 0 to 0.98)amtis the "wetness" amount for the effect.
Synth.Models.fm — Functionfm(carrier, modulator, index, amp = konst(1.0f0))Basic FM synth module. carrier is the carrier frequency that can itself be a signal. modulator is the modulation frequency and index is the extent of modulation. amp, if given decides the final amplitude. All of them can vary over time.
Example
play(fm(220.0f0, 550.0f0, 100.0f0), 5.0)Synth.Models.hit — Functionhit(samplefile::AbstractString, vel::Real = 1.0f0) :: DrumHit
hit(drum::DrumHit, vel::Real = 1.0f0) :: DrumHitConstructs a DrumHit that can be used in Gen compositions. Drum hits have an inherent duration of 0.0. So if you want to put a gap between two drum hits, you'll need to use rest. hit will load the sample and cache it so the loading doesn't happen at actual play time.
Usage: play(track([hit("kick.wav", 0.5), rest(0.5), hit("snare.wav", 0.5)]), 2.0)
See also Synth.Models.drumkit
Synth.Models.ising2 — Methodising2(f :: Signal, b1 :: Signal, b2 :: Signal, x1 :: Signal, x2 :: Signal, w12 :: Signal)Experimental 2-qubit "Ising" model with controllable weights. Not very interesting at this point, but perhaps with more qubits it might get interesting as the number of frequencies that get mixed in will increase, producing a richer sound.
Synth.Models.limiter — Functionlimiter(sig::SignalWithFanout, level::Real = 1.0f0)A simple limiter based on an approximate peak follower. Should help prevent uncontrolled growth disasters. Smooths the level measurement and uses it to adjust the gain. Has about a 10 millisecond delay.
Todo: Wondering about the difference between this and smoothing the gain instead. Also, the lpf will introduce a small delay that could be problematic. Need to test.
Synth.Models.phasedistortion — Methodphasedistortion(sig::SignalWithFanout, del::Signal, depth::Signal, amt::Signal)Works by using the signal itself to determine the delay time to read.
sigis the signal to be phase distorted.delis the delay offset - usually a few 10s of milliseconds.depthis the gain applied to the signal to read the delay line.amtis the "wetness" amount of the effect.
Synth.Models.siginv — Methodsiginv(s::Signal)Constructs 1/x. This is sometimes needed, for example when building up a limiter. The signal is assumed to be well behaved enough to be inverted like this and no checks are done. So you're on your own there. siginv is adequately polymorphic.
Synth.Models.snare — Methodsnare(dur::Real; rng = MersenneTwister(1234))Very simple snare hit where the dur is the "half life" of the snare's decay. Just amplitude modulates some white noise.
Synth.Models.tone — Methodtone(amp, freq, duration; attack_factor = 2.0, attack_secs = 0.005, decay_secs = 0.05, release_secs = 0.2)A simple sine tone modulator by an ADSR envelope. amp is the amplitude of the sustain portion, freq is the Hz value of the frequency of the tone and duration is the duration in seconds of the sustain portion.
Envelope characteristics
attack_factor- the factor (usually > 1.0) that multiplies the amplitude value to determine the peak of the attack portion of the envelope.attack_secs- the duration of the attack portion. This should be kept short in general.decay_secs- the duration of the portion of the envelope where it decays from the peak attack value down to the sustain level.release_secs- the "half life" of the release portion of the envelope. Over this time, the amplitude of the signal will decay by a factor of 2.
Synth.Models.DrumHit — TypeRepresents a sampled drum sound to be played without a "duration". You can use the [hit])(@ref "Synth.Models.hit") function with it to reuse it with a different velocity.
samplefile- file name of the sample containing the drum hit.vel- the velocity of the hit - in the range [0.0,1.0].
Synth.Models.DrumKit — TypeCollects together a number of "standard" drums belonging to a "kit".