Skip to content

Commit

Permalink
Adapt two classes to new Track hierarchy
Browse files Browse the repository at this point in the history
Issue #297 adapt AcousticEvent and Image_MultiTrack classes to accomodate drawing of the new Track class
  • Loading branch information
towsey committed Apr 15, 2020
1 parent 728d540 commit 1954a7d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
22 changes: 18 additions & 4 deletions src/AudioAnalysisTools/AcousticEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ namespace AudioAnalysisTools
using Acoustics.Shared.ImageSharp;
using AnalysisBase.ResultBases;
using AudioAnalysisTools.DSP;
using AudioAnalysisTools.Events.Drawing;
using AudioAnalysisTools.Events.Interfaces;
using AudioAnalysisTools.Events.Tracks;
using AudioAnalysisTools.StandardSpectrograms;
using CsvHelper.Configuration;
using SixLabors.ImageSharp;
Expand Down Expand Up @@ -126,7 +128,7 @@ public AcousticEventClassMap()
/// <summary>
/// Gets or sets a horizontal or vertical spectral track.
/// </summary>
public SpectralTrack_TO_BE_REMOVED TheTrack { get; set; }
public Track TheTrack { get; set; }

public bool IsMelscale { get; set; }

Expand All @@ -138,7 +140,7 @@ public AcousticEventClassMap()
/// </summary>
public Oblong Oblong { get; set; }

/// <summary> Gets or sets required for conversions to & from MEL scale AND for drawing event on spectrum.</summary>
/// <summary> Gets or sets required for conversions to/from MEL scale AND for drawing event on spectrum.</summary>
public int FreqBinCount { get; set; }

/// <summary>
Expand Down Expand Up @@ -459,8 +461,20 @@ public void DrawEvent<T>(Image<T> imageToReturn, double framesPerSecond, double
if (this.TheTrack != null)
{
// currently this call assumes that the Track[frame, bin[ elements correspond to the pixels of the passed spectrogram.
// That is, there is no rescaling of the time and frequency axes.
this.TheTrack.DrawTrack(imageToReturn, framesPerSecond, freqBinWidth);
// That is, there is no rescaling of the time and frequency axes
var converter = new UnitConverters(
segmentStartOffset: this.SegmentStartSeconds,
segmentDuration: this.SegmentDurationSeconds,
nyquistFrequency: freqBinWidth * sonogramHeight,
imageWidth: imageToReturn.Width,
imageHeight: imageToReturn.Height);

var renderingOptions = new EventRenderingOptions(converter);
imageToReturn.Mutate(
context =>
{
this.TheTrack.Draw(context, renderingOptions);
});
return;
}

Expand Down
20 changes: 16 additions & 4 deletions src/AudioAnalysisTools/StandardSpectrograms/Image_MultiTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace AudioAnalysisTools.StandardSpectrograms
{
using System;
using System.Collections.Generic;
using AudioAnalysisTools.Events.Drawing;
using AudioAnalysisTools.Events.Interfaces;
using AudioAnalysisTools.Events.Tracks;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
Expand Down Expand Up @@ -37,7 +40,7 @@ public Image_MultiTrack(Image<Rgb24> image)

public IEnumerable<AcousticEvent> EventList { get; set; }

public List<SpectralTrack_TO_BE_REMOVED> SpectralTracks { get; set; }
public List<Track> SpectralTracks { get; set; }

public double[,] SuperimposedMatrix { get; set; }

Expand Down Expand Up @@ -118,7 +121,7 @@ public void AddFreqHitValues(int[] f, int nyquist)
this.nyquistFreq = nyquist;
}

public void AddTracks(List<SpectralTrack_TO_BE_REMOVED> tracks, double framesPerSecond, double freqBinWidth)
public void AddTracks(List<Track> tracks, double framesPerSecond, double freqBinWidth)
{
this.freqBinWidth = freqBinWidth;
this.framesPerSecond = framesPerSecond;
Expand Down Expand Up @@ -202,9 +205,18 @@ public Image<Rgb24> GetImage()

if (this.SpectralTracks != null)
{
foreach (SpectralTrack_TO_BE_REMOVED t in this.SpectralTracks)
var converter = new UnitConverters(
segmentStartOffset: 0.0,
segmentDuration: this.framesPerSecond * this.SonogramImage.Width,
nyquistFrequency: this.freqBinWidth * this.SonogramImage.Height,
imageWidth: this.SonogramImage.Width,
imageHeight: this.SonogramImage.Height);

var renderingOptions = new EventRenderingOptions(converter);

foreach (var t in this.SpectralTracks)
{
t.DrawTrack(this.SonogramImage, this.framesPerSecond, this.freqBinWidth);
t.Draw(g, renderingOptions);
}
}

Expand Down

0 comments on commit 1954a7d

Please sign in to comment.