From 28832b52af37a6a08c2926b2c98368654e5b5645 Mon Sep 17 00:00:00 2001 From: towsey Date: Thu, 13 Aug 2020 17:33:48 +1000 Subject: [PATCH] New tests and revise tests for Octave scale Issue #332 --- .../StandardSpectrograms/BaseSonogram.cs | 12 ++++++ .../DSP/FrequencyScaleTests.cs | 40 +++++++++++++++++-- tests/Fixtures/Indices/BGN_OctaveScale.bin | 4 +- tests/Fixtures/Indices/CVR_OctaveScale.bin | 4 +- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/AudioAnalysisTools/StandardSpectrograms/BaseSonogram.cs b/src/AudioAnalysisTools/StandardSpectrograms/BaseSonogram.cs index a1071b7e7..1692537ae 100644 --- a/src/AudioAnalysisTools/StandardSpectrograms/BaseSonogram.cs +++ b/src/AudioAnalysisTools/StandardSpectrograms/BaseSonogram.cs @@ -239,6 +239,17 @@ public Image GetImageFullyAnnotated(string title, Color? tag = null) return image; } + /// + /// 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. + /// + /// The raw spectrogram image. + /// To go on the title bar. + /// A matrix of values. + /// Used to identify images??. + /// The annotated spectrogram. public Image GetImageFullyAnnotated(Image image, string title, int[,] gridLineLocations, Color? tag = null) { if (image == null) @@ -248,6 +259,7 @@ public Image GetImageFullyAnnotated(Image 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> { titleBar, timeBmp, image, timeBmp }; diff --git a/tests/Acoustics.Test/AudioAnalysisTools/DSP/FrequencyScaleTests.cs b/tests/Acoustics.Test/AudioAnalysisTools/DSP/FrequencyScaleTests.cs index cdf85909f..07df57c73 100644 --- a/tests/Acoustics.Test/AudioAnalysisTools/DSP/FrequencyScaleTests.cs +++ b/tests/Acoustics.Test/AudioAnalysisTools/DSP/FrequencyScaleTests.cs @@ -270,9 +270,7 @@ public void TestMakeMelScaleSpectrogram() } /// - /// 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. /// [TestMethod] public void TestAssignmentOfGridLinesForOctaveFrequencyScale() @@ -323,6 +321,40 @@ public void TestAssignmentOfGridLinesForOctaveFrequencyScale() Assert.That.MatricesAreEqual(expected, gridLineLocations); } + /// + /// Test static method which returns bin index for a given frequency. + /// + [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); + } + /// /// Test of the default standard split LINEAR-Octave FREQ SCALE /// Check it on pure tone spectrum. @@ -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; diff --git a/tests/Fixtures/Indices/BGN_OctaveScale.bin b/tests/Fixtures/Indices/BGN_OctaveScale.bin index a3cca5db4..21164a976 100644 --- a/tests/Fixtures/Indices/BGN_OctaveScale.bin +++ b/tests/Fixtures/Indices/BGN_OctaveScale.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:528021ef3170acf932de1b953e302787c0b7cab7e6957b059eee875655d27202 -size 2076 +oid sha256:9c1b61f7a575832ccd224a03414c46f1d6100936d9a639d8260e229127cc278e +size 188 diff --git a/tests/Fixtures/Indices/CVR_OctaveScale.bin b/tests/Fixtures/Indices/CVR_OctaveScale.bin index defb981f1..b3f5a20fe 100644 --- a/tests/Fixtures/Indices/CVR_OctaveScale.bin +++ b/tests/Fixtures/Indices/CVR_OctaveScale.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8f1b637e5bce179219068eaae31f5e3db6af24dbd0e2c91d6a43e9c41acd3629 -size 2076 +oid sha256:690d679c79b7f07df7f7dea89d79249041928512a21b32de4e08140792cdb494 +size 188