From 5958a59630b7126a00f35035888ce50a377f9bf9 Mon Sep 17 00:00:00 2001 From: towsey Date: Thu, 24 Sep 2020 11:21:59 +1000 Subject: [PATCH] Enable Oscillation recognizer to utilize an array of decibel thresholds Issue #370 Part of ongoing refactoring to allow all recognizers to work with an array of decibel thresholds. --- .../Recognizers/GenericRecognizer.cs | 27 +++--------- .../Ocillations/Oscillations2012.cs | 43 +++++++++++++++++++ 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs b/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs index a453a14d2..d38824754 100644 --- a/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs +++ b/src/AnalysisPrograms/Recognizers/GenericRecognizer.cs @@ -255,27 +255,14 @@ public override RecognizerResults Recognize( } else if (profileConfig is OscillationParameters op) { - Oscillations2012.Execute( + List decibelPlots; + (spectralEvents, decibelPlots) = Oscillations2012.GetComponentsWithOscillations( spectrogram, - op.MinHertz.Value, - op.MaxHertz.Value, - op.DctDuration, - op.MinOscillationFrequency, - op.MaxOscillationFrequency, - op.DctThreshold, - op.EventThreshold, - op.MinDuration.Value, - op.MaxDuration.Value, - out var scores, - out var oscillationEvents, - out var hits, - segmentStartOffset); - - spectralEvents = new List(oscillationEvents); - - //plots.Add(new Plot($"{profileName} (:OscillationScore)", scores, op.EventThreshold)); - var plot = Plot.PreparePlot(scores, $"{profileName} (:OscillationScore)", op.EventThreshold); - plots.Add(plot); + op, + segmentStartOffset, + profileName); + + plots.AddRange(decibelPlots); } else { diff --git a/src/AudioAnalysisTools/Ocillations/Oscillations2012.cs b/src/AudioAnalysisTools/Ocillations/Oscillations2012.cs index 3a126ef0d..3ed499d02 100644 --- a/src/AudioAnalysisTools/Ocillations/Oscillations2012.cs +++ b/src/AudioAnalysisTools/Ocillations/Oscillations2012.cs @@ -6,6 +6,8 @@ namespace AudioAnalysisTools { using System; using System.Collections.Generic; + using System.Reflection.Metadata.Ecma335; + using AnalysisPrograms.Recognizers.Base; using AudioAnalysisTools.DSP; using AudioAnalysisTools.Events; using AudioAnalysisTools.StandardSpectrograms; @@ -21,6 +23,47 @@ namespace AudioAnalysisTools /// public static class Oscillations2012 { + public static (List SpectralEvents, List DecibelPlots) GetComponentsWithOscillations( + SpectrogramStandard spectrogram, + OscillationParameters op, + TimeSpan segmentStartOffset, + string profileName) + { + // get the array of decibel thresholds + var thresholdArray = op.DecibelThresholds; + + var spectralEvents = new List(); + var plots = new List(); + + // loop through the array of decibel thresholds + foreach (var threshold in thresholdArray) + { + Oscillations2012.Execute( + spectrogram, + op.MinHertz.Value, + op.MaxHertz.Value, + op.DctDuration, + op.MinOscillationFrequency, + op.MaxOscillationFrequency, + op.DctThreshold, + op.EventThreshold, + op.MinDuration.Value, + op.MaxDuration.Value, + out var scores, + out var oscillationEvents, + out var hits, + segmentStartOffset); + + spectralEvents.AddRange(oscillationEvents); + + // prepare plot of resultant Harmonics decibel array. + var plot = Plot.PreparePlot(scores, $"{profileName} (Oscillations:{threshold:d0}db)", threshold.Value); + plots.Add(plot); + } + + return (spectralEvents, plots); + } + public static void Execute( SpectrogramStandard sonogram, int minHz,