summaryrefslogtreecommitdiff
path: root/tools/spectral_editor/script.js
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-06 16:53:41 +0100
committerskal <pascal.massimino@gmail.com>2026-02-06 16:53:41 +0100
commitf998bfcd7a6167ae6bdf5ad7f8685b2cdf1fe811 (patch)
tree6dc288b12ed30914007ea54eaa8b2cc2d778b71b /tools/spectral_editor/script.js
parent6ed5952afe5c7a03f82ea02d261c3be2d56bd6a1 (diff)
fix(audio): Remove Hamming window from synthesis (before IDCT)
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 <noreply@anthropic.com>
Diffstat (limited to 'tools/spectral_editor/script.js')
-rw-r--r--tools/spectral_editor/script.js8
1 files changed, 4 insertions, 4 deletions
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];
}
}
}