Skip to content

Commit

Permalink
Remove old AcousticEvent constructor
Browse files Browse the repository at this point in the history
Issue #297 and fix all the associated errors. Create a new static method to accomodate loss of old constructor.
  • Loading branch information
towsey committed Apr 22, 2020
1 parent 2274b91 commit 45ed89d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 68 deletions.
30 changes: 12 additions & 18 deletions src/AnalysisPrograms/GroundParrotRecogniser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ namespace AnalysisPrograms
public class GroundParrotRecogniser : AbstractStrongAnalyser
{
public const string CommandName = "GroundParrot";
private const string EcosoundsGroundParrotIdentifier = "Ecosounds.GroundParrot";
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

public override string Description => "[UNMAINTAINED] Uses event pattern recognition for ground-parrots";

Expand Down Expand Up @@ -195,17 +197,12 @@ public static void Execute(Arguments arguments)
}

LoggedConsole.WriteLine();

string outputFolder = arguments.Config.ToFileInfo().DirectoryName;
string wavFilePath = input.FullName;
BaseSonogram sonogram = result.Item1;
string imagePath = Path.Combine(outputFolder, Path.GetFileNameWithoutExtension(wavFilePath) + ".png");
var image = Aed.DrawSonogram(sonogram, eprEvents.ConvertAcousticEventsToSpectralEvents());
image.Save(imagePath);

//ProcessingTypes.SaveAeCsv(eprEvents, outputFolder, wavFilePath);

Log.Info("Finished");
}

/// <summary>
Expand Down Expand Up @@ -244,7 +241,6 @@ public static List<AcousticEvent> ReadGroundParrotTemplateAsList(BaseSonogram so
var timeScale = sonogram.FrameStep;
var hzScale = (int)sonogram.FBinWidth;
int rows = GroundParrotTemplate1.GetLength(0);
int cols = GroundParrotTemplate1.GetLength(1);
double timeOffset = GroundParrotTemplate1[0, 0];
var gpTemplate = new List<AcousticEvent>();
for (int r = 0; r < rows; r++)
Expand All @@ -254,23 +250,21 @@ public static List<AcousticEvent> ReadGroundParrotTemplateAsList(BaseSonogram so
int f2 = (int)Math.Round(GroundParrotTemplate1[r, 2] / hzScale);
int f1 = (int)Math.Round(GroundParrotTemplate1[r, 3] / hzScale);
Oblong o = new Oblong(t1, f1, t2, f2);
gpTemplate.Add(
new AcousticEvent(
TimeSpan.Zero,
o,
sonogram.NyquistFrequency,
sonogram.Configuration.FreqBinCount,
sonogram.FrameDuration,
sonogram.FrameStep,
sonogram.FrameCount));
var ae = AcousticEvent.InitializeAcousticEvent(
TimeSpan.Zero,
o,
sonogram.NyquistFrequency,
sonogram.Configuration.FreqBinCount,
sonogram.FrameDuration,
sonogram.FrameStep,
sonogram.FrameCount);

gpTemplate.Add(ae);
}

return gpTemplate;
}

private const string EcosoundsGroundParrotIdentifier = "Ecosounds.GroundParrot";
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

public override string DisplayName => "Ground Parrot Recognizer";

public override string Identifier => EcosoundsGroundParrotIdentifier;
Expand Down
10 changes: 5 additions & 5 deletions src/AnalysisPrograms/Recognizers/Base/RecognizerResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ public RecognizerResults()
/// </summary>
public Image<Rgb24> ScoreTrack { get; set; }

public IEnumerable<EventBase> GetAllEvents()
{
return this.Events.Cast<EventBase>().Concat(this.NewEvents.Cast<EventBase>());
}

/// <summary>
/// Gets or sets a list of plots.
/// Used by the multi recognizer.
Expand All @@ -63,5 +58,10 @@ public List<Plot> Plots
this.plots = value ?? throw new ArgumentNullException(nameof(value), "Cannot be set to null");
}
}

public IEnumerable<EventBase> GetAllEvents()
{
return this.Events.Cast<EventBase>().Concat(this.NewEvents.Cast<EventBase>());
}
}
}
22 changes: 9 additions & 13 deletions src/AnalysisPrograms/Recognizers/ExempliGratia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace AnalysisPrograms.Recognizers
using AnalysisPrograms.Recognizers.Base;
using AudioAnalysisTools;
using AudioAnalysisTools.DSP;
using AudioAnalysisTools.Events;
using AudioAnalysisTools.Indices;
using AudioAnalysisTools.StandardSpectrograms;
using AudioAnalysisTools.WavTools;
Expand Down Expand Up @@ -185,30 +186,25 @@ private static List<AcousticEvent> RunFemaleProfile(configuration, rest of argum
// then indices have been calculated before
}

var foundEvents = new List<AcousticEvent>();
var foundEvents = new List<EventCommon>();

// some kind of loop where you scan through the audio

// 'find' an event - if you find an event, store the data in the AcousticEvent class
var anEvent = new AcousticEvent(
segmentStartOffset,
new Oblong(50, 50, 100, 100),
sonogram.NyquistFrequency,
sonogram.Configuration.FreqBinCount,
sonogram.FrameDuration,
sonogram.FrameStep,
sonogram.FrameCount);
anEvent.Name = "FAKE!";

var anEvent = new SpectralEvent
{
Name = "FAKE!",
};

foundEvents.Add(anEvent);

return new RecognizerResults()
{
Events = foundEvents,
//Plots = null,
NewEvents = foundEvents,
Hits = null,
ScoreTrack = null,

//Plots = null,
Sonogram = sonogram,
};
}
Expand Down
34 changes: 2 additions & 32 deletions src/AudioAnalysisTools/AcousticEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,38 +276,6 @@ public AcousticEvent(TimeSpan segmentStartOffset, Track track)
this.Oblong = null;
}

/// <summary>
/// Initializes a new instance of the <see cref="AcousticEvent"/> class.
/// This constructor currently works ONLY for linear Hertz scale events.
/// It requires the event bounds to provided (using Oblong) in terms of time frame and frequency bin counts.
/// Scale information must also be provided to convert bounds into real values (seconds, Hertz).
/// </summary>
/// <param name="o">An oblong initialized with bin and frame numbers marking location of the event.</param>
/// <param name="nyquistFrequency">to set the freq scale.</param>
/// <param name="binCount">Number of freq bins.</param>
/// <param name="frameDuration">tseconds duration of a frame - to set the time scale.</param>
/// <param name="frameStep">seconds between frame starts i.e. frame step; i.e. inverse of frames per second. Sets the time scale for an event.</param>
/// <param name="frameCount">to set the time scale.</param>
public AcousticEvent(TimeSpan segmentStartOffset, Oblong o, int nyquistFrequency, int binCount, double frameDuration, double frameStep, int frameCount)
: this()
{
this.Oblong = o;
this.FreqBinWidth = nyquistFrequency / (double)binCount;
this.FrameDuration = frameDuration;
this.FrameOffset = frameStep;
this.FreqBinCount = binCount;
this.FrameCount = frameCount;

double startTime = o.RowTop * this.FrameOffset;
double end = (o.RowBottom + 1) * this.FrameOffset;

this.SetEventPositionRelative(segmentStartOffset, startTime, end);

this.LowFrequencyHertz = (int)Math.Round(o.ColumnLeft * this.FreqBinWidth);
this.HighFrequencyHertz = (int)Math.Round(o.ColumnRight * this.FreqBinWidth);
this.HitElements = o.HitElements;
}

public int FrameCount { get; set; }

public ISet<Point> HitElements { get; set; }
Expand Down Expand Up @@ -610,6 +578,8 @@ public static AcousticEvent InitializeAcousticEvent(TimeSpan segmentStartOffset,
FrameDuration = frameDuration,
FreqBinCount = binCount,
FrameCount = frameCount,
Oblong = o,
HitElements = o.HitElements,
};

return ae;
Expand Down

0 comments on commit 45ed89d

Please sign in to comment.