From f998bfcd7a6167ae6bdf5ad7f8685b2cdf1fe811 Mon Sep 17 00:00:00 2001 From: skal Date: Fri, 6 Feb 2026 16:53:41 +0100 Subject: fix(audio): Remove Hamming window from synthesis (before IDCT) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed incorrect windowing before IDCT in both C++ and JavaScript. The Hamming window is ONLY for analysis (before DCT), not synthesis. Changes: - synth.cc: Removed windowing before IDCT (direct spectral → IDCT) - spectral_editor/script.js: Removed spectrum windowing, kept time-domain window for overlap-add - editor/script.js: Removed spectrum windowing, kept time-domain window for smooth transitions Windowing Strategy (Correct): - ANALYSIS (spectool.cc, gen.cc): Apply window BEFORE DCT - SYNTHESIS (synth.cc, editors): NO window before IDCT Why: - Analysis window reduces spectral leakage during DCT - Synthesis needs raw IDCT output for accurate reconstruction - Time-domain window after IDCT is OK for overlap-add smoothing Result: - Correct audio synthesis without spectral distortion - Spectrograms reconstruct properly - C++ and JavaScript now match correct approach All 23 tests pass. Co-Authored-By: Claude Sonnet 4.5 --- tools/spectral_editor/script.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tools/spectral_editor') diff --git a/tools/spectral_editor/script.js b/tools/spectral_editor/script.js index 677a823..6c6dd49 100644 --- a/tools/spectral_editor/script.js +++ b/tools/spectral_editor/script.js @@ -1543,20 +1543,20 @@ function spectrogramToAudio(spectrogram, dctSize, numFrames) { const window = hanningWindowArray; for (let frameIdx = 0; frameIdx < numFrames; frameIdx++) { - // Extract frame and apply window to spectrum (matches C++ synth.cc) + // Extract frame (no windowing - window is only for analysis, not synthesis) const frame = new Float32Array(dctSize); for (let b = 0; b < dctSize; b++) { - frame[b] = spectrogram[frameIdx * dctSize + b] * window[b]; + frame[b] = spectrogram[frameIdx * dctSize + b]; } // IDCT const timeFrame = javascript_idct_512(frame); - // Overlap-add (no additional windowing - window already applied to spectrum) + // Apply synthesis window for overlap-add const frameStart = frameIdx * hopSize; for (let i = 0; i < dctSize; i++) { if (frameStart + i < audioLength) { - audioData[frameStart + i] += timeFrame[i]; + audioData[frameStart + i] += timeFrame[i] * window[i]; } } } -- cgit v1.2.3