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>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
## Mono 16-bit PCM WAV files, written and read without the engine's importer, so the
|
||||
## generator's output is byte-for-byte the same on every run.
|
||||
extends RefCounted
|
||||
|
||||
const Dsp = preload("res://tools/audio/dsp.gd")
|
||||
|
||||
|
||||
static func encode(samples: PackedFloat32Array, rate: int = Dsp.RATE) -> PackedByteArray:
|
||||
var data: StreamPeerBuffer = StreamPeerBuffer.new()
|
||||
data.big_endian = false
|
||||
var bytes: int = samples.size() * 2
|
||||
data.put_data("RIFF".to_ascii_buffer())
|
||||
data.put_u32(36 + bytes)
|
||||
data.put_data("WAVEfmt ".to_ascii_buffer())
|
||||
data.put_u32(16)
|
||||
data.put_u16(1)
|
||||
data.put_u16(1)
|
||||
data.put_u32(rate)
|
||||
data.put_u32(rate * 2)
|
||||
data.put_u16(2)
|
||||
data.put_u16(16)
|
||||
data.put_data("data".to_ascii_buffer())
|
||||
data.put_u32(bytes)
|
||||
for value: float in samples:
|
||||
data.put_16(clampi(int(round(clampf(value, -1.0, 1.0) * 32767.0)), -32768, 32767))
|
||||
return data.data_array
|
||||
|
||||
|
||||
## The samples of a file encode() wrote, or an empty array if it isn't one.
|
||||
static func decode(bytes: PackedByteArray) -> PackedFloat32Array:
|
||||
var out: PackedFloat32Array = PackedFloat32Array()
|
||||
if bytes.size() < 44 or bytes.slice(0, 4).get_string_from_ascii() != "RIFF" or bytes.slice(36, 40).get_string_from_ascii() != "data":
|
||||
return out
|
||||
var count: int = bytes.decode_u32(40) / 2
|
||||
if 44 + count * 2 > bytes.size():
|
||||
return out
|
||||
out.resize(count)
|
||||
for i: int in count:
|
||||
out[i] = bytes.decode_s16(44 + i * 2) / 32767.0
|
||||
return out
|
||||
|
||||
|
||||
static func rate_of(bytes: PackedByteArray) -> int:
|
||||
return bytes.decode_u32(24) if bytes.size() >= 44 else 0
|
||||
Reference in New Issue
Block a user