Skip to content

Commit

Permalink
Fix generation of additional spectrogram types.
Browse files Browse the repository at this point in the history
Issue #332
  • Loading branch information
towsey committed Aug 17, 2020
1 parent 2a8c3e2 commit adcab04
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ static SpectrogramGenerator()
/// Waveform.
/// DecibelSpectrogram.
/// DecibelSpectrogramNoiseReduced.
/// MelScaleSpectrogram
/// CepstralSpectrogram.
/// OctaveScaleSpectrogram
/// DifferenceSpectrogram.
/// AmplitudeSpectrogramLocalContrastNormalization.
/// Experimental.
Expand Down
7 changes: 4 additions & 3 deletions src/AudioAnalysisTools/StandardSpectrograms/BaseSonogram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ private void InitialiseSpectrogram(WavReader wav)
this.Configuration.SampleRate = wav.SampleRate; //also set the Nyquist
this.MaxAmplitude = wav.CalculateMaximumAmplitude();

//init normalised signal energy array but do nothing with it. This has to be done from outside
this.DecibelsNormalised = new double[this.FrameCount];

var recording = new AudioRecording(wav);
var fftData = DSP_Frames.ExtractEnvelopeAndFfts(
recording,
Expand All @@ -190,6 +187,10 @@ private void InitialiseSpectrogram(WavReader wav)
this.Configuration.WindowPower = fftData.WindowPower;
this.FrameCount = fftData.FrameCount;
this.DecibelsPerFrame = fftData.FrameDecibels;

//init normalised signal energy array but do nothing with it. This has to be done from outside
this.DecibelsNormalised = new double[this.FrameCount];

this.Data = fftData.AmplitudeSpectrogram;

// currently DoSnr = true by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ namespace Acoustics.Test.AnalysisPrograms.SpectrogramGenerator
[TestClass]
public class SpectrogramGeneratorTests : GeneratedImageTest<Rgb24>
{
// There are currently eight spectrogram types plus the waveform.
private const int Width = 1096;
private const int Waveform = 154;
private const int Spectrogram = 310;
private const int SpectrogramNoiseRemoved = 310;
private const int SpectrogramExperimental = 310;
private const int SpectrogramDifference = 310;
private const int SpectrogramMel = 118;
private const int Cepstral = 67;
private const int SpectrogramOctave = 157;
private const int SpectrogramAmplitude = 310;

private static readonly Dictionary<SpectrogramImageType, int> All = new Dictionary<SpectrogramImageType, int>()
Expand All @@ -36,7 +39,9 @@ public class SpectrogramGeneratorTests : GeneratedImageTest<Rgb24>
{ SpectrogramImageType.DecibelSpectrogramNoiseReduced, SpectrogramNoiseRemoved },
{ SpectrogramImageType.Experimental, SpectrogramExperimental },
{ SpectrogramImageType.DifferenceSpectrogram, SpectrogramDifference },
{ SpectrogramImageType.MelScaleSpectrogram, SpectrogramMel },
{ SpectrogramImageType.CepstralSpectrogram, Cepstral },
{ SpectrogramImageType.OctaveScaleSpectrogram, SpectrogramOctave },
{ SpectrogramImageType.AmplitudeSpectrogramLocalContrastNormalization, SpectrogramAmplitude },
};

Expand Down Expand Up @@ -111,7 +116,7 @@ public void TestAudio2SonogramCombinations(SpectrogramImageType[] images)

// get expected height
var expectedHeight = images.Select(imageType => All[imageType]).Sum();
Assert.That.ImageIsSize(OneSecondWidth, expectedHeight, result.CompositeImage);
Assert.That.ImageIsSize(OneSecondWidth, expectedHeight, this.ActualImage);

// ensure images are in correct order
int y = 0;
Expand Down

0 comments on commit adcab04

Please sign in to comment.