Models

This section describes code snippets available in the Synth.Models module.

Synth.Models.additiveFunction
additive(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.

source
Synth.Models.basicvocoderMethod
basicvocoder(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.

source
Synth.Models.chirpMethod
chirp(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.

source
Synth.Models.chorusMethod
chorus(sig::Signal, rate::Signal, depth::Signal, deltime::Signal, amt::Signal)
  • sig is the signal being chorused
  • rate is the delay oscillator's rate - usually a few Hz
  • depth is the extent of the "chorusing" - also of the order of 1
  • deltime is delay time being picked for the chorus.
  • amt is the "wetness" amount - range 0.0 to 1.0
source
Synth.Models.combFunction
comb(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 freq supported is 1.0. To permit lower values, set the minfreq keyword 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.

source
Synth.Models.drumkitMethod
drumkit(kit::AbstractString, dir::AbstractString) :: DrumKit
drumkit(kit::AbstractString) :: DrumKit

Loads 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

source
Synth.Models.flangerMethod
flanger(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.

  • sig is the signal to be flanged
  • rate is the oscillator rate for the flanging - usually a few Hz
  • depth is the depth of the oscillator, which determines the delay range - also usually of the order of 1
  • del is the delay offset around which the flanging is happening.
  • fb is the amount of feedback (range 0 to 0.98)
  • amt is the "wetness" amount for the effect.
source
Synth.Models.fmFunction
fm(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)
source
Synth.Models.hitFunction
hit(samplefile::AbstractString, vel::Real = 1.0f0) :: DrumHit
hit(drum::DrumHit, vel::Real = 1.0f0) :: DrumHit

Constructs 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

source
Synth.Models.ising2Method
ising2(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.

source
Synth.Models.limiterFunction
limiter(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.

source
Synth.Models.phasedistortionMethod
phasedistortion(sig::SignalWithFanout, del::Signal, depth::Signal, amt::Signal)

Works by using the signal itself to determine the delay time to read.

  • sig is the signal to be phase distorted.
  • del is the delay offset - usually a few 10s of milliseconds.
  • depth is the gain applied to the signal to read the delay line.
  • amt is the "wetness" amount of the effect.
source
Synth.Models.siginvMethod
siginv(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.

source
Synth.Models.snareMethod
snare(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.

source
Synth.Models.toneMethod
tone(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.
source
Synth.Models.DrumHitType

Represents 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].
source