summaryrefslogtreecommitdiff
path: root/tools/mq_editor/fft.js
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-18 05:20:39 +0100
committerskal <pascal.massimino@gmail.com>2026-02-18 05:20:39 +0100
commit1d3039f3e2e9269e69364a9b6da90fd28b36c18f (patch)
tree03cfdeb04be20ee28264de2e5c0f6a353858afb1 /tools/mq_editor/fft.js
parent35ebfac6c860cc7de7db447b57158a7a3a27daaa (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/fft.js')
-rw-r--r--tools/mq_editor/fft.js19
1 files changed, 6 insertions, 13 deletions
diff --git a/tools/mq_editor/fft.js b/tools/mq_editor/fft.js
index 36b9936..9b9bc94 100644
--- a/tools/mq_editor/fft.js
+++ b/tools/mq_editor/fft.js
@@ -109,7 +109,7 @@ class STFTCache {
this.sampleRate = sampleRate;
this.fftSize = fftSize;
this.hopSize = hopSize;
- this.frames = []; // Array of {time, offset, spectrum}
+ this.frames = []; // Array of {time, offset, squaredAmplitude}
this.compute();
}
@@ -131,18 +131,16 @@ class STFTCache {
windowed[i] = frame[i] * w;
}
- // Compute FFT
- const spectrum = realFFT(windowed);
-
- // Cache squared amplitudes (re*re + im*im, no sqrt)
+ // Compute FFT, store only squared amplitudes (re*re + im*im, no sqrt)
+ const fftOut = realFFT(windowed);
const squaredAmplitude = new Float32Array(this.fftSize / 2);
for (let i = 0; i < this.fftSize / 2; ++i) {
- const re = spectrum[i * 2];
- const im = spectrum[i * 2 + 1];
+ const re = fftOut[i * 2];
+ const im = fftOut[i * 2 + 1];
squaredAmplitude[i] = re * re + im * im;
}
- this.frames.push({time, offset, spectrum, squaredAmplitude});
+ this.frames.push({time, offset, squaredAmplitude});
}
}
@@ -175,11 +173,6 @@ class STFTCache {
return this.getFrameAtIndex(frameIdx);
}
- getFFT(t) {
- const frame = this.getFrameAtTime(t);
- return frame ? frame.spectrum : null;
- }
-
getSquaredAmplitude(t) {
const frame = this.getFrameAtTime(t);
return frame ? frame.squaredAmplitude : null;