Skip to content

Commit

Permalink
Fixes broken oscillation tests
Browse files Browse the repository at this point in the history
Note to Michael: I susbstituted in a different spectrogram generation method because it was more flexible to input - paritcularly very short recordings.
  • Loading branch information
atruskie committed Dec 19, 2018
1 parent d09c82f commit d8f3b26
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ csharp_style_var_when_type_is_apparent = true:warning
csharp_style_var_elsewhere = true:warning
# Expression-bodied members
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#expression_bodied_members
csharp_style_expression_bodied_methods = true:warning
csharp_style_expression_bodied_constructors = true:warning
csharp_style_expression_bodied_methods = when_on_single_line:warning
csharp_style_expression_bodied_constructors = when_on_single_line:warning
csharp_style_expression_bodied_operators = true:warning
csharp_style_expression_bodied_properties = true:warning
csharp_style_expression_bodied_indexers = true:warning
Expand Down
4 changes: 3 additions & 1 deletion AudioAnalysis.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,6 @@
<s:Boolean x:Key="/Default/ReSpeller/UserDictionaries/=en_005Fus/Words/=appenders/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/ReSpeller/UserDictionaries/=en_005Fus/Words/=parallelized/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/ReSpeller/UserDictionaries/=en_005Fus/Words/=spectrums/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/ReSpeller/UserDictionaries/=en_005Fus/Words/=Truskinger/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/ReSpeller/UserDictionaries/=en_005Fus/Words/=Truskinger/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=spectrograms/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Submatrix/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
28 changes: 16 additions & 12 deletions src/AudioAnalysisTools/Oscillations2014.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ public static Dictionary<string, string> GetConfigDictionary(FileInfo configFile
public static double[,] GetSpectrogramMatrix(AudioRecording recordingSegment, int frameLength)
{
// set up the default songram config object
var sonoConfig = new SonogramConfig
{
WindowSize = frameLength,
WindowOverlap = 0.0,
};
// var sonoConfig = new SonogramConfig
// {
// WindowSize = frameLength,
// WindowOverlap = 0.0,
// };

BaseSonogram sonogram = new AmplitudeSonogram(sonoConfig, recordingSegment.WavReader);
// BaseSonogram sonogram = new AmplitudeSonogram(sonoConfig, recordingSegment.WavReader);

// Taking the decibel spectrogram also works
// BaseSonogram sonogram = new SpectrogramStandard(sonoConfig, recordingSegment.WavReader);
Expand All @@ -261,13 +261,17 @@ public static Dictionary<string, string> GetConfigDictionary(FileInfo configFile

// remove the DC bin if it has not already been removed.
// Assume test of divisible by 2 is good enough.
int binCount = sonogram.Data.GetLength(1);
if (!binCount.IsEven())
{
sonogram.Data = MatrixTools.Submatrix(sonogram.Data, 0, 1, sonogram.FrameCount - 1, binCount - 1);
}
// int binCount = sonogram.Data.GetLength(1);
// if (!binCount.IsEven())
// {
// sonogram.Data = MatrixTools.Submatrix(sonogram.Data, 0, 1, sonogram.FrameCount - 1, binCount - 1);
// }

// AT: Switched to below method of extracting the spectrogram because BaseSonogram
// does not allow small spectrograms (less than 0.2s) to calculated.

return sonogram.Data;
var fft = DSP_Frames.ExtractEnvelopeAndFfts(recordingSegment, frameLength, frameLength);
return fft.AmplitudeSpectrogram;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void TwoOscillationTests()

//TODO Following test fails when using CSV reader because the reader cuts out first line of the matrix
//var expectedMatrix = Csv.ReadMatrixFromCsv<double>(expectedMatrixFile);
CollectionAssert.AreEqual(expectedMatrix, tuple.Item2);
CollectionAssert.That.AreEqual(expectedMatrix, tuple.Item2, 0.000001);
}
}

Expand Down Expand Up @@ -160,7 +160,7 @@ public void SpectralIndexOsc_Test()
// TODO this test fails when using CSV reader because the reader cuts out first element/line of the vector
//var expectedVector = (double[])Csv.ReadFromCsv<double>(expectedIndexPath);
var expectedVector = Binary.Deserialize<double[]>(expectedIndexPath);
CollectionAssert.AreEqual(expectedVector, spectralIndex);
CollectionAssert.That.AreEqual(expectedVector, spectralIndex, 0.000001);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Acoustics.Test/TestHelpers/Assertions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="Assertions.cs" company="QutEcoacoustics">
// <copyright file="Assertions.cs" company="QutEcoacoustics">
// All code in this file and all associated files are the copyright and property of the QUT Ecoacoustics Research Group (formerly MQUTeR, and formerly QUT Bioacoustics Research Group).
// </copyright>

Expand Down

0 comments on commit d8f3b26

Please sign in to comment.