Skip to content

Commit

Permalink
Update SpectrogramTools.cs
Browse files Browse the repository at this point in the history
Issue #469  Fix the drawing of spectrograms.
  • Loading branch information
towsey committed Jun 14, 2021
1 parent 0c9eaa4 commit 3b9b1b8
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/AudioAnalysisTools/StandardSpectrograms/SpectrogramTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,31 @@ public static Image<Rgb24> GetSonogramPlusCharts(
BaseSonogram sonogram,
List<EventCommon> events,
List<Plot> plots,
double[,] hits)
double[,] hits,
string title)
{
var spectrogram = sonogram.GetImage(doHighlightSubband: false, add1KHzLines: true, doMelScale: false);
// get the spectrogram as image but do not add gridlines at this stage.
var spectrogram = sonogram.GetImage(doHighlightSubband: false, add1KHzLines: false, doMelScale: false);
Contract.RequiresNotNull(spectrogram, nameof(spectrogram));

var height = spectrogram.Height;
var width = spectrogram.Width;
var frameSize = sonogram.Configuration.WindowSize;
//var segmentDuration = sonogram.Duration;
var spectrogramDuration = width * sonogram.FrameStep;

// init with linear frequency scale and draw freq grid lines on image
int hertzInterval = 1000;
if (height < 200)
var nyquist = sonogram.NyquistFrequency;
int hertzInterval = 2000;
if (nyquist <= 16000)
{
hertzInterval = 1000;
} else
if (nyquist <= 8000)
{
hertzInterval = 2000;
hertzInterval = 500;
}

var nyquist = sonogram.NyquistFrequency;
// now add gridlines
var freqScale = new FrequencyScale(nyquist, frameSize, hertzInterval);
FrequencyScale.DrawFrequencyLinesOnImage(spectrogram, freqScale.GridLineLocations, includeLabels: true);

Expand All @@ -186,7 +192,7 @@ public static Image<Rgb24> GetSonogramPlusCharts(
}

int pixelWidth = spectrogram.Width;
var titleBar = LDSpectrogramRGB.DrawTitleBarOfGrayScaleSpectrogram("TITLE", pixelWidth);
var titleBar = LDSpectrogramRGB.DrawTitleBarOfGrayScaleSpectrogram(title, pixelWidth);
var timeTrack = ImageTrack.DrawTimeTrack(sonogram.Duration, pixelWidth);

var imageList = new List<Image<Rgb24>>
Expand Down Expand Up @@ -226,11 +232,12 @@ public static Image<Rgb24> GetSonogramPlusCharts(
BaseSonogram sonogram,
List<AcousticEvent> events,
List<Plot> plots,
double[,] hits)
double[,] hits,
string title)
{
// convert AcousticEvents to EventsCommon
List<EventCommon> newEvents = EventConverters.ConvertAcousticEventsToSpectralEvents(events);
var compositeImage = GetSonogramPlusCharts(sonogram, newEvents, plots, hits);
var compositeImage = GetSonogramPlusCharts(sonogram, newEvents, plots, hits, title);
return compositeImage;
}

Expand Down

0 comments on commit 3b9b1b8

Please sign in to comment.