Skip to content

Commit

Permalink
FUrther changes of method and class names
Browse files Browse the repository at this point in the history
  • Loading branch information
towsey committed Apr 20, 2020
1 parent 3f0e9c6 commit 15cebf9
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 80 deletions.
113 changes: 56 additions & 57 deletions src/AnalysisPrograms/Recognizers/GenericRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public override AnalyzerConfig ParseConfig(FileInfo file)
case OscillationParameters _:
algorithmName = "Oscillation";
break;
case WhistleParameters _:
case OnebinTrackParameters _:
algorithmName = "Whistle";
break;
case HarmonicParameters _:
Expand All @@ -80,7 +80,7 @@ public override AnalyzerConfig ParseConfig(FileInfo file)
case UpwardTrackParameters _:
algorithmName = "VerticalTrack";
break;
case ClickParameters _:
case OneframeTrackParameters _:
algorithmName = "Click";
break;
case Aed.AedConfiguration _:
Expand All @@ -91,11 +91,11 @@ public override AnalyzerConfig ParseConfig(FileInfo file)
var allowedAlgorithms =
$"{nameof(BlobParameters)}," +
$"{nameof(OscillationParameters)}," +
$"{nameof(WhistleParameters)}," +
$"{nameof(OnebinTrackParameters)}," +
$"{nameof(HarmonicParameters)}," +
$"{nameof(FowardTrackParameters)}," +
$"{nameof(UpwardTrackParameters)}," +
$"{nameof(ClickParameters)}," +
$"{nameof(OneframeTrackParameters)}," +
$"{nameof(Aed.AedConfiguration)}";
throw new ConfigFileException($"The algorithm type in profile {profileName} is not recognized. It must be one of {allowedAlgorithms}");
}
Expand Down Expand Up @@ -148,37 +148,15 @@ public override RecognizerResults Recognize(
{
if (profileConfig is BlobParameters
|| profileConfig is OscillationParameters
|| profileConfig is WhistleParameters
|| profileConfig is OnebinTrackParameters
|| profileConfig is HarmonicParameters
|| profileConfig is FowardTrackParameters
|| profileConfig is UpwardTrackParameters
|| profileConfig is ClickParameters)
|| profileConfig is OneframeTrackParameters)
{
sonogram = new SpectrogramStandard(ParametersToSonogramConfig(parameters), audioRecording.WavReader);

if (profileConfig is OscillationParameters op)
{
Oscillations2012.Execute(
sonogram,
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 acousticEvents,
out var hits,
segmentStartOffset);

//plots.Add(new Plot($"{profileName} (:OscillationScore)", scores, op.EventThreshold));
var plot = PreparePlot(scores, $"{profileName} (:OscillationScore)", op.EventThreshold);
plots.Add(plot);
}
else if (profileConfig is BlobParameters bp)
if (profileConfig is BlobParameters bp)
{
//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.
Expand Down Expand Up @@ -207,43 +185,23 @@ public override RecognizerResults Recognize(
sonogram.FramesPerSecond,
sonogram.FBinWidth);
}
else if (profileConfig is WhistleParameters wp)
else if (profileConfig is OnebinTrackParameters wp)
{
//get the array of intensity values minus intensity in side/buffer bands.
double[] decibelArray;
(acousticEvents, decibelArray) = WhistleParameters.GetWhistles(
(acousticEvents, decibelArray) = OnebinTrackParameters.GetOnebinTracks(
sonogram,
wp.MinHertz.Value,
wp.MaxHertz.Value,
sonogram.NyquistFrequency,
wp.DecibelThreshold.Value,
wp.MinDuration.Value,
wp.MaxDuration.Value,
wp.CombinePossibleSequence,
segmentStartOffset);

var plot = PreparePlot(decibelArray, $"{profileName} (Whistle:dB Intensity)", wp.DecibelThreshold.Value);
plots.Add(plot);
}
else if (profileConfig is HarmonicParameters hp)
{
double[] decibelMaxArray;
double[] harmonicIntensityScores;
(acousticEvents, decibelMaxArray, harmonicIntensityScores) = HarmonicParameters.GetComponentsWithHarmonics(
sonogram,
hp.MinHertz.Value,
hp.MaxHertz.Value,
sonogram.NyquistFrequency,
hp.DecibelThreshold.Value,
hp.DctThreshold.Value,
hp.MinDuration.Value,
hp.MaxDuration.Value,
hp.MinFormantGap.Value,
hp.MaxFormantGap.Value,
segmentStartOffset);

var plot = PreparePlot(harmonicIntensityScores, $"{profileName} (Harmonics:dct intensity)", hp.DctThreshold.Value);
plots.Add(plot);
}
else if (profileConfig is FowardTrackParameters tp)
{
double[] decibelArray;
Expand All @@ -257,24 +215,23 @@ public override RecognizerResults Recognize(
tp.CombinePossibleHarmonics,
segmentStartOffset);

var plot = PreparePlot(decibelArray, $"{profileName} (SpectralPeaks:dB Intensity)", tp.DecibelThreshold.Value);
var plot = PreparePlot(decibelArray, $"{profileName} (Chirps:dB Intensity)", tp.DecibelThreshold.Value);
plots.Add(plot);
}
else if (profileConfig is ClickParameters cp)
else if (profileConfig is OneframeTrackParameters cp)
{
double[] decibelArray;
(acousticEvents, decibelArray) = ClickParameters.GetClicks(
(acousticEvents, decibelArray) = OneframeTrackParameters.GetOneFrameTracks(
sonogram,
cp.MinHertz.Value,
cp.MaxHertz.Value,
sonogram.NyquistFrequency,
cp.DecibelThreshold.Value,
cp.MinBandwidthHertz.Value,
cp.MaxBandwidthHertz.Value,
cp.CombineProximalSimilarEvents,
segmentStartOffset);

var plot = PreparePlot(decibelArray, $"{profileName} (Click:dB Intensity)", cp.DecibelThreshold.Value);
var plot = PreparePlot(decibelArray, $"{profileName} (Clicks:dB Intensity)", cp.DecibelThreshold.Value);
plots.Add(plot);
}
else if (profileConfig is UpwardTrackParameters vtp)
Expand All @@ -293,6 +250,48 @@ public override RecognizerResults Recognize(
var plot = PreparePlot(decibelArray, $"{profileName} (VerticalTrack:dB Intensity)", vtp.DecibelThreshold.Value);
plots.Add(plot);
}
else if (profileConfig is HarmonicParameters hp)
{
double[] decibelMaxArray;
double[] harmonicIntensityScores;
(acousticEvents, decibelMaxArray, harmonicIntensityScores) = HarmonicParameters.GetComponentsWithHarmonics(
sonogram,
hp.MinHertz.Value,
hp.MaxHertz.Value,
sonogram.NyquistFrequency,
hp.DecibelThreshold.Value,
hp.DctThreshold.Value,
hp.MinDuration.Value,
hp.MaxDuration.Value,
hp.MinFormantGap.Value,
hp.MaxFormantGap.Value,
segmentStartOffset);

var plot = PreparePlot(harmonicIntensityScores, $"{profileName} (Harmonics:dct intensity)", hp.DctThreshold.Value);
plots.Add(plot);
}
if (profileConfig is OscillationParameters op)
{
Oscillations2012.Execute(
sonogram,
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 acousticEvents,
out var hits,
segmentStartOffset);

//plots.Add(new Plot($"{profileName} (:OscillationScore)", scores, op.EventThreshold));
var plot = PreparePlot(scores, $"{profileName} (:OscillationScore)", op.EventThreshold);
plots.Add(plot);
}
else
{
throw new InvalidOperationException();
Expand Down
23 changes: 10 additions & 13 deletions src/AudioAnalysisTools/Events/Tracks/Track.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ namespace AudioAnalysisTools.Events.Tracks

public enum TrackType
{
HorizontalTrack, // Sounds like single tone whistle. Each track point advances one time step. All points remain in the same frequency bin.
OneBinTrack, // Sounds like single tone whistle. Each track point advances one time step. All points remain in the same frequency bin.
FowardTrack, // Sounds like fluctuating tone/chirp. Each track point advances one time step. Points may move up or down two frequency bins.
UpwardTrack, // Sounds like whip. Each track point ascends one frequency bin. Points may move forwards or back one frame step.
VerticalTrack, // Sounds like click. Each track point ascends one frequency bin. All points remain in the same time frame.
OneFrameTrack, // Sounds like click. Each track point ascends one frequency bin. All points remain in the same time frame.
MixedTrack, // A track containing segments of two or more of the above. At present time, only created to accomodate test at TrackTests at Line 116.
}

Expand Down Expand Up @@ -197,12 +197,9 @@ public double[] GetAmplitudeOverTimeFrames()
.Points
.GroupBy(g => g.Seconds)
.OrderBy(x => x.Key)
.Windowed(2)
.Select(pointPair =>
.Select(framePoints =>
{
var firstPoints = pointPair[0];
var secondPoints = pointPair[1];
var maxAmplitude = secondPoints.Max(y => y.Value);
var maxAmplitude = framePoints.Max(y => y.Value);
return maxAmplitude;
})
.ToArray();
Expand All @@ -222,16 +219,16 @@ public void Draw(IImageProcessingContext graphics, EventRenderingOptions options
switch (this.trackType)
{
case TrackType.UpwardTrack:
((IPointData)this).DrawPointsAsPath(graphics, options);
((IPointData)this).DrawPointsAsFillExperiment(graphics, options);
break;
case TrackType.HorizontalTrack:
((IPointData)this).DrawPointsAsPath(graphics, options);
case TrackType.OneBinTrack:
((IPointData)this).DrawPointsAsFillExperiment(graphics, options);
break;
case TrackType.VerticalTrack:
((IPointData)this).DrawPointsAsPath(graphics, options);
case TrackType.OneFrameTrack:
((IPointData)this).DrawPointsAsFillExperiment(graphics, options);
break;
case TrackType.FowardTrack:
((IPointData)this).DrawPointsAsFill(graphics, options);
((IPointData)this).DrawPointsAsFillExperiment(graphics, options);
break;
default:
((IPointData)this).DrawPointsAsPath(graphics, options);
Expand Down
Loading

0 comments on commit 15cebf9

Please sign in to comment.