summaryrefslogtreecommitdiff
path: root/tools/mq_editor/fft.js
diff options
context:
space:
mode:
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;