From f3eb3ed8e09b6c09850bc40f5bafce989a5f1b93 Mon Sep 17 00:00:00 2001 From: towsey Date: Tue, 11 Aug 2020 17:19:51 +1000 Subject: [PATCH] Fix production of Octave scale spectrogram Issue #332 --- .../BaseSonogramConfig.cs | 5 +++ .../SpectrogramOctaveScale.cs | 33 ++----------------- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/AudioAnalysisTools/StandardSpectrograms/BaseSonogramConfig.cs b/src/AudioAnalysisTools/StandardSpectrograms/BaseSonogramConfig.cs index 38905c0f4..749482dbd 100644 --- a/src/AudioAnalysisTools/StandardSpectrograms/BaseSonogramConfig.cs +++ b/src/AudioAnalysisTools/StandardSpectrograms/BaseSonogramConfig.cs @@ -357,5 +357,10 @@ public double GetFrameOffset(int sampleRate) int step = DSP_Frames.FrameStep(this.WindowSize, this.WindowOverlap); return step / (double)sampleRate; } + + public static double CalculateFrameOverlap(int frameWidth, int frameStep) + { + return 1 - (frameStep / (double)frameWidth); + } } } \ No newline at end of file diff --git a/src/AudioAnalysisTools/StandardSpectrograms/SpectrogramOctaveScale.cs b/src/AudioAnalysisTools/StandardSpectrograms/SpectrogramOctaveScale.cs index 8af62a5f0..cb5064040 100644 --- a/src/AudioAnalysisTools/StandardSpectrograms/SpectrogramOctaveScale.cs +++ b/src/AudioAnalysisTools/StandardSpectrograms/SpectrogramOctaveScale.cs @@ -12,45 +12,18 @@ namespace AudioAnalysisTools.StandardSpectrograms public class SpectrogramOctaveScale : BaseSonogram { - public SpectrogramOctaveScale(string configFile, WavReader wav) - : this(SonogramConfig.Load(configFile), wav) + public SpectrogramOctaveScale(SonogramConfig config, FrequencyScale scale, WavReader wav) + : base(config, scale, wav) { } - public SpectrogramOctaveScale(SonogramConfig config, WavReader wav) - : base(config, wav) - { - } - - public SpectrogramOctaveScale(AmplitudeSonogram sg) - : base(sg.Configuration) - { - this.Configuration = sg.Configuration; - this.DecibelsPerFrame = sg.DecibelsPerFrame; - this.DecibelsNormalised = sg.DecibelsNormalised; - this.Duration = sg.Duration; - this.FrameCount = sg.FrameCount; - this.DecibelReference = sg.DecibelReference; - this.MaxAmplitude = sg.MaxAmplitude; - this.SampleRate = sg.SampleRate; - this.SigState = sg.SigState; - this.SnrData = sg.SnrData; - this.Make(sg.Data); - } - /// /// Converts amplitude matrix to octave frequency scale spectrogram. - /// ########################################################################TODO TODO need to init as AmplitudeSpectrogram and then use constructor at Line 25. /// /// Matrix of amplitude values. public override void Make(double[,] amplitudeM) { - //var freqScale = new FrequencyScale(FreqScaleType.LinearOctaveStandard); - //var freqScale = new FrequencyScale(FreqScaleType.OctaveDataReduction); - var freqScale = new FrequencyScale(FreqScaleType.Linear125OctaveTones32Nyquist11025); - //var freqScale = new FrequencyScale(FreqScaleType.Linear62OctaveTones31Nyquist11025); - - double[,] m = OctaveFreqScale.ConvertAmplitudeSpectrogramToDecibelOctaveScale(amplitudeM, freqScale); + double[,] m = OctaveFreqScale.ConvertAmplitudeSpectrogramToDecibelOctaveScale(amplitudeM, this.FreqScale); // Do noise reduction var tuple = SNR.NoiseReduce(m, this.Configuration.NoiseReductionType, this.Configuration.NoiseReductionParameter);