diff options
Diffstat (limited to 'tools/mq_editor/fft.js')
| -rw-r--r-- | tools/mq_editor/fft.js | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/tools/mq_editor/fft.js b/tools/mq_editor/fft.js index 9b9bc94..10a5b45 100644 --- a/tools/mq_editor/fft.js +++ b/tools/mq_editor/fft.js @@ -115,6 +115,7 @@ class STFTCache { compute() { this.frames = []; + this.maxDB = -Infinity; const numFrames = Math.floor((this.signal.length - this.fftSize) / this.hopSize); for (let frameIdx = 0; frameIdx < numFrames; ++frameIdx) { @@ -138,10 +139,14 @@ class STFTCache { const re = fftOut[i * 2]; const im = fftOut[i * 2 + 1]; squaredAmplitude[i] = re * re + im * im; + const db = 10 * Math.log10(Math.max(squaredAmplitude[i], 1e-20)); + if (db > this.maxDB) this.maxDB = db; } this.frames.push({time, offset, squaredAmplitude}); } + + if (!isFinite(this.maxDB)) this.maxDB = 0; } setHopSize(hopSize) { |
