"""The mockup's sound recipes (its `SFX` table), one function per recipe. Each recipe takes a `Mix` and adds its sounds starting at time 0. Where the mockup picks something at random, a fixed choice is used here so every run gives the same audio. """ from synth import arpeggio, noise, tone def harp(mix): arpeggio(mix, 0, [392, 494, 587, 740, 880], 0.06, 0.9, wave_type="triangle", gain=0.1) def swish(mix): noise(mix, 0, 0.28, freq=1200, freq_end=4000, quality=0.8, gain=0.12, attack=0.08) def dreamy(mix): chord = [523, 659, 784, 988] arpeggio(mix, 0, chord, 0.1, 1.5, gain=0.07, attack=0.08) arpeggio(mix, 0, chord, 0.1, 1.5, gain=0.05, attack=0.08, detune_cents=14) def tapestop(mix): tone(mix, 0, 440, 0.55, wave_type="sawtooth", freq_end=90, lowpass=1400, gain=0.06) def synth(mix): arpeggio(mix, 0, [220, 262, 330, 440, 523, 659], 0.055, 0.22, wave_type="sawtooth", lowpass=2200, gain=0.07) def cassette(mix): noise(mix, 0, 0.05, filter_type="lowpass", freq=700, gain=0.35) tone(mix, 0.03, 90, 0.09, wave_type="square", gain=0.07, lowpass=500) def windchime(mix): # The mockup shuffles these five notes each time; this is one fixed shuffle. shuffled = [523, 392, 659, 440, 587] arpeggio(mix, 0, shuffled, 0.12, 0.7, wave_type="triangle", gain=0.11) def rustle(mix): noise(mix, 0, 0.22, filter_type="highpass", freq=2500, gain=0.12, attack=0.04) noise(mix, 0.12, 0.18, filter_type="highpass", freq=3500, gain=0.08, attack=0.03) def clack(mix): for i, delay in enumerate([0, 0.13, 0.22]): noise(mix, delay, 0.05, freq=1100 - i * 120, quality=6, gain=0.6) tone(mix, delay, 170, 0.1, wave_type="triangle", gain=0.12) def creak(mix): tone(mix, 0, 70, 0.4, wave_type="sawtooth", freq_end=96, lowpass=420, gain=0.08, attack=0.05) noise(mix, 0, 0.35, freq=350, quality=4, gain=0.1, attack=0.06) def drops(mix): for i, delay in enumerate([0, 0.16, 0.34]): tone(mix, delay, 800 + i * 180, 0.14, freq_end=1500 + i * 200, glide=0.07, gain=0.13) def leafswish(mix): noise(mix, 0, 0.3, freq=700, freq_end=3000, quality=1.2, gain=0.13, attack=0.1) def airchime(mix): noise(mix, 0, 0.6, filter_type="lowpass", freq=500, freq_end=1500, gain=0.06, attack=0.25) arpeggio(mix, 0.1, [1047, 1319, 1568, 2093], 0.07, 1.1, gain=0.06) def whoosh(mix): noise(mix, 0, 0.45, freq=350, freq_end=1600, quality=0.9, gain=0.18, attack=0.2) def bubbles(mix): for i, delay in enumerate([0, 0.07, 0.15, 0.24]): tone(mix, delay, 280 + i * 60, 0.09, freq_end=900 + i * 150, glide=0.08, gain=0.1) tone(mix, 0.32, 1568, 0.7, gain=0.06) tone(mix, 0.36, 2093, 0.7, gain=0.05) def tink(mix): tone(mix, 0, 2637, 0.5, gain=0.07) tone(mix, 0, 3951, 0.3, gain=0.04) def bell(mix): # Partials of a 98 Hz bell: (frequency multiple, gain, duration). partials = [(1, 0.13, 2.6), (2, 0.06, 1.6), (2.4, 0.05, 1.4), (3, 0.04, 1), (4.2, 0.03, 0.8)] for multiple, gain, duration in partials: tone(mix, 0, 98 * multiple, duration, gain=gain, attack=0.004) def scrape(mix): noise(mix, 0, 0.6, filter_type="lowpass", freq=450, gain=0.2, attack=0.15) def beeps(mix): for freq, delay in [(880, 0), (1320, 0.1), (1760, 0.2)]: tone(mix, delay, freq, 0.07, wave_type="square", gain=0.045) def relay(mix): noise(mix, 0, 0.02, filter_type="highpass", freq=4000, gain=0.4) noise(mix, 0.06, 0.02, filter_type="highpass", freq=3500, gain=0.35) def typewriter(mix): # Six key strikes with random gaps (seeded, so fixed), then the carriage bell. delay = 0.0 for _ in range(6): noise(mix, delay, 0.03, freq=2400, quality=3, gain=0.5) delay += 0.06 + mix.random.random() * 0.06 tone(mix, delay + 0.08, 2093, 0.7, gain=0.07) def slap(mix): noise(mix, 0, 0.09, filter_type="lowpass", freq=1600, gain=0.45) def drone(mix): tone(mix, 0, 55, 2.2, wave_type="sawtooth", lowpass=380, gain=0.09, attack=0.5) tone(mix, 0, 55.9, 2.2, wave_type="sawtooth", lowpass=380, gain=0.08, attack=0.6) tone(mix, 0.3, 82.4, 1.9, wave_type="sawtooth", lowpass=300, gain=0.06, attack=0.5) def wetpage(mix): noise(mix, 0, 0.32, freq=900, freq_end=400, quality=2, gain=0.2, attack=0.05) def slide(mix): tone(mix, 0, 300, 0.4, freq_end=1400, glide=0.35, gain=0.09) noise(mix, 0.38, 0.1, filter_type="lowpass", freq=1200, gain=0.4) def whack(mix): noise(mix, 0, 0.1, filter_type="lowpass", freq=900, gain=0.55) tone(mix, 0, 140, 0.16, freq_end=55, gain=0.18) def ratchet(mix): for i in range(8): noise(mix, i * 0.045, 0.016, freq=3200, quality=8, gain=0.7) tone(mix, 0.42, 1760, 1, gain=0.07) def hiss(mix): noise(mix, 0, 0.55, filter_type="highpass", freq=5000, gain=0.12, attack=0.05) def glitch(mix): # Eight square-wave stabs at random pitches (seeded, so fixed), then a hiss. for i in range(8): pitch = 200 + mix.random.random() * 1800 tone(mix, i * 0.035, pitch, 0.03, wave_type="square", gain=0.04) noise(mix, 0.1, 0.05, filter_type="highpass", freq=3000, gain=0.2) def blip(mix): tone(mix, 0, 1200, 0.07, wave_type="square", freq_end=2400, glide=0.05, gain=0.05) def sonar(mix): tone(mix, 0, 1180, 1.4, gain=0.1) tone(mix, 0.45, 1180, 1, gain=0.035) def hud(mix): tone(mix, 0, 1800, 0.05, gain=0.06) tone(mix, 0.06, 2400, 0.05, gain=0.06) def quill(mix): for delay in [0, 0.14, 0.26]: noise(mix, delay, 0.1, filter_type="highpass", freq=2200, freq_end=4200, gain=0.12, attack=0.02) def unfold(mix): noise(mix, 0, 0.2, filter_type="lowpass", freq=1300, gain=0.18, attack=0.03) noise(mix, 0.15, 0.25, filter_type="lowpass", freq=900, gain=0.14, attack=0.04) def chip(mix): arpeggio(mix, 0, [523, 659, 784, 1047, 1319], 0.05, 0.13, wave_type="square", lowpass=3200, gain=0.05) def mouse(mix): noise(mix, 0, 0.012, filter_type="highpass", freq=3000, gain=0.6) noise(mix, 0.08, 0.012, filter_type="highpass", freq=2600, gain=0.45) def xylo(mix): arpeggio(mix, 0, [523, 659, 784, 1047], 0.09, 0.38, wave_type="triangle", gain=0.13) def pageturn(mix): noise(mix, 0, 0.3, freq=1500, freq_end=600, quality=1, gain=0.15, attack=0.06) RECIPES = { recipe.__name__: recipe for recipe in [harp, swish, dreamy, tapestop, synth, cassette, windchime, rustle, clack, creak, drops, leafswish, airchime, whoosh, bubbles, tink, bell, scrape, beeps, relay, typewriter, slap, drone, wetpage, slide, whack, ratchet, hiss, glitch, blip, sonar, hud, quill, unfold, chip, mouse, xylo, pageturn] }