Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update unintelligibility algorithm #242

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions OrcanodeMonitor/Core/FfmpegCoreAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public static double MinNoiseMagnitude

// Minimum ratio of magnitude outside the hum range to magnitude
// within the hum range. So far the max in a known-unintelligible
// sample is 21% and the min in a known-good sample is 50%.
const double _defaultMinSignalPercent = 30;
// sample is 21% and the min in a known-good sample is 29%.
const double _defaultMinSignalPercent = 25;
private static double MinSignalRatio
{
get
Expand All @@ -125,9 +125,14 @@ private static double MinSignalRatio
// power lines and other electronic devices.
const double HumFrequency1 = 50.0; // Hz
const double HumFrequency2 = 60.0; // Hz
private static bool IsHumFrequency(double frequency, double humFrequency) => Math.Abs(frequency - humFrequency) < 1.0;
private static bool IsHumFrequency(double frequency, double humFrequency)
{
const double tolerance = 1.0;
double remainder = frequency % humFrequency;
return (remainder < tolerance || remainder > (humFrequency - tolerance));
}

private static bool IsHumFrequency(double frequency) => IsHumFrequency(frequency, HumFrequency1) || IsHumFrequency(frequency, HumFrequency2);
public static bool IsHumFrequency(double frequency) => IsHumFrequency(frequency, HumFrequency1) || IsHumFrequency(frequency, HumFrequency2);

/// <summary>
/// Find the maximum magnitude outside the audio hum range.
Expand Down
15 changes: 15 additions & 0 deletions Test/UnintelligibilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ private async Task TestSampleAsync(string filename, OrcanodeOnlineStatus expecte
}
}

[TestMethod]
public async Task TestHumFrequencies()
{
Assert.IsTrue(FrequencyInfo.IsHumFrequency(59.1));
Assert.IsTrue(FrequencyInfo.IsHumFrequency(60.0));
Assert.IsTrue(FrequencyInfo.IsHumFrequency(60.9));
Assert.IsTrue(FrequencyInfo.IsHumFrequency(120.0));
Assert.IsTrue(FrequencyInfo.IsHumFrequency(300.0));

Assert.IsFalse(FrequencyInfo.IsHumFrequency(59.0));
Assert.IsFalse(FrequencyInfo.IsHumFrequency(61.0));
Assert.IsFalse(FrequencyInfo.IsHumFrequency(121.0));
Assert.IsFalse(FrequencyInfo.IsHumFrequency(299.0));
}

[TestMethod]
public async Task TestSilentSample()
{
Expand Down
Loading