Skip to content

Commit

Permalink
Finished response to requests from Anthony
Browse files Browse the repository at this point in the history
Issue #238 Only unit tests to be done.
  • Loading branch information
towsey committed Aug 29, 2019
1 parent 877703f commit 1d1c552
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 40 deletions.
50 changes: 12 additions & 38 deletions src/AnalysisPrograms/Recognizers/PteropusSpecies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public override RecognizerResults Recognize(AudioRecording audioRecording, Confi
log.Warn("No configuration profiles found. Two profiles expected for the Flying Fox recogniser.");
}

RecognizerResults territorialResults = null;
var territorialResults = new RecognizerResults();

if (ConfigFile.TryGetProfile(genericConfig, "Territorial", out var profile1))
{
Expand All @@ -121,7 +121,7 @@ public override RecognizerResults Recognize(AudioRecording audioRecording, Confi
log.Warn("Could not access Territorial configuration parameters");
}

RecognizerResults wingbeatResults = null;
var wingbeatResults = new RecognizerResults();
if (ConfigFile.TryGetProfile(genericConfig, "Wingbeats", out var profile2))
{
wingbeatResults = WingBeats(audioRecording, genericConfig, "Wingbeats", segmentStartOffset);
Expand All @@ -133,13 +133,9 @@ public override RecognizerResults Recognize(AudioRecording audioRecording, Confi
}

// combine the results i.e. add wing-beat events to the list of territorial call events.

// results1.Events.Concat(results2.Events.Concat)
if (territorialResults != null && wingbeatResults != null)
{
territorialResults.Events.AddRange(wingbeatResults.Events);
territorialResults.Plots.AddRange(wingbeatResults.Plots);
}
//NOTE: The returned territorialResults and wingbeatResults will never be null.
territorialResults.Events.AddRange(wingbeatResults.Events);
territorialResults.Plots.AddRange(wingbeatResults.Plots);

//UNCOMMENT following line if you want special debug spectrogram, i.e. with special plots.
// NOTE: Standard spectrograms are produced by setting SaveSonogramImages: "True" or "WhenEventsDetected" in <Towsey.PteropusSpecies.yml> config file.
Expand Down Expand Up @@ -171,7 +167,6 @@ private static RecognizerResults TerritorialCall(AudioRecording audioRecording,
double minDurationSeconds = profile.GetDoubleOrNull(AnalysisKeys.MinDuration) ?? 0.15;
double maxDurationSeconds = profile.GetDoubleOrNull(AnalysisKeys.MaxDuration) ?? 0.5;
double decibelThreshold = profile.GetDoubleOrNull(AnalysisKeys.DecibelThreshold) ?? 9.0;

var minTimeSpan = TimeSpan.FromSeconds(minDurationSeconds);
var maxTimeSpan = TimeSpan.FromSeconds(maxDurationSeconds);

Expand Down Expand Up @@ -304,14 +299,13 @@ private static List<AcousticEvent> FilterEventsForSpectralProfile(List<AcousticE
{
filteredEvents.Add(ae);

// draw DEBUG IMAGES
if (true)
{
double startSecond = ae.EventStartSeconds - ae.SegmentStartSeconds;
string name = "CallSpectrum " + (ae.SegmentStartSeconds / 60) + "m" + (int)Math.Floor(startSecond) + "s hzMax" + hzMax;
var bmp2 = GraphsAndCharts.DrawGraph(name, normalisedSpectrum, 100);
bmp2.Save(Path.Combine(@"C:\Ecoacoustics\Output\BradLaw\FlyingFox\Towsey.PteropusSpecies", name + ".png"));
}
//DEBUG SPECTRAL PROFILES: UNCOMMENT following lines to get spectral profiles of the events.
/*
double startSecond = ae.EventStartSeconds - ae.SegmentStartSeconds;
string name = "CallSpectrum " + (ae.SegmentStartSeconds / 60) + "m" + (int)Math.Floor(startSecond) + "s hzMax" + hzMax;
var bmp2 = GraphsAndCharts.DrawGraph(name, normalisedSpectrum, 100);
bmp2.Save(Path.Combine(@"PATH\Towsey.PteropusSpecies", name + ".png"));
*/
}
}

Expand Down Expand Up @@ -351,26 +345,6 @@ private static RecognizerResults WingBeats(AudioRecording audioRecording, Config
//var samples = audioRecording.WavReader.Samples;
//Instead, convert each segment to a spectrogram.
var sonogram = GetSonogram(configuration, audioRecording);
/*
//2.Convert each segment to a spectrogram. Don't use samples in this recogniser.
//var samples = audioRecording.WavReader.Samples;
// make a spectrogram
var sonoConfig = new SonogramConfig
{
WindowSize = 512,
NoiseReductionType = NoiseReductionType.Standard,
NoiseReductionParameter = configuration.GetDoubleOrNull(AnalysisKeys.NoiseBgThreshold) ?? 0.0,
};
sonoConfig.WindowOverlap = 0.0;
// now construct the standard decibel spectrogram WITH noise removal, and look for LimConvex
// get frame parameters for the analysis
var sonogram = (BaseSonogram)new SpectrogramStandard(sonoConfig, audioRecording.WavReader);
*/

var decibelArray = SNR.CalculateFreqBandAvIntensity(sonogram.Data, minHz, maxHz, sonogram.NyquistFrequency);

// Look for wing beats using oscillation detector
Expand Down
4 changes: 2 additions & 2 deletions src/AnalysisPrograms/Sandpit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ public static void Audio2CsvOverOneFile()

// FLYING FOX RECORDINGS
//string recordingPath = @"C:\Ecoacoustics\WavFiles\BradLawData\FlyingFox\20190127_Bellingen_Feeding_SM4.wav";
//string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190115_Bellingen_Feeding.wav";
string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190115_Bellingen_Feeding.wav";
//string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190121_2_Bellingen_Feeding.wav";
string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190127_Bellingen_Feeding_SM4.wav";
//string recordingPath = @"C:\Ecoacoustics\WavFiles\FlyingFox\20190127_Bellingen_Feeding_SM4.wav";
string configPath = @"C:\Work\GitHub\audio-analysis\src\AnalysisConfigFiles\RecognizerConfigFiles\Towsey.PteropusSpecies.yml";
string outputPath = @"C:\Ecoacoustics\Output\BradLaw\FlyingFox";

Expand Down

0 comments on commit 1d1c552

Please sign in to comment.