Skip to content

Commit

Permalink
New tests and revise tests for Octave scale
Browse files Browse the repository at this point in the history
Issue #332
  • Loading branch information
towsey committed Aug 13, 2020
1 parent 5908e27 commit 28832b5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/AudioAnalysisTools/StandardSpectrograms/BaseSonogram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,17 @@ public Image<Rgb24> GetImageFullyAnnotated(string title, Color? tag = null)
return image;
}

/// <summary>
/// This method fully annotates a short-time scale spectrogram.
/// The grid-lines are drawn according to indices in gridLineLocations.
/// Therefore the method will accept spectrograms with octave or any frequency scale.
/// The time scale is calculated from recording duration and width of image.
/// </summary>
/// <param name="image">The raw spectrogram image.</param>
/// <param name="title">To go on the title bar.</param>
/// <param name="gridLineLocations">A matrix of values.</param>
/// <param name="tag">Used to identify images??.</param>
/// <returns>The annotated spectrogram.</returns>
public Image<Rgb24> GetImageFullyAnnotated(Image<Rgb24> image, string title, int[,] gridLineLocations, Color? tag = null)
{
if (image == null)
Expand All @@ -248,6 +259,7 @@ public Image<Rgb24> GetImageFullyAnnotated(Image<Rgb24> image, string title, int

FrequencyScale.DrawFrequencyLinesOnImage(image, gridLineLocations, includeLabels: true);

// collect all the images and combine.
var titleBar = DrawTitleBarOfGrayScaleSpectrogram(title, image.Width, tag);
var timeBmp = ImageTrack.DrawTimeTrack(this.Duration, image.Width);
var list = new List<Image<Rgb24>> { titleBar, timeBmp, image, timeBmp };
Expand Down
40 changes: 36 additions & 4 deletions tests/Acoustics.Test/AudioAnalysisTools/DSP/FrequencyScaleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ public void TestMakeMelScaleSpectrogram()
}

/// <summary>
/// Test of the default standard split LINEAR-Octave FREQ SCALE
/// Check it on pure tone spectrum.
/// By default, the split between linear and octave is at 1000 Hz.
/// Test static method which returns bin index for a given frequency.
/// </summary>
[TestMethod]
public void TestAssignmentOfGridLinesForOctaveFrequencyScale()
Expand Down Expand Up @@ -323,6 +321,40 @@ public void TestAssignmentOfGridLinesForOctaveFrequencyScale()
Assert.That.MatricesAreEqual(expected, gridLineLocations);
}

/// <summary>
/// Test static method which returns bin index for a given frequency.
/// </summary>
[TestMethod]
public void TestReturnOfBinIndex()
{
var freqScale = new FrequencyScale(FreqScaleType.OctaveDataReduction);

// test contents of the octave bin bounds matrix.
int[,] octaveBinBounds = freqScale.BinBounds;

Assert.AreEqual(20, octaveBinBounds.GetLength(0));

int hertzValue = 500;
var binId = freqScale.GetBinIdForHerzValue(hertzValue);
Assert.AreEqual(2, binId);

hertzValue = 1000;
binId = freqScale.GetBinIdForHerzValue(hertzValue);
Assert.AreEqual(4, binId);

hertzValue = 2000;
binId = freqScale.GetBinIdForHerzValue(hertzValue);
Assert.AreEqual(7, binId);

hertzValue = 4000;
binId = freqScale.GetBinIdForHerzValue(hertzValue);
Assert.AreEqual(12, binId);

hertzValue = 8000;
binId = freqScale.GetBinIdForHerzValue(hertzValue);
Assert.AreEqual(17, binId);
}

/// <summary>
/// Test of the default standard split LINEAR-Octave FREQ SCALE
/// Check it on pure tone spectrum.
Expand Down Expand Up @@ -395,7 +427,7 @@ public void OctaveFrequencyScale1()

var recording = new AudioRecording(recordingPath);

var fst = FreqScaleType.OctaveCustom;
var fst = FreqScaleType.OctaveDataReduction;
int nyquist = recording.SampleRate / 2;
int frameSize = 16384;
int linearBound = 125;
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/Indices/BGN_OctaveScale.bin
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/Fixtures/Indices/CVR_OctaveScale.bin
Git LFS file not shown

0 comments on commit 28832b5

Please sign in to comment.