Skip to content

[Audio] Sampled Sound Effects + Positional Audio System #108

@putersdcat

Description

@putersdcat

Why this issue exists

Closed issue #75 delivered an oscillator-based SFX engine, but the original spec (Docs/Epic Music and Sound Engine Implementation.md) called for sampled audio files with positional (spatial) audio — creating recognizable real-world sounds rather than abstract electronic beeps.

Gap Analysis — What Was Specified vs. What Was Delivered

❌ No Sampled Audio Files

The spec called for pre-recorded WAV/OGG files from FreeSound.org:

  • Cat purring (soft rumble loop on scritch interaction)
  • ""Ouch"" cartoon yelp (bumps/sharp objects)
  • Waterfall rushing water loop (distance-based volume)
  • Night owls (random interval hoots)
  • Crickets (ambient loop)
  • Dusk crickets fade-in
  • Morning rooster crow, birds tweeting with chirp variations

Current reality: All 22 SFX are oscillator-synthesized (sine/square waves). The ""bird"" ambience is a 2400Hz sine wave with LFO modulation — sounds like electronic warbling, not a bird. The ""owl"" is a 400Hz sine hum. No recognizable real-world sounds exist.

❌ No Positional Audio (PannerNode)

The spec called for Web Audio PannerNode for distance-based volume:

  • Waterfall gets louder as player approaches
  • Sound sources have world positions that affect stereo pan + volume

Current reality: Flat volume for all SFX. GainNode only for volume control. No PannerNode anywhere in codebase. No spatial audio at all.

❌ No AudioWorklet for Heavy DSP

Spec mentioned AudioWorklet for complex mixing without GC/FPS drops. Not implemented (all audio on main thread via standard nodes). This may become necessary as more audio sources are added.

Scope

Phase 1: Sampled SFX Pipeline (High Priority)

  • Source 15-20 public domain audio samples from FreeSound.org / similar:
    • Animal: Cat purr (loop), bird chirp (3 variations), owl hoot, rooster crow, cricket chirp (loop), frog croak
    • Environment: Waterfall rush (loop), wind gust, rain patter, thunder crack, campfire crackle (loop)
    • Interaction: Footstep (grass/dirt/stone variants), ""Ouch"" yelp, coin clink, chest creak
  • Convert to OGG for size, bundle in public/audio/sfx/
  • Build AudioBuffer loading pipeline with preload + cache
  • Replace highest-impact oscillator SFX with sampled equivalents (keep oscillator as fallback)

Phase 2: Positional Audio (Medium Priority)

  • Add PannerNode support to SFX engine for distance-based volume
  • Calculate listener position from player world coords
  • Wire waterfall, campfire, NPC voice sources to world positions
  • Attenuate based on distance (e.g., max audible at 5 tiles, fade to 0 at 15 tiles)
  • Stereo pan based on relative screen position

Phase 3: Ambience Polish (Medium Priority)

  • Replace oscillator ambience layers with sampled loops:
    • Day: Mixed birdsong + breeze
    • Dusk: Crickets fade-in + last birdsong
    • Night: Cricket loop + owl hoots (random interval) + breeze
    • Morning: Rooster crow (time trigger) + dawn birdsong
  • Crossfade between ambience profiles on time-of-day transitions
  • Add biome-specific ambience overlays (waterfall near river, wind in mountains)

Acceptance Criteria

  • At least 15 sampled audio effects play in-game with recognizable sounds
  • Waterfall and campfire have distance-based volume attenuation
  • Time-of-day ambience uses at least partially sampled sources (not pure oscillator)
  • No FPS impact (benchmark with 5+ simultaneous sources)
  • npx tsc --noEmit and Playwright tests pass

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    artArt and visual assetsfeatureNew featurehigh-priorityHigh priority item

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions