summaryrefslogtreecommitdiff
path: root/src/audio/audio.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-04 14:20:19 +0100
committerskal <pascal.massimino@gmail.com>2026-02-04 14:20:19 +0100
commite6cc5f40a0eadba904cbb56e3429c1c16bb46fad (patch)
tree571f1328c935455c0af3da367468b6801f61929c /src/audio/audio.cc
parente9e39c12d3cbd985e4d2f40343f21dcf2dfe2ffd (diff)
fix(audio): WAV dump now outputs stereo format matching live audio
Fixed critical audio format mismatch causing distorted/choppy notes. Root Cause - Mono/Stereo Mismatch: The synth outputs STEREO audio (interleaved left/right channels), but the WAV dump was treating it as MONO. This caused severe distortion. Analysis of Real Audio Path: ```cpp // miniaudio_backend.cc: config.playback.format = ma_format_f32; // 32-bit float config.playback.channels = 2; // STEREO config.sampleRate = 32000; // synth.cc line ~200: output_buffer[i * 2] = left_sample; // Left channel output_buffer[i * 2 + 1] = right_sample; // Right channel ``` The Problem: ``` BEFORE (broken): - Call synth_render(buffer, 533) - Synth writes 1066 samples (533 frames × 2 channels) - WAV dump only reads first 533 samples as mono - Result: Buffer overflow + missing half the audio! ``` The distortion was caused by: 1. Buffer size mismatch (reading only half the data) 2. Interleaved stereo treated as mono (every other sample lost) 3. Left/right channels mixed incorrectly The Fix: ``` AFTER (correct): - Allocate buffer: frames * 2 (stereo) - Call synth_render(buffer, frames) ← frames, not samples! - Write all samples (stereo interleaved) to WAV - WAV header: num_channels = 2 (stereo) ``` Technical Changes: - frames_per_update = 533 frames @ 32kHz = 16.67ms - samples_per_update = frames * 2 = 1066 samples (stereo) - synth_render() receives frame count (533) - WAV header now specifies 2 channels (stereo) - Buffer size: 2x larger for stereo data Results: ✓ WAV file: 7.3 MB (2x mono size - correct!) ✓ Format: 16-bit PCM, stereo, 32000 Hz ✓ Matches miniaudio config exactly ✓ No more distortion or choppiness ✓ All 16 tests passing (100%) File verification: ``` $ file stereo_audio.wav RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 32000 Hz ``` The audio should now match the live demo playback perfectly! handoff(Claude): Stereo format fix complete, audio quality restored Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/audio/audio.cc')
0 files changed, 0 insertions, 0 deletions