Files
claudeandClaude Opus 5.5 2545337204 A8: Synthesized sound effects and an adaptive score
Every sound is made by scripts in tools/audio/ and committed as a WAV in
assets/audio/ with a manifest of hashes and levels:

- dsp.gd: seeded noise, wavetable oscillators, filters, envelopes and
  struck modes. recipes.gd: 50 effects (footsteps on five surfaces,
  a report per weapon, impacts, carpentry building and breaking, the
  tide's bell, foghorn, surge and lighthouse, player, ambience, menus).
- score.gd: an original eight-bar tune and chords in D Dorian, 6/8,
  rendered as four looping layers (drone, frame drum, concertina,
  fiddle).
- loudness.gd and check.gd: per-category loudness targets, a -1 dBFS
  peak ceiling and the mix order (the tide loudest). make audio and
  make audio-check.

In the client, SoundDirector turns FX records, footsteps, building,
the tide and the player's own hurts into sounds, placed on 3D voices
at the event so gunfire and footsteps come from their direction.
MusicDirector fades the score's layers with the tide on an
AudioStreamSynchronized, full in menus. MenuSounds knocks for buttons.

Closes #48

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 14:28:34 -05:00

147 lines
5.4 KiB
GDScript

## Tidewall's adaptive score: one eight-bar tune in D Dorian, 6/8 at 72 dotted
## crotchets a minute, rendered as four layers that loop together and are faded in
## and out by the client (MusicDirector) as the tide builds:
##
## drone low D and A bowed together, always there
## drum a frame drum's 6/8 pulse, from the first rise
## concertina chords on the bellows, from the middle phases
## fiddle the tune, in menus, results and the last land
##
## The tune and the chords were written for Tidewall (see assets/PROVENANCE.md). They
## follow no existing song: the melody is the note list below, nothing else.
extends RefCounted
const Dsp = preload("res://tools/audio/dsp.gd")
const LAYERS: Array[String] = ["music_drone", "music_drum", "music_concertina", "music_fiddle"]
## Loudness per layer in dBFS RMS, so the full mix sits near -20.
const TARGETS: Dictionary = {
"music_drone": -29.0,
"music_drum": -28.0,
"music_concertina": -29.0,
"music_fiddle": -26.0,
}
const EIGHTH: float = 60.0 / (72.0 * 3.0)
const BAR_EIGHTHS: int = 6
const BARS: int = 8
## The tune: [MIDI note, length in quavers], six quavers to a bar.
const TUNE: Array = [
[69, 3], [67, 1], [65, 2],
[64, 2], [62, 1], [64, 3],
[65, 1], [67, 1], [69, 1], [74, 3],
[72, 2], [69, 1], [64, 3],
[62, 1], [65, 1], [69, 1], [71, 2], [69, 1],
[67, 3], [64, 3],
[71, 2], [67, 1], [74, 3],
[69, 3], [62, 3],
]
## One chord a bar, as MIDI notes: Dm C Dm Am Dm C G Dm.
const CHORDS: Array = [
[50, 53, 57], [48, 52, 55], [50, 53, 57], [45, 52, 57],
[50, 53, 57], [48, 52, 55], [47, 50, 55], [50, 53, 57],
]
## Frame drum strokes per bar, a gain per quaver (0 for a rest); bar 4 and 8 fill.
const DRUM: Array = [1.0, 0.0, 0.45, 0.8, 0.0, 0.45]
const DRUM_FILL: Array = [1.0, 0.35, 0.45, 0.8, 0.5, 0.6]
static func loop_seconds() -> float:
return EIGHTH * BAR_EIGHTHS * BARS
static func render(layer: String) -> PackedFloat32Array:
match layer:
"music_drone":
return _drone()
"music_drum":
return _drum()
"music_concertina":
return _concertina()
"music_fiddle":
return _fiddle()
return PackedFloat32Array()
static func _loop() -> PackedFloat32Array:
var out: PackedFloat32Array = PackedFloat32Array()
out.resize(int(round(loop_seconds() * Dsp.RATE)))
out.fill(0.0)
return out
## A bowed note: soft attack, slow vibrato that grows, a short release.
static func _bowed(note: int, seconds: float, vibrato_depth: float) -> PackedFloat32Array:
var hz: float = Dsp.midi_hz(note)
var tone: PackedFloat32Array = Dsp.osc("bow", seconds + 0.15, [hz], [5.3, vibrato_depth])
tone = Dsp.lowpass(tone, [2600.0])
return Dsp.shape(tone, [[0.0, 0.0], [0.07, 1.0], [seconds * 0.6, 0.85], [seconds, 0.7], [seconds + 0.15, 0.0]])
static func _drone() -> PackedFloat32Array:
var out: PackedFloat32Array = _loop()
var length: float = loop_seconds()
var fade: float = 1.5
for note: int in [38, 45, 50]:
var hz: float = Dsp.midi_hz(note)
var tone: PackedFloat32Array = Dsp.osc("bow", length + fade, [hz], [0.21, 0.04])
tone = Dsp.lowpass(tone, [900.0], 2)
# Swells with the bow, twice a loop.
tone = Dsp.shape(tone, [[0.0, 0.0], [fade, 0.8], [length * 0.25, 1.0], [length * 0.5, 0.75], [length * 0.75, 1.0], [length, 0.8], [length + fade, 0.0]])
Dsp.mix_into(out, tone, 0, 0.5 if note == 50 else 1.0, true)
return out
static func _drum() -> PackedFloat32Array:
var out: PackedFloat32Array = _loop()
var rng: RandomNumberGenerator = RandomNumberGenerator.new()
rng.seed = 6809
for bar: int in BARS:
var pattern: Array = DRUM_FILL if bar % 4 == 3 else DRUM
for q: int in BAR_EIGHTHS:
var gain: float = float(pattern[q])
if gain <= 0.0:
continue
var low: bool = q == 0 or q == 3
var base: float = 82.0 if low else 120.0
var hit: PackedFloat32Array = Dsp.modes(0.5, base, [1.0, 1.59, 2.14], [1.0, 0.4, 0.2], [0.35 if low else 0.18, 0.12, 0.08], 0.85)
var slap: PackedFloat32Array = Dsp.decay(Dsp.bandpass(Dsp.noise(0.06, rng.randi()), [1600.0], 1.0), 0.0, 0.03)
Dsp.mix_into(hit, slap, 0, 0.5 if low else 0.8)
var at: int = int(round((bar * BAR_EIGHTHS + q) * EIGHTH * Dsp.RATE))
Dsp.mix_into(out, hit, at, gain * rng.randf_range(0.9, 1.0), true)
return out
static func _concertina() -> PackedFloat32Array:
var out: PackedFloat32Array = _loop()
for bar: int in BARS:
var chord: Array = CHORDS[bar]
# Two bellows pushes a bar, on each dotted crotchet.
for half: int in 2:
var seconds: float = EIGHTH * 3.0 - 0.06
var press: PackedFloat32Array = Dsp.silence(seconds + 0.1)
for note: int in chord:
var hz: float = Dsp.midi_hz(note)
Dsp.mix_into(press, Dsp.osc("reed", seconds + 0.1, [hz * 0.9977]), 0, 0.5)
Dsp.mix_into(press, Dsp.osc("reed", seconds + 0.1, [hz * 1.0023], [0.0, 0.0], 0.37), 0, 0.5)
press = Dsp.lowpass(press, [1700.0], 2)
var gain: float = 1.0 if half == 0 else 0.7
press = Dsp.shape(press, [[0.0, 0.0], [0.06, gain], [seconds, gain * 0.8], [seconds + 0.1, 0.0]])
var at: int = int(round((bar * BAR_EIGHTHS + half * 3) * EIGHTH * Dsp.RATE))
Dsp.mix_into(out, press, at, 1.0, true)
return out
static func _fiddle() -> PackedFloat32Array:
var out: PackedFloat32Array = _loop()
var quaver: int = 0
for entry: Array in TUNE:
var note: int = int(entry[0])
var length: int = int(entry[1])
var seconds: float = length * EIGHTH - 0.02
var tone: PackedFloat32Array = _bowed(note, seconds, 0.05 + 0.04 * length)
Dsp.mix_into(out, tone, int(round(quaver * EIGHTH * Dsp.RATE)), 1.0, true)
quaver += length
return out