Skip to content

Commit

Permalink
Fix spectrogram gain
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Pyke committed Dec 21, 2024
1 parent 8368928 commit 4aa64a7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/plugins/spectrogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ class SpectrogramPlugin extends BasePlugin<SpectrogramPluginEvents, SpectrogramP
this.frequencyMin = options.frequencyMin || 0
this.frequencyMax = options.frequencyMax || 0

this.gainDB = options.gainDB || 20
this.rangeDB = options.rangeDB || 80
this.gainDB = options.gainDB ?? 20
this.rangeDB = options.rangeDB ?? 80
this.scale = options.scale || 'mel'
this.numMelFilters = options.numMelFilters || this.fftSamples / 8
if (this.scale == 'mel') {
Expand Down Expand Up @@ -602,7 +602,7 @@ class SpectrogramPlugin extends BasePlugin<SpectrogramPluginEvents, SpectrogramP
for (let j = 0; j < fftSamples / 2; j++) {
// Based on: https://manual.audacityteam.org/man/spectrogram_view.html
let valueDB = 20 * Math.log10(spectrum[j])
if (valueDB < -this.rangeDB) {
if (valueDB < -this.gainDB - this.rangeDB) {
array[j] = 0
} else if (valueDB > -this.gainDB) {
array[j] = 255
Expand Down

0 comments on commit 4aa64a7

Please sign in to comment.