Files

181 lines
7.9 KiB
Python

"""Streak level 2's sounds: 2 s each, one per animation in level2.py (same names as its ANIMS).
Seeds 2200-2299.
"""
import functools
import math
import random
from sound_kit import SR, add_noise, add_tone, bell, ease_off, sbuf
def tail(fn):
"""Soften the last quarter second, so nothing still ringing stops dead at 2 s."""
@functools.wraps(fn)
def wrapped():
return ease_off(fn(), 0.25)
return wrapped
def crackles(b, start, dur, rate, amp, seed, f=(2500, 6000)):
"""Random tiny clicks: fizz, sparks, frying."""
rng = random.Random(seed)
for _ in range(int(dur * rate)):
st = start + rng.uniform(0, dur)
add_tone(b, st, 0.012, rng.uniform(*f), amp=amp * rng.uniform(0.3, 1.0), a=0.0005, d=0.003)
@tail
def plinkety():
"""A fairground jingle under three popgun shots, each a tok and a tinny ping, a clack as the board flips, and a ding-ding-ding win."""
b = sbuf()
tune = [523, 659, 784, 659, 587, 698, 880, 698]
for k, f in enumerate(tune):
add_tone(b, k * 0.14, 0.12, f, amp=0.06, a=0.005, d=0.08, shape="square")
for k, st in enumerate((0.3, 0.63, 0.96)):
add_noise(b, st, 0.05, 0.6, a=0.0005, d=0.012, lp0=0.6, seed=2200 + k)
add_tone(b, st, 0.04, 600, 250, 0.4, a=0.0005, d=0.012)
bell(b, st + 0.04, 2100 + k * 250, 0.22, 0.18)
add_tone(b, 1.12, 0.06, 400, 200, 0.4, a=0.0005, d=0.02, shape="square")
add_noise(b, 1.12, 0.05, 0.3, a=0.0005, d=0.015, lp0=0.5, seed=2205)
for k in range(3):
bell(b, 1.25 + k * 0.13, 1568, 0.25, 0.35)
for f in (523, 659, 784):
add_tone(b, 1.65, 0.35, f, amp=0.07, a=0.01, d=0.3, shape="square")
return b
@tail
def bumpers():
"""A plunger stretched and let go, three electric bumper bonks, a flipper clack, then multiball: a jangling cascade of bonks and beeps."""
b = sbuf()
add_tone(b, 0.0, 0.25, 300, 160, 0.12, a=0.2, d=0.3, shape="tri")
add_noise(b, 0.25, 0.25, 0.25, a=0.005, d=0.1, lp0=0.4, lp1=0.9, seed=2210)
def bonk(st, f, amp):
add_tone(b, st, 0.12, f, f * 0.7, amp, a=0.001, d=0.05, shape="square")
add_noise(b, st, 0.03, amp * 0.6, a=0.0005, d=0.01, lp0=0.8, seed=int(st * 997) + 2211)
for k, st in enumerate((0.42, 0.58, 0.75)):
bonk(st, 660 + 110 * k, 0.3)
add_tone(b, 0.92, 0.06, 220, 120, 0.4, a=0.0005, d=0.02)
add_noise(b, 0.92, 0.05, 0.3, a=0.0005, d=0.015, lp0=0.4, seed=2220)
rng = random.Random(2221)
for k in range(16):
st = 1.0 + k * 0.058
bonk(st, rng.choice((660, 770, 880, 990, 1320)), 0.18)
for k, f in enumerate((523, 659, 784, 1047, 1319)):
add_tone(b, 1.0 + k * 0.07, 0.15, f, amp=0.1, a=0.002, d=0.1, shape="square")
return b
@tail
def spindle():
"""The candyfloss tub's motor whirring up with airy whooshes, then a sugary harp sweep and sparkles."""
b = sbuf()
ph = 0.0
for k in range(int(SR * 1.15)):
t = k / SR
f = 90 + 80 * t
ph += 2 * math.pi * f / SR
am = 0.7 + 0.3 * math.sin(2 * math.pi * (6 + 10 * t) * t)
loud = min(1.0, t / 0.15) * (1.0 if t < 1.0 else (1.15 - t) / 0.15)
b[k] += (((ph / (2 * math.pi)) % 1.0) * 2 - 1) * 0.12 * am * loud
for k in range(6):
add_noise(b, k * 0.18, 0.18, 0.15, a=0.06, d=0.1, lp0=0.2, lp1=0.6, seed=2230 + k)
for k, f in enumerate((523, 587, 659, 784, 880, 1047, 1175, 1319, 1568)):
add_pl = 1.08 + k * 0.045
add_tone(b, add_pl, 0.5, f, amp=0.14, a=0.002, d=0.25, shape="tri")
rng = random.Random(2240)
for k in range(8):
bell(b, 1.4 + k * 0.06, rng.uniform(2600, 4000), 0.07, 0.15)
return b
@tail
def crowdroar():
"""A thumping kick, the ball whizzing, a SWISH of net, and a stadium crowd erupting with whistles."""
b = sbuf()
add_tone(b, 0.33, 0.12, 120, 60, 0.8, a=0.001, d=0.04)
add_noise(b, 0.33, 0.06, 0.4, a=0.0005, d=0.015, lp0=0.3, seed=2250)
add_noise(b, 0.36, 0.4, 0.2, a=0.05, d=0.3, lp0=0.6, lp1=0.9, seed=2251)
add_tone(b, 0.36, 0.4, 900, 1300, 0.05, a=0.05, d=0.3)
add_noise(b, 0.75, 0.2, 0.45, a=0.01, d=0.08, lp0=0.9, lp1=0.5, seed=2252)
for k in range(5): # the crowd: layers of soft roaring noise
add_noise(b, 0.78 + k * 0.03, 1.22, 0.16, a=0.25, d=1.5, lp0=0.12 + 0.05 * k, seed=2253 + k)
rng = random.Random(2260)
for k in range(40): # voices in it
st = 0.85 + rng.uniform(0, 1.0)
f = rng.uniform(250, 600)
add_tone(b, st, 0.3, f, f * rng.uniform(1.05, 1.3), 0.03, a=0.05, d=0.15, shape="saw")
for st, f in ((1.0, 2400), (1.35, 2700)): # whistles
add_tone(b, st, 0.25, f, f * 1.15, 0.08, a=0.02, d=0.3, vib=(9, 0.01))
return b
@tail
def dodgem():
"""Two electric hums zooming in with crackling sparks, a big CRUNCH-BONK, two springy rebounds, and sparks fizzing down."""
b = sbuf()
add_tone(b, 0.0, 0.67, 80, 160, 0.15, a=0.1, d=2.0, shape="saw")
add_tone(b, 0.0, 0.67, 95, 185, 0.12, a=0.1, d=2.0, shape="saw")
crackles(b, 0.0, 0.67, 40, 0.2, 2270)
add_noise(b, 0.67, 0.3, 0.8, a=0.0005, d=0.07, lp0=0.5, lp1=0.15, seed=2271)
add_tone(b, 0.67, 0.25, 110, 50, 0.8, a=0.001, d=0.08)
bell(b, 0.68, 520, 0.2, 0.15)
for st in (0.8, 0.95):
add_tone(b, st, 0.25, 250, 500, 0.15, a=0.005, d=0.12, vib=(20, 0.1))
crackles(b, 0.68, 1.25, 70, 0.3, 2272)
add_noise(b, 0.7, 1.25, 0.1, a=0.02, d=1.0, lp0=0.95, seed=2273)
for k, f in enumerate((784, 988, 1175, 1568)):
add_tone(b, 1.05 + k * 0.1, 0.5, f, amp=0.2, a=0.005, d=0.4, shape="tri")
return b
@tail
def rawr():
"""A tom-tom roll, a whooshing leap through fire, a soft paw landing, and a big lion ROAR."""
b = sbuf()
for k in range(8):
add_tone(b, k * 0.04, 0.08, 130, 100, 0.12 + 0.03 * k, a=0.001, d=0.04)
add_noise(b, 0.33, 0.6, 0.4, a=0.15, d=0.3, lp0=0.08, lp1=0.4, seed=2280)
crackles(b, 0.4, 0.8, 50, 0.12, 2281, (1200, 3500))
add_tone(b, 0.95, 0.1, 140, 80, 0.4, a=0.002, d=0.04)
for ratio, a in ((1, 0.5), (2, 0.3), (3, 0.2), (5, 0.08)): # the roar: a growling, swelling saw
add_tone(b, 1.08, 0.75, 120 * ratio, 85 * ratio, a * 0.5, a=0.12, d=0.5, shape="saw", vib=(28, 0.06))
add_noise(b, 1.08, 0.75, 0.3, a=0.1, d=0.4, lp0=0.2, seed=2282)
return b
@tail
def fizzle():
"""Three soft cakey thumps as the tiers land, a match struck, and sparklers spitting and fizzing over a happy little tune."""
b = sbuf()
for k, st in enumerate((0.17, 0.42, 0.67)):
add_tone(b, st, 0.15, 150 - 15 * k, 70, 0.5, a=0.002, d=0.05)
add_noise(b, st, 0.08, 0.25, a=0.002, d=0.03, lp0=0.25, seed=2290 + k)
add_noise(b, 0.92, 0.12, 0.4, a=0.003, d=0.05, lp0=0.9, lp1=0.4, seed=2293)
add_noise(b, 1.0, 1.0, 0.18, a=0.03, d=2.0, lp0=0.95, seed=2294)
crackles(b, 1.0, 1.0, 140, 0.25, 2295)
for k, f in enumerate((784, 784, 880, 784, 1047, 988)):
add_tone(b, 1.05 + k * 0.15, 0.14, f, amp=0.1, a=0.005, d=0.12, shape="tri")
return b
@tail
def sizzle():
"""A frying pan sizzling, three flips (whoosh, flop), a whistling spin for the last, a ding as it lands, and a glug of syrup."""
b = sbuf()
add_noise(b, 0.0, 2.0, 0.08, a=0.1, d=3.0, lp0=0.9, seed=2296)
crackles(b, 0.0, 2.0, 50, 0.1, 2297, (3000, 7000))
for k, (st, land) in enumerate(((0.08, 0.42), (0.42, 0.75), (0.75, 1.08))):
add_noise(b, st, 0.15, 0.25, a=0.02, d=0.06, lp0=0.3, lp1=0.7, seed=2210 + k)
add_tone(b, land, 0.1, 160, 110, 0.4, a=0.002, d=0.04)
add_noise(b, land, 0.06, 0.2, a=0.002, d=0.03, lp0=0.2, seed=2220 + k)
add_tone(b, 1.08, 0.4, 700, 1400, 0.12, a=0.02, d=0.5, vib=(12, 0.08))
bell(b, 1.5, 1319, 0.3, 0.4)
for k in range(5): # syrup glugs
add_tone(b, 1.58 + k * 0.07, 0.07, 180 + 20 * k, 320 + 30 * k, 0.2, a=0.005, d=0.03)
return b
SOUNDS = [plinkety, bumpers, spindle, crowdroar, dodgem, rawr, fizzle, sizzle]