Skip to content

Commit

Permalink
Begin work on flying fox recogniser
Browse files Browse the repository at this point in the history
Branch for Issue-#238
  • Loading branch information
towsey authored and atruskie committed Aug 28, 2019
1 parent 6481e0e commit 414b392
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
66 changes: 39 additions & 27 deletions src/AnalysisPrograms/Recognizers/PteropusSpecies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace AnalysisPrograms.Recognizers
/// </summary>
internal class PteropusSpecies : RecognizerBase
{
public override string Author => "Truskinger";
public override string Author => "Towsey";

public override string SpeciesName => "PteropusSpecies";

Expand Down Expand Up @@ -81,19 +81,28 @@ public override void SummariseResults(
/// <returns>recogniser results.</returns>
public override RecognizerResults Recognize(AudioRecording audioRecording, Config configuration, TimeSpan segmentStartOffset, Lazy<IndexCalculateResult[]> getSpectralIndexes, DirectoryInfo outputDirectory, int? imageWidth)
{
// Get a value from the config file - with a backup default
int minHz = configuration.GetIntOrNull(AnalysisKeys.MinHz) ?? 600;
// get the common properties
string speciesName = configuration[AnalysisKeys.SpeciesName] ?? "<no species>";
string abbreviatedSpeciesName = configuration[AnalysisKeys.AbbreviatedSpeciesName] ?? "<no.sp>";

// Get a value from the config file - with no default, throw an exception if value is not present
//int maxHz = ((int?)configuration[AnalysisKeys.MaxHz]).Value;
RecognizerResults results = Gruntwork(audioRecording, configuration, outputDirectory, segmentStartOffset);

return results;
}

/// <summary>
/// THis method does the work.
/// </summary>
/// <param name="audioRecording">the recording.</param>
/// <param name="configuration">the config file.</param>
/// <param name="outputDirectory">where results are to be put.</param>
/// <param name="segmentStartOffset">where one segment is located in the total recording.</param>
/// <returns>a list of events.</returns>
internal static RecognizerResults Gruntwork(AudioRecording audioRecording, Config configuration, DirectoryInfo outputDirectory, TimeSpan segmentStartOffset)
{
// Get a value from the config file - without a string accessor, as a double
double someExampleSettingA = configuration.GetDoubleOrNull("SomeExampleSettingA") ?? 0.0;

// common properties
string speciesName = configuration[AnalysisKeys.SpeciesName] ?? "<no species>";
string abbreviatedSpeciesName = configuration[AnalysisKeys.AbbreviatedSpeciesName] ?? "<no.sp>";

/*
* Examples of using profiles
*/
Expand All @@ -115,6 +124,27 @@ public override RecognizerResults Recognize(AudioRecording audioRecording, Confi

//######################
//2.Convert each segment to a spectrogram.
double noiseReductionParameter = configuration.GetDoubleOrNull(AnalysisKeys.NoiseBgThreshold) ?? 0.1;

// make a spectrogram
var sonoConfig = new SonogramConfig
{
WindowSize = 512,
NoiseReductionType = NoiseReductionType.Standard,
NoiseReductionParameter = configuration.GetDoubleOrNull(AnalysisKeys.NoiseBgThreshold) ?? 0.0,
};
sonoConfig.WindowOverlap = 0.0;

// now construct the standard decibel spectrogram WITH noise removal, and look for LimConvex
// get frame parameters for the analysis
var sonogram = (BaseSonogram)new SpectrogramStandard(sonoConfig, audioRecording.WavReader);

var sonoImage = sonogram.GetImageFullyAnnotated("Test");
string imageFilename = "Test.png";
sonoImage.Save(Path.Combine(outputDirectory.FullName, imageFilename));

// get samples
var samples = audioRecording.WavReader.Samples;

// Profile example: running the same algorithm on every profile with different settings (regional variation)
/*
Expand Down Expand Up @@ -188,27 +218,9 @@ private static List<AcousticEvent> RunFemaleProfile(configuration, rest of argum
}
*/

// get samples
var samples = audioRecording.WavReader.Samples;

// make a spectrogram
var config = new SonogramConfig
{
NoiseReductionType = NoiseReductionType.Standard,
NoiseReductionParameter = configuration.GetDoubleOrNull(AnalysisKeys.NoiseBgThreshold) ?? 0.0,
};
var sonogram = (BaseSonogram)new SpectrogramStandard(config, audioRecording.WavReader);

// get high resolution indices

// when the value is accessed, the indices are calculated
var indices = getSpectralIndexes.Value;

// check if the indices have been calculated - you shouldn't actually need this
if (getSpectralIndexes.IsValueCreated)
{
// then indices have been calculated before
}

var foundEvents = new List<AcousticEvent>();

Expand Down
2 changes: 1 addition & 1 deletion src/AnalysisPrograms/Sandpit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public static void Audio2CsvOverOneFile()
//audio2csv "C:\SensorNetworks\WavFiles\KoalaMale\SmallTestSet\DaguilarGoldCreek1_DM420157_0000m_00s__0059m_47s_49h.mp3" "C:\SensorNetworks\Software\AudioAnalysis\AnalysisConfigFiles\Towsey.MultiAnalyser.cfg" "C:\SensorNetworks\Output\Test1"

// FLYING FOX RECORDINGS
string recordingPath = @"C:\SensorNetworks\WavFiles\TsheringDema\WBH12HOURS-D_20160403_120000.wav";
string recordingPath = @"C:\Ecoacoustics\WavFiles\BradLawData\FlyingFox\20190127_Bellingen_Feeding_SM4.wav";
string configPath = @"C:\Work\GitHub\audio-analysis\src\AnalysisConfigFiles\RecognizerConfigFiles\Towsey.PteropusSpecies.yml";
string outputPath = @"C:\Ecoacoustics\Output\BradLaw\FlyingFox";

Expand Down

0 comments on commit 414b392

Please sign in to comment.