Skip to content

Commit

Permalink
Make GetCompositeTrack generic
Browse files Browse the repository at this point in the history
  • Loading branch information
atruskie committed Jun 12, 2020
1 parent 3ea2467 commit f8545f0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static List<EventCommon> FilterEventsOnFrequencyProfile(List<EventCommon>
var returnEvents = new List<EventCommon>();
foreach (var ev in compositeEvents)
{
var componentEvents = ev.ComponentEvents;
var componentEvents = ev.ComponentEvents.Cast<WhipEvent>();
var points = EventExtentions.GetCompositeTrack(componentEvents).ToArray();

// Uncomment this line when want to see the composite track profile.
Expand Down
9 changes: 5 additions & 4 deletions src/AudioAnalysisTools/Events/EventExtentions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace AudioAnalysisTools.Events
using System;
using System.Collections.Generic;
using System.Linq;
using AudioAnalysisTools.Events.Interfaces;
using AudioAnalysisTools.Events.Tracks;
using AudioAnalysisTools.Events.Types;
using AudioAnalysisTools.StandardSpectrograms;
using MoreLinq;
Expand Down Expand Up @@ -347,13 +349,12 @@ public static List<EventCommon> FilterEventsOnCompositeContent(
/// Combines all the tracks in all the events in the passed list into a single track.
/// Each frame in the composite event is assigned the spectral point having maximum amplitude.
/// The points in the returned array are in temporal order.
/// TODO TODO WARNING! This method needs to be generalised from WhipEvent - see first line.
/// </summary>
/// <param name="events">List of spectral events.</param>
public static IEnumerable<ISpectralPoint> GetCompositeTrack(List<EventCommon> events)
public static IEnumerable<ISpectralPoint> GetCompositeTrack<T>(IEnumerable<T> events)
where T : ITracks<Track>
{
var spectralEvents = events.Select(x => (WhipEvent)x);
var points = spectralEvents.SelectMany(x => x.Tracks.SelectMany(t => t.Points));
var points = events.SelectMany(x => x.Tracks.SelectMany(t => t.Points));

// group all the points by their start time.
var groupStarts = points.GroupBy(p => p.Seconds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Acoustics.Test.AnalysisPrograms.Recognizers
using Acoustics.Tools.Wav;
using global::AnalysisPrograms.Recognizers;
using global::AnalysisPrograms.SourcePreparers;
using global::AudioAnalysisTools;
using global::AudioAnalysisTools.Events;
using global::AudioAnalysisTools.Events.Types;
using global::AudioAnalysisTools.WavTools;
Expand Down Expand Up @@ -77,10 +78,10 @@ public void TestRecognizer()

// This tests that the component tracks are correctly combined.
//This can also be tested somewhere else, starting with just the comosite event in json file.
var points = EventExtentions.GetCompositeTrack(componentEvents).ToArray();
var points = EventExtentions.GetCompositeTrack(componentEvents.Cast<WhipEvent>()).ToArray();
Assert.AreEqual(16.672, points[1].Seconds.Minimum);
Assert.AreEqual(5425, points[1].Hertz.Minimum);
Assert.AreEqual(23.71245325, points[1].Value, TestHelper.AllowedDelta);
Assert.AreEqual(23.712453258003087, points[1].Value, TestHelper.AllowedDelta);
}
}
}

0 comments on commit f8545f0

Please sign in to comment.