diff options
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; |
