public void FindWorksForAbolsutePath() { var realConfig = PathHelper.ResolveConfigFile("IndexPropertiesConfig.yml"); var parentConfig = new IndexCalculateConfig() { IndexPropertiesConfig = realConfig.FullName, }; Assert.AreEqual(realConfig.FullName, IndexProperties.Find(parentConfig).FullName); // and test direct Assert.AreEqual(realConfig.FullName, IndexProperties.Find(realConfig.FullName, null).FullName); }
public void FindWorksForRelativePath() { var parentConfigPath = PathHelper.ResolveConfigFile("Towsey.Acoustic.yml"); var realConfig = PathHelper.ResolveConfigFile("IndexPropertiesConfig.yml"); var parentConfig = new IndexCalculateConfig() { IndexPropertiesConfig = realConfig.Name, ConfigPath = parentConfigPath.FullName, }; Assert.AreEqual(realConfig.FullName, IndexProperties.Find(parentConfig).FullName); // and test direct Assert.AreEqual(realConfig.FullName, IndexProperties.Find(realConfig.Name, parentConfigPath).FullName); }
public void FindReturnsNullOnGivenEmpty() { var emptyConfig = new IndexCalculateConfig() { IndexPropertiesConfig = string.Empty, }; Assert.IsNull(IndexProperties.Find(emptyConfig)); AnalyzerConfig genericConfig = new AcousticIndices.AcousticIndicesConfig() { IndexPropertiesConfig = string.Empty, }; Assert.IsNull(IndexProperties.Find(genericConfig as IIndexPropertyReferenceConfiguration)); // and test direct Assert.IsNull(IndexProperties.Find(string.Empty, null)); }
public void FindFailsWithConfigFileErrorForMissing() { var parentConfigPath = PathHelper.ResolveConfigFile("Towsey.Acoustic.yml"); var nonExisting = "blahblahblah.yml"; var parentConfig = new IndexCalculateConfig() { IndexPropertiesConfig = nonExisting, ConfigPath = parentConfigPath.FullName, }; Assert.ThrowsException <ConfigFileException>( () => IndexProperties.Find(parentConfig), $"The specified config file ({nonExisting}) could not be found"); // and test direct Assert.ThrowsException <ConfigFileException>( () => IndexProperties.Find(nonExisting, parentConfigPath), $"The specified config file ({nonExisting}) could not be found"); }
public void FindReturnsNullOnGivenNull() { var nullConfig = new IndexCalculateConfig() { IndexPropertiesConfig = null, }; Assert.IsNull(IndexProperties.Find(nullConfig)); var genericConfig = new AnalyzerConfig() { // property does not exist //IndexPropertiesConfig = string.Empty, }; Assert.IsNull(IndexProperties.Find(genericConfig as IIndexPropertyReferenceConfiguration)); // and test direct Assert.IsNull(IndexProperties.Find((string)null, null)); }
public static IndexCalculateResult[] CalculateIndicesInSubsegments( AudioRecording recording, TimeSpan segmentStartOffset, TimeSpan segmentDuration, TimeSpan indexCalculationDuration, Dictionary <string, IndexProperties> indexProperties, int sampleRateOfOriginalAudioFile, IndexCalculateConfig config) { if (recording.WavReader.Channels > 1) { throw new InvalidOperationException( @"A multi-channel recording MUST be mixed down to MONO before calculating acoustic indices!"); } double recordingDuration = recording.Duration.TotalSeconds; double subsegmentDuration = indexCalculationDuration.TotalSeconds; // intentional possible null ref, throw if not null double segmentDurationSeconds = segmentDuration.TotalSeconds; double audioCuttingError = subsegmentDuration - segmentDurationSeconds; // using the expected duration, each call to analyze will always produce the same number of results // round, we expect perfect numbers, warn if not double subsegmentsInSegment = segmentDurationSeconds / subsegmentDuration; int subsegmentCount = (int)Math.Round(segmentDurationSeconds / subsegmentDuration); const double warningThreshold = 0.01; // 1% double fraction = subsegmentsInSegment - subsegmentCount; if (Math.Abs(fraction) > warningThreshold) { Log.Warn( string.Format( "The IndexCalculationDuration ({0}) does not fit well into the provided segment ({1}). This means a partial result has been {3}, {2} results will be calculated", subsegmentDuration, segmentDurationSeconds, subsegmentCount, fraction >= 0.5 ? "added" : "removed")); } Log.Trace(subsegmentCount + " sub segments will be calculated"); var indexCalculateResults = new IndexCalculateResult[subsegmentCount]; // calculate indices for each subsegment for (int i = 0; i < subsegmentCount; i++) { var subsegmentOffset = segmentStartOffset + TimeSpan.FromSeconds(i * subsegmentDuration); var indexCalculateResult = IndexCalculate.Analysis( recording, subsegmentOffset, indexProperties, sampleRateOfOriginalAudioFile, segmentStartOffset, config); indexCalculateResults[i] = indexCalculateResult; } return(indexCalculateResults); }