summaryrefslogtreecommitdiff
path: root/src/audio/gen.cc
AgeCommit message (Collapse)Author
20 hoursfix(audio): Normalize procedurally generated notes to consistent RMS levelskal
ISSUE: Generated NOTE_ samples were extremely loud and not normalized: - Peak: 9.994 (999% over limit - severe clipping) - RMS: 3.486 (23x louder than normalized asset samples) - User report: "NOTE_ is way too loud" ROOT CAUSE: generate_note_spectrogram() applied a fixed scale factor (6.4) without measuring actual output levels. This was a guess from commit f998bfc that didn't account for harmonic synthesis amplification. SOLUTION: Added post-generation normalization (matching spectool --normalize): 1. Generate spectrogram with existing algorithm 2. Synthesize PCM via IDCT to measure actual output 3. Calculate RMS and peak of synthesized audio 4. Scale spectrogram to target RMS (0.15, matching normalized assets) 5. Limit by peak to prevent clipping (max safe peak = 1.0) RESULTS: After normalization: - Peak: 0.430 (safe, no clipping) ✅ - RMS: 0.150 (exactly target) ✅ - Consistent with normalized asset samples (RMS 0.09-0.15 range) IMPROVEMENT: - Peak reduced by 23.3x (9.994 → 0.430) - RMS reduced by 23.2x (3.486 → 0.150) - Procedural notes now have same perceived loudness as assets COST: Small CPU overhead during note generation (one-time cost per unique note): - One full IDCT pass per note (31 frames × 512 samples) - Negligible for tracker system with caching (14 unique samples total) handoff(Claude): Generated notes now normalized to match asset samples. All audio levels consistent.
21 hoursfix(audio): Fix spectrogram amplification issue and add diagnostic toolskal
## Root Cause .spec files were NOT regenerated after orthonormal DCT changes (commit d9e0da9). They contained spectrograms from old non-orthonormal DCT (16x larger values), but were played back with new orthonormal IDCT. Result: 16x amplification → Peaks of 12-17x → Severe clipping/distortion ## Diagnosis Tool Created specplay tool to analyze and play .spec/.wav files: - Reports PCM peak and RMS values - Detects clipping during playback - Usage: ./build/specplay <file.spec|file.wav> ## Fixes 1. Revert accidental window.h include in synth.cc (keep no-window state) 2. Adjust gen.cc scaling from 16x to 6.4x (16/2.5) for procedural notes 3. Regenerated ALL .spec files with ./scripts/gen_spectrograms.sh ## Verified Results Before: Peak=16.571 (KICK_3), 12.902 (SNARE_2), 14.383 (SNARE_3) After: Peak=0.787 (BASS_GUITAR_FEEL), 0.759 (SNARE_909), 0.403 (KICK_606) All peaks now < 1.0 (safe range)
23 hoursfix(audio): Scale procedural note generation for orthonormal DCTskal
Fixed procedural notes (NOTE_*) being inaudible by adding scaling compensation in gen.cc. Root Cause: - Old non-orthonormal DCT produced values ~16x larger (no sqrt scaling) - New orthonormal DCT: output *= sqrt(1/N) or sqrt(2/N) - Procedural note generation in gen.cc now produces 16x smaller spectrograms - IDCT expects same magnitude as .spec files -> notes too quiet Solution: - Added scale_factor = sqrt(DCT_SIZE / 2) = sqrt(256) = 16 - Multiply DCT output by 16 to match old magnitude - Procedural notes now have same loudness as sample-based notes Verification: - Checked spectral_editor: does not use DCT for procedural - Checked editor tools: no procedural generation with DCT - All 23 tests pass Procedural notes should now be audible at correct volume. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
7 daysclang-formatskal
7 daysstyle: add vertical compression rules to clang-formatskal
- Enabled AllowShortFunctionsOnASingleLine: All - Enabled AllowShortBlocksOnASingleLine: Always - Enabled AllowShortIfStatementsOnASingleLine: Always - Enabled AllowShortLoopsOnASingleLine: true - Set MaxEmptyLinesToKeep: 1 - Applied formatting to all source files.
8 daysChore: Add missing newlines at end of source filesskal
8 daysImplement procedural audio generation, spectral effects, and WebGPU particle ↵skal
system
8 daysadd notesskal