From 69fd884aaec5523871696149cd39aff6b10c9397 Mon Sep 17 00:00:00 2001 From: skal Date: Fri, 6 Feb 2026 18:31:14 +0100 Subject: feat(audio): Add RMS normalization to spectool for consistent sample loudness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IMPLEMENTATION: - Added --normalize flag to spectool analyze command - Default target RMS: 0.15 (customizable via --normalize [rms]) - Two-pass processing: load all PCM → calculate RMS/peak → normalize → DCT - Peak-limiting safety: prevents clipping by limiting scale factor if peak > 1.0 - Updated gen_spectrograms.sh to use --normalize by default ALGORITHM: 1. Calculate original RMS and peak of input audio 2. Compute scale factor to reach target RMS (default 0.15) 3. Check if scaled peak would exceed 1.0 (after windowing + IDCT) 4. If yes, reduce scale factor to keep peak ≤ 1.0 (prevents clipping) 5. Apply scale factor to all PCM samples before windowing/DCT RESULTS: Before normalization: - RMS range: 0.054 - 0.248 (4.6x variation, ~13 dB) - Some peaks > 1.0 (clipping) After normalization: - RMS range: 0.049 - 0.097 (2.0x variation, ~6 dB) ✅ 2.3x improvement - All peaks < 1.0 (no clipping) ✅ SAMPLES REGENERATED: - All 14 .spec files regenerated with normalization - High dynamic range samples (SNARE_808, CRASH_DMX, HIHAT_CLOSED_DMX) were peak-limited to prevent clipping - Consistent loudness across all drum and bass samples GITIGNORE CHANGE: - Removed *.spec from .gitignore to track normalized spectrograms - This ensures reproducibility and prevents drift from source files handoff(Claude): RMS normalization implemented and working. All samples now have consistent loudness with no clipping. --- scripts/gen_spectrograms.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/gen_spectrograms.sh') diff --git a/scripts/gen_spectrograms.sh b/scripts/gen_spectrograms.sh index 7eb6bdc..a5c1510 100755 --- a/scripts/gen_spectrograms.sh +++ b/scripts/gen_spectrograms.sh @@ -49,7 +49,7 @@ process_file() { fi echo "Generating spectrogram: ${base_name} -> ${output_name}.spec" - "${SPECTOOL_PATH}" analyze "$file_to_process" "$spec_file" + "${SPECTOOL_PATH}" analyze "$file_to_process" "$spec_file" --normalize } # Find and process all audio files -- cgit v1.2.3