From 828347fc0b6a4c623f701945cd1d6cb8df22a42e Mon Sep 17 00:00:00 2001 From: towsey Date: Sat, 24 Oct 2020 15:29:35 +1100 Subject: [PATCH] Shift some classes into new folder structure Issue #390 Moved some classes into separate folders, according to their functionality. --- .../{ => Events}/BlobParameters.cs | 0 .../Events/Types/BlobEvent.cs | 59 +++++++++---------- .../{ => Harmonics}/HarmonicAnalysis.cs | 0 .../{ => Harmonics}/HarmonicParameters.cs | 44 ++++++-------- .../{ => Indices}/SpectralCentroid.cs | 0 .../{ => Tracks}/RidgeDetection.cs | 0 .../{ => Tracks}/SpectralPeakTracking2018.cs | 0 .../{ => Tracks}/SpectralPeakTracks.cs | 0 8 files changed, 47 insertions(+), 56 deletions(-) rename src/AudioAnalysisTools/{ => Events}/BlobParameters.cs (100%) rename src/AudioAnalysisTools/{ => Harmonics}/HarmonicAnalysis.cs (100%) rename src/AudioAnalysisTools/{ => Harmonics}/HarmonicParameters.cs (79%) rename src/AudioAnalysisTools/{ => Indices}/SpectralCentroid.cs (100%) rename src/AudioAnalysisTools/{ => Tracks}/RidgeDetection.cs (100%) rename src/AudioAnalysisTools/{ => Tracks}/SpectralPeakTracking2018.cs (100%) rename src/AudioAnalysisTools/{ => Tracks}/SpectralPeakTracks.cs (100%) diff --git a/src/AudioAnalysisTools/BlobParameters.cs b/src/AudioAnalysisTools/Events/BlobParameters.cs similarity index 100% rename from src/AudioAnalysisTools/BlobParameters.cs rename to src/AudioAnalysisTools/Events/BlobParameters.cs diff --git a/src/AudioAnalysisTools/Events/Types/BlobEvent.cs b/src/AudioAnalysisTools/Events/Types/BlobEvent.cs index 69c0d3889..6dd0e7fca 100644 --- a/src/AudioAnalysisTools/Events/Types/BlobEvent.cs +++ b/src/AudioAnalysisTools/Events/Types/BlobEvent.cs @@ -30,46 +30,43 @@ public BlobEvent() public static (List Events, List DecibelPlots) GetBlobEvents( SpectrogramStandard spectrogram, BlobParameters bp, + double? decibelThreshold, TimeSpan segmentStartOffset, string profileName) { - var decibelThresholds = bp.DecibelThresholds; var spectralEvents = new List(); var plots = new List(); - foreach (var threshold in decibelThresholds) - { - //get the array of intensity values minus intensity in side/buffer bands. - //i.e. require silence in side-bands. Otherwise might simply be getting part of a broader band acoustic event. - var decibelArray = SNR.CalculateFreqBandAvIntensityMinusBufferIntensity( - spectrogram.Data, - bp.MinHertz.Value, - bp.MaxHertz.Value, - bp.BottomHertzBuffer.Value, - bp.TopHertzBuffer.Value, - spectrogram.NyquistFrequency); + //get the array of intensity values minus intensity in side/buffer bands. + //i.e. require silence in side-bands. Otherwise might simply be getting part of a broader band acoustic event. + var decibelArray = SNR.CalculateFreqBandAvIntensityMinusBufferIntensity( + spectrogram.Data, + bp.MinHertz.Value, + bp.MaxHertz.Value, + bp.BottomHertzBuffer.Value, + bp.TopHertzBuffer.Value, + spectrogram.NyquistFrequency); - // prepare plot of resultant blob decibel array. - var plot = Plot.PreparePlot(decibelArray, $"{profileName} (Blobs:{threshold.Value:F0}dB)", threshold.Value); - plots.Add(plot); + // prepare plot of resultant blob decibel array. + var plot = Plot.PreparePlot(decibelArray, $"{profileName} (Blobs:{decibelThreshold.Value:F0}dB)", decibelThreshold.Value); + plots.Add(plot); - // iii: CONVERT blob decibel SCORES TO ACOUSTIC EVENTS. - // Note: This method does NOT do prior smoothing of the dB array. - var acEvents = AcousticEvent.GetEventsAroundMaxima( - decibelArray, - segmentStartOffset, - bp.MinHertz.Value, - bp.MaxHertz.Value, - threshold.Value, - TimeSpan.FromSeconds(bp.MinDuration.Value), - TimeSpan.FromSeconds(bp.MaxDuration.Value), - spectrogram.FramesPerSecond, - spectrogram.FBinWidth); + // iii: CONVERT blob decibel SCORES TO ACOUSTIC EVENTS. + // Note: This method does NOT do prior smoothing of the dB array. + var acEvents = AcousticEvent.GetEventsAroundMaxima( + decibelArray, + segmentStartOffset, + bp.MinHertz.Value, + bp.MaxHertz.Value, + decibelThreshold.Value, + TimeSpan.FromSeconds(bp.MinDuration.Value), + TimeSpan.FromSeconds(bp.MaxDuration.Value), + spectrogram.FramesPerSecond, + spectrogram.FBinWidth); - var events = acEvents.ConvertAcousticEventsToSpectralEvents(); - spectralEvents.AddRange(events); - plots.Add(plot); - } + var events = acEvents.ConvertAcousticEventsToSpectralEvents(); + spectralEvents.AddRange(events); + plots.Add(plot); return (spectralEvents, plots); } diff --git a/src/AudioAnalysisTools/HarmonicAnalysis.cs b/src/AudioAnalysisTools/Harmonics/HarmonicAnalysis.cs similarity index 100% rename from src/AudioAnalysisTools/HarmonicAnalysis.cs rename to src/AudioAnalysisTools/Harmonics/HarmonicAnalysis.cs diff --git a/src/AudioAnalysisTools/HarmonicParameters.cs b/src/AudioAnalysisTools/Harmonics/HarmonicParameters.cs similarity index 79% rename from src/AudioAnalysisTools/HarmonicParameters.cs rename to src/AudioAnalysisTools/Harmonics/HarmonicParameters.cs index e64665735..9c17d59ec 100644 --- a/src/AudioAnalysisTools/HarmonicParameters.cs +++ b/src/AudioAnalysisTools/Harmonics/HarmonicParameters.cs @@ -38,37 +38,31 @@ public class HarmonicParameters : CommonParameters public static (List SpectralEvents, List DecibelPlots) GetComponentsWithHarmonics( SpectrogramStandard spectrogram, HarmonicParameters hp, + double? decibelThreshold, TimeSpan segmentStartOffset, string profileName) { - // get the array of decibel thresholds - var thresholdArray = hp.DecibelThresholds; - var spectralEvents = new List(); var plots = new List(); - // loop through the array of decibel thresholds - foreach (var threshold in thresholdArray) - { - double[] decibelMaxArray; - double[] harmonicIntensityScores; - (spectralEvents, decibelMaxArray, harmonicIntensityScores) = HarmonicParameters.GetComponentsWithHarmonics( - spectrogram, - hp.MinHertz.Value, - hp.MaxHertz.Value, - spectrogram.NyquistFrequency, - threshold.Value, - hp.DctThreshold.Value, - hp.MinDuration.Value, - hp.MaxDuration.Value, - hp.MinFormantGap.Value, - hp.MaxFormantGap.Value, - segmentStartOffset); - - // prepare plot of resultant Harmonics decibel array. - var plot = Plot.PreparePlot(decibelMaxArray, $"{profileName} (Harmonics:{threshold:F0}db)", threshold.Value); - plots.Add(plot); - } + double[] decibelMaxArray; + double[] harmonicIntensityScores; + (spectralEvents, decibelMaxArray, harmonicIntensityScores) = HarmonicParameters.GetComponentsWithHarmonics( + spectrogram, + hp.MinHertz.Value, + hp.MaxHertz.Value, + spectrogram.NyquistFrequency, + decibelThreshold.Value, + hp.DctThreshold.Value, + hp.MinDuration.Value, + hp.MaxDuration.Value, + hp.MinFormantGap.Value, + hp.MaxFormantGap.Value, + segmentStartOffset); + + // prepare plot of resultant Harmonics decibel array. + var plot = Plot.PreparePlot(decibelMaxArray, $"{profileName} (Harmonics:{decibelThreshold:F0}db)", decibelThreshold.Value); + plots.Add(plot); return (spectralEvents, plots); } diff --git a/src/AudioAnalysisTools/SpectralCentroid.cs b/src/AudioAnalysisTools/Indices/SpectralCentroid.cs similarity index 100% rename from src/AudioAnalysisTools/SpectralCentroid.cs rename to src/AudioAnalysisTools/Indices/SpectralCentroid.cs diff --git a/src/AudioAnalysisTools/RidgeDetection.cs b/src/AudioAnalysisTools/Tracks/RidgeDetection.cs similarity index 100% rename from src/AudioAnalysisTools/RidgeDetection.cs rename to src/AudioAnalysisTools/Tracks/RidgeDetection.cs diff --git a/src/AudioAnalysisTools/SpectralPeakTracking2018.cs b/src/AudioAnalysisTools/Tracks/SpectralPeakTracking2018.cs similarity index 100% rename from src/AudioAnalysisTools/SpectralPeakTracking2018.cs rename to src/AudioAnalysisTools/Tracks/SpectralPeakTracking2018.cs diff --git a/src/AudioAnalysisTools/SpectralPeakTracks.cs b/src/AudioAnalysisTools/Tracks/SpectralPeakTracks.cs similarity index 100% rename from src/AudioAnalysisTools/SpectralPeakTracks.cs rename to src/AudioAnalysisTools/Tracks/SpectralPeakTracks.cs