Add an air horn sound, for the end of a timed match.
ui.air_horn(seconds=1.2): two brassy reeds a major third apart, each a pair of detuned sawtooths, scooping up into pitch, blaring with a faint flutter, then a short tail. Grave Racer's destruction derby ends with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
17fe11d229
commit
30b42f3efe
5 files changed
+32
-4
No files matched your search
@@ -1,10 +1,10 @@
|
||||
"""Interface sounds: beeps, menu moves, confirmations and on/off sweeps."""
|
||||
"""Interface sounds: beeps, menu moves, confirmations, on/off sweeps and an air horn."""
|
||||
|
||||
import math
|
||||
|
||||
import numpy as np
|
||||
|
||||
from .synth import sampleRate, soften, square_wave
|
||||
from .synth import Biquad, sampleRate, saw_wave, soften, square_wave
|
||||
|
||||
|
||||
def beep(frequency, seconds):
|
||||
@@ -22,6 +22,33 @@ def fanfare():
|
||||
return np.concatenate(parts)
|
||||
|
||||
|
||||
def air_horn(seconds=1.2):
|
||||
"""A loud stadium air horn, for something ending, such as time running out.
|
||||
|
||||
Two brassy reeds a major third apart, each a pair of slightly detuned
|
||||
sawtooths, scoop up into pitch as the air hits them, then blare with a
|
||||
faint flutter and cut off with a short tail.
|
||||
"""
|
||||
length = int(sampleRate * seconds)
|
||||
times = np.arange(length) / sampleRate
|
||||
# The pitch scoops up from a little flat over the first 80 milliseconds.
|
||||
scoop = 1.0 - 0.12 * np.exp(-times / 0.03)
|
||||
flutter = 1.0 + 0.004 * np.sin(2.0 * math.pi * 6.0 * times)
|
||||
horn = np.zeros(length)
|
||||
for frequency, level in ((349.2, 1.0), (440.0, 0.8)):
|
||||
for detune in (0.997, 1.004):
|
||||
phaseStep = frequency * detune * scoop * flutter / sampleRate
|
||||
horn += level * saw_wave(np.cumsum(phaseStep) % 1.0, phaseStep)
|
||||
# A reedy, nasal body: the band where an air horn blares, with the fizz above it taken off.
|
||||
body = Biquad("bandpass").process(horn, 1100.0, 0.9) + 0.35 * Biquad("lowpass").process(horn, 600.0)
|
||||
body = Biquad("lowpass").process(body, 3500.0)
|
||||
# Overblown: squash it, so it sounds strained.
|
||||
body = np.tanh(1.8 * body / np.max(np.abs(body)))
|
||||
attack = np.minimum(1.0, times / 0.02)
|
||||
release = np.clip((seconds - times) / 0.18, 0.0, 1.0) ** 1.5
|
||||
return 0.5 * body * attack * release
|
||||
|
||||
|
||||
def toggle_sweep(rising, seconds=0.14, low=500.0, high=1000.0):
|
||||
"""A short triangle tone gliding up an octave for something turning on, or down for turning off."""
|
||||
times = np.arange(int(sampleRate * seconds)) / sampleRate
|
||||
|
||||
Reference in new issue
Block a user