Skip to content

Commit

Permalink
Enable Oscillation recognizer to utilize an array of decibel thresholds
Browse files Browse the repository at this point in the history
Issue #370 Part of ongoing refactoring to allow all recognizers to work with an array of decibel thresholds.
  • Loading branch information
towsey authored and atruskie committed Oct 14, 2020
1 parent 24cdc16 commit 5958a59
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/AnalysisPrograms/Recognizers/GenericRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,27 +255,14 @@ public override RecognizerResults Recognize(
}
else if (profileConfig is OscillationParameters op)
{
Oscillations2012.Execute(
List<Plot> 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<EventCommon>(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
{
Expand Down
43 changes: 43 additions & 0 deletions src/AudioAnalysisTools/Ocillations/Oscillations2012.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +23,47 @@ namespace AudioAnalysisTools
/// </summary>
public static class Oscillations2012
{
public static (List<EventCommon> SpectralEvents, List<Plot> DecibelPlots) GetComponentsWithOscillations(
SpectrogramStandard spectrogram,
OscillationParameters op,
TimeSpan segmentStartOffset,
string profileName)
{
// get the array of decibel thresholds
var thresholdArray = op.DecibelThresholds;

var spectralEvents = new List<EventCommon>();
var plots = new List<Plot>();

// 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,
Expand Down

0 comments on commit 5958a59

Please sign in to comment.