Files

142 lines
6.2 KiB
Python

"""Streak level 4's sounds: 2 s each, one per animation in level4.py (same names as its ANIMS).
Seeds 2400-2499 (see level0_sounds.py).
"""
import math
import random
from sound_kit import SR, add_noise, add_tone, bell, ease_off, sbuf
def brass(b, st, dur, f, amp=0.12, d=0.6, vib=(5, 0.006)):
for ratio, a in ((1, 1.0), (2, 0.45), (3, 0.2)):
add_tone(b, st, dur, f * ratio, amp=amp * a, a=0.02, d=d, shape="saw", vib=vib)
def piano(b, st, f, amp=0.25, d=0.35, dur=0.9):
for ratio, a in ((1, 1.0), (2, 0.35), (3, 0.12), (4, 0.06)):
add_tone(b, st, dur, f * ratio, amp=amp * a, a=0.003, d=d / ratio ** 0.4)
def ovation():
"""The curtains swish open, a brassy fanfare, and a roar of applause."""
b = sbuf()
add_noise(b, 0.05, 0.7, 0.35, a=0.3, d=0.3, lp0=0.25, lp1=0.6, seed=2400)
for st, chord, dur in ((0.66, (392, 494, 587), 0.14), (0.82, (523, 659, 784, 1046), 0.9)):
for f in chord:
brass(b, st, dur, f, 0.09, 0.5)
rng = random.Random(2401)
for k in range(150): # the applause: many hands
st = 0.85 + rng.uniform(0, 1.12)
swell = min(1.0, (st - 0.85) / 0.3)
add_noise(b, st, 0.03, 0.12 * swell, a=0.0005, d=0.008, lp0=rng.uniform(0.5, 0.9), seed=2402 + k)
return ease_off(b, 0.4)
def showtime():
"""Bulbs ticking round, a big-band hit as the number lands, and a swinging riff."""
b = sbuf()
for k in range(22): # the chase
add_tone(b, 0.02 + k * 0.083, 0.02, 3000 if k % 3 else 2200, amp=0.06, a=0.001, d=0.006)
for f in (233, 294, 349, 415, 523): # the hit, a fat seventh
brass(b, 0.42, 0.35, f, 0.08, 0.2)
add_noise(b, 0.42, 0.5, 0.25, a=0.002, d=0.2, lp0=0.95, seed=2410)
for st, f in ((0.95, 392), (1.12, 466), (1.2, 523), (1.37, 587), (1.45, 698)):
brass(b, st, 0.14, f, 0.1, 0.15)
for f in (349, 440, 523, 698):
brass(b, 1.58, 0.42, f, 0.07, 0.4, vib=(6, 0.01))
add_noise(b, 1.58, 0.42, 0.18, a=0.002, d=0.25, lp0=0.95, seed=2411)
return b
def projector():
"""A projector's clatter, three countdown beeps, and a swelling chord as the picture lights."""
b = sbuf()
for k in range(48): # the clatter, 24 a second
st = k / 24
add_noise(b, st, 0.015, 0.1, a=0.0005, d=0.004, lp0=0.6, seed=2420 + k)
add_tone(b, st, 0.012, 900, amp=0.03, a=0.0005, d=0.003)
for st in (0.25, 0.58, 0.92):
add_tone(b, st, 0.12, 1000, amp=0.25, a=0.003, d=1.0, shape="tri")
for f in (262, 330, 392, 523, 659):
add_tone(b, 1.08, 0.92, f, amp=0.08, a=0.12, d=1.0, shape="saw", vib=(5, 0.005))
bell(b, 1.08, 1046, 0.12, 0.5)
return ease_off(b, 0.25)
def arpeggio():
"""A rippling run up the keyboard, a big chord as the notes spray, and a sparkle at the top."""
b = sbuf()
notes = [131, 165, 196, 262, 330, 392, 523, 659, 784, 1046, 1319]
for k, f in enumerate(notes):
piano(b, 0.22 + k * 0.055, f, 0.2, 0.3, 0.6)
for f in (131, 262, 330, 392, 523, 659):
piano(b, 0.85, f, 0.17, 0.6, 1.15)
rng = random.Random(2430)
for k in range(8):
piano(b, 1.0 + k * 0.1 + rng.uniform(0, 0.03), rng.choice((1568, 2093, 2637, 3136)), 0.07, 0.15, 0.4)
return ease_off(b, 0.2)
def bwong():
"""A whoosh as the mallet winds back, then one huge shimmering, beating gong stroke."""
b = sbuf()
add_noise(b, 0.3, 0.37, 0.2, a=0.3, d=0.2, lp0=0.1, lp1=0.4, seed=2440)
st = 0.67
add_tone(b, st, 0.2, 80, 50, 0.7, a=0.001, d=0.06)
add_noise(b, st, 0.12, 0.4, a=0.001, d=0.03, lp0=0.3, seed=2441)
for ratio, a, d in ((1, 0.5, 0.9), (1.012, 0.35, 0.9), (1.52, 0.3, 0.7), (2.03, 0.22, 0.6), (2.71, 0.16, 0.5),
(3.49, 0.1, 0.35), (4.13, 0.07, 0.3), (5.6, 0.04, 0.2)):
f = 98 * ratio
add_tone(b, st, 2.0 - st, f * 0.985, f * 1.01, a, a=0.004, d=d)
return ease_off(b, 0.3)
def burner():
"""Three roaring gusts of the burner, under a rising, airy tune."""
b = sbuf()
for k, (st, dur) in enumerate(((0.08, 0.26), (0.75, 0.2), (1.33, 0.28))):
add_noise(b, st, dur + 0.1, 0.55, a=0.02, d=0.25, lp0=0.15, seed=2450 + k)
add_noise(b, st, dur + 0.1, 0.15, a=0.01, d=0.15, lp0=0.6, seed=2455 + k)
add_tone(b, st, dur + 0.1, 55, 60, 0.25, a=0.02, d=0.2, shape="tri")
for st, f, dur in ((0.35, 392, 0.4), (0.7, 523, 0.4), (1.05, 659, 0.4), (1.4, 784, 0.6)):
add_tone(b, st, dur, f, amp=0.12, a=0.06, d=0.5, shape="tri", vib=(5, 0.008))
add_tone(b, st, dur, f * 2, amp=0.03, a=0.06, d=0.3)
return ease_off(b, 0.3)
def quindar():
"""The beep of a far-off radio, a hissing descent, a soft thump down, the answering beep and a bright chord."""
b = sbuf()
add_tone(b, 0.0, 0.25, 2525, amp=0.18, a=0.003, d=1.0)
add_noise(b, 0.15, 0.8, 0.3, a=0.15, d=0.6, lp0=0.7, lp1=0.4, seed=2460)
add_tone(b, 0.15, 0.8, 70, 85, 0.15, a=0.1, d=0.6, shape="tri")
add_tone(b, 0.92, 0.2, 90, 45, 0.6, a=0.001, d=0.06)
add_noise(b, 0.92, 0.35, 0.3, a=0.002, d=0.12, lp0=0.3, lp1=0.1, seed=2461)
add_tone(b, 1.0, 0.25, 2475, amp=0.18, a=0.003, d=1.0)
for f in (392, 523, 659, 784):
add_tone(b, 1.12, 0.88, f, amp=0.09, a=0.03, d=0.6, shape="tri", vib=(5, 0.006))
bell(b, 1.12, 1568, 0.07, 0.4)
return ease_off(b, 0.25)
def starfall():
"""Falling pings, more and more of them, a rushing fireball, and a crackling burst of shimmer."""
b = sbuf()
rng = random.Random(2470)
for k in range(22):
st = 0.04 + 0.95 * (k / 22) ** 0.8 + rng.uniform(0, 0.03)
f = rng.uniform(1800, 3400)
add_tone(b, st, 0.22, f, f * 0.55, amp=0.12, a=0.003, d=0.08)
add_noise(b, 0.5, 0.5, 0.35, a=0.45, d=0.2, lp0=0.1, lp1=0.8, seed=2471)
add_tone(b, 1.0, 0.2, 120, 50, 0.55, a=0.001, d=0.08)
add_noise(b, 1.0, 0.35, 0.4, a=0.001, d=0.08, lp0=0.9, seed=2472)
for k in range(18):
add_noise(b, 1.05 + rng.uniform(0, 0.6), 0.01, 0.15, a=0.0005, d=0.003, lp0=0.9, seed=2473 + k)
for f in (1047, 1319, 1568, 2093):
bell(b, 1.0, f, 0.1, 0.45)
return ease_off(b, 0.3)
SOUNDS = [ovation, showtime, projector, arpeggio, bwong, burner, quindar, starfall]