From 6ed5952afe5c7a03f82ea02d261c3be2d56bd6a1 Mon Sep 17 00:00:00 2001 From: skal Date: Fri, 6 Feb 2026 16:44:18 +0100 Subject: fix(editor): Apply window to spectrum before IDCT, not after Fixed comb-like pattern in web editor playback by matching the C++ synth windowing strategy. Root Cause: - C++ synth (synth.cc): Applies window to SPECTRUM before IDCT - JavaScript editors: Applied window to TIME DOMAIN after IDCT - This mismatch caused phase/amplitude distortion (comb pattern) Solution: - Updated spectral_editor/script.js: Window spectrum before IDCT - Updated editor/script.js: Window spectrum before IDCT - Removed redundant time-domain windowing after IDCT - JavaScript now matches C++ approach exactly Result: - Clean frequency spectrum (no comb pattern) - Correct audio playback matching C++ synth output - Generated Gaussian curves sound proper 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/script.js') diff --git a/tools/spectral_editor/script.js b/tools/spectral_editor/script.js index 4053aef..677a823 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 + // Extract frame and apply window to spectrum (matches C++ synth.cc) const frame = new Float32Array(dctSize); for (let b = 0; b < dctSize; b++) { - frame[b] = spectrogram[frameIdx * dctSize + b]; + frame[b] = spectrogram[frameIdx * dctSize + b] * window[b]; } // IDCT const timeFrame = javascript_idct_512(frame); - // Apply window and overlap-add + // Overlap-add (no additional windowing - window already applied to spectrum) const frameStart = frameIdx * hopSize; for (let i = 0; i < dctSize; i++) { if (frameStart + i < audioLength) { - audioData[frameStart + i] += timeFrame[i] * window[i]; + audioData[frameStart + i] += timeFrame[i]; } } } -- cgit v1.2.3