# game-audio

Procedural game audio library. Generates tones, noise, pattern-based music, and full multi-track songs from a text format — without bundled audio files.

## Features

- **Tone** – sine wave with configurable frequency, frequency slide, and amplitude decay
- **Noise** – PRNG-based noise with decay
- **Sequence** – multi-segment frequency sequences for one-shot SFX
- **Track format** – multi-track songs in a `.track` text format with synthesized notes (custom timbres + ADSR), audio file clips (WAV/MP3/OGG/FLAC), per-track volume/pan/mute/solo/loop
- **SoundSystem** – rodio wrapper for one-shot, delayed, and ambient sounds

## Quick example

```rust
use std::time::Duration;
use game_audio::{Tone, Noise, Sequence, SoundSystem};

let system = SoundSystem::new();

system.play(Tone::new(Duration::from_millis(200), 440.0, 0.0, 0.2, 0.999));
system.play(Noise::new(Duration::from_millis(500), 0.5, 0.99995));
system.play(Sequence::new(&[(800.0, 0.04), (1100.0, 0.06)]));
```

## Track format

Songs live in `.track` files: a small text format with synthesizable sounds, multiple tracks, and clips placed on a beat timeline.

```
@tempo 120

# Sounds

bell:   sine 1, octave 0.4, decay 0.5
guitar: sine 0.6, triangle 0.3, attack 0.01, decay 0.2

# Track Drums
@volume 0.9

kick.wav 0
snare.wav 1

# Track Melody
@volume 0.6

bell 0 0 2
bell 2 7 2
```

- Sound definitions list harmonics (`sine`, `triangle`, `soft_square` with optional `@multiplier`) plus `distortion`, `volume`, `attack <sec> [linear|sine]`, `decay <sec> [linear|sine]`.
- Tracks have `@volume`, `@pan`, `@mute`, `@solo`, `@loop` directives.
- Note clips: `<sound> <start_beat> <pitch_semitones> <duration_beats>`. Pitch is in semitones relative to A4 (0 = 440 Hz).
- Audio clips: `<file.wav> <start_beat>`. Paths are relative to the song file.
- `@import other.track` pulls in another file's sound definitions.

Play a song:

```rust
use game_audio::{SoundSystem, track::SongPlayer};

let system = SoundSystem::new();
let mut player = SongPlayer::new();
player.play_path(&system, "song.track").unwrap();
```

The `track` module also exposes `parse`, `resolve_imports`, `Song`, `Sound`, `Harmonic`, `Note`, etc., for direct use without the convenience player.

## Editor

Companion crate [`multitrack`](https://crates.io/crates/multitrack) provides a graphical editor for `.track` files: timeline, mixer, sound designer, file open/save, live source view.

## Notes

This project is designed for use with AI coding assistants: consistent types, no implicit defaults, all parameters explicit. The `deny(missing_docs)` lint ensures complete documentation.
