diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-18 05:20:39 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-18 05:20:39 +0100 |
| commit | 1d3039f3e2e9269e69364a9b6da90fd28b36c18f (patch) | |
| tree | 03cfdeb04be20ee28264de2e5c0f6a353858afb1 /tools/mq_editor/viewer.js | |
| parent | 35ebfac6c860cc7de7db447b57158a7a3a27daaa (diff) | |
refactor(mq_editor): store only squared amplitude after FFT, drop re/im
handoff(Claude): removed full spectrum storage from STFTCache frames;
getFFT() deleted; viewers use squaredAmplitude + 10*log10 directly.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'tools/mq_editor/viewer.js')
| -rw-r--r-- | tools/mq_editor/viewer.js | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/tools/mq_editor/viewer.js b/tools/mq_editor/viewer.js index 21c0a0c..3ca2f87 100644 --- a/tools/mq_editor/viewer.js +++ b/tools/mq_editor/viewer.js @@ -166,7 +166,7 @@ class SpectrogramViewer { const frame = stftCache.getFrameAtIndex(frameIdx); if (!frame) continue; - const spectrum = frame.spectrum; + const squaredAmp = frame.squaredAmplitude; // Compute frame time range const frameTime = frame.time; @@ -186,10 +186,7 @@ class SpectrogramViewer { const freqNext = (bin + 1) * binFreqWidth; if (freqNext < this.freqStart || freq > this.freqEnd) continue; - const re = spectrum[bin * 2]; - const im = spectrum[bin * 2 + 1]; - const mag = Math.sqrt(re * re + im * im); - const magDB = 20 * Math.log10(Math.max(mag, 1e-10)); + const magDB = 10 * Math.log10(Math.max(squaredAmp[bin], 1e-20)); const normalized = (magDB + 80) / 80; const clamped = Math.max(0, Math.min(1, normalized)); @@ -488,8 +485,8 @@ class SpectrogramViewer { ctx.fillStyle = '#1e1e1e'; ctx.fillRect(0, 0, width, height); - const spectrum = cache.getFFT(this.spectrumTime); - if (!spectrum) return; + const squaredAmp = cache.getSquaredAmplitude(this.spectrumTime); + if (!squaredAmp) return; const fftSize = cache.fftSize; @@ -500,10 +497,7 @@ class SpectrogramViewer { for (let i = 0; i < numBars; ++i) { const binIdx = Math.floor(i * numBins / numBars); - const re = spectrum[binIdx * 2]; - const im = spectrum[binIdx * 2 + 1]; - const mag = Math.sqrt(re * re + im * im); - const magDB = 20 * Math.log10(Math.max(mag, 1e-10)); + const magDB = 10 * Math.log10(Math.max(squaredAmp[binIdx], 1e-20)); // Normalize to [0, 1] const normalized = (magDB + 80) / 80; |
