Skip to content

Commit

Permalink
Improve unintelligibility algorithm (#141)
Browse files Browse the repository at this point in the history
* Improve unintelligibility algorithm

Make signal to noise ratio configurable

Signed-off-by: Dave Thaler <[email protected]>

* Remove obsolete configuration parameter ORCASOUND_MIN_INTELLIGIBLE_STREAM_DEVIATION

No longer used in the new unintelligibility algorithm.

Signed-off-by: Dave Thaler <[email protected]>

* Add test case file

Signed-off-by: Dave Thaler <[email protected]>

---------

Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler authored Oct 1, 2024
1 parent 89eceb2 commit bcd27d6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 32 deletions.
14 changes: 11 additions & 3 deletions OrcanodeMonitor/Core/FfmpegCoreAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ public class FfmpegCoreAnalyzer

// Minimum ratio of amplitude outside the hum range to amplitude
// within the hum range. So far the max in a known-unintelligible
// sample is 10% and the min in a known-good sample is 50%. So for
// now we use 20%.
const double MinSignalRatio = 0.20;
// sample is 21% and the min in a known-good sample is 50%.
const double _defaultMinSignalPercent = 30;
private static double MinSignalRatio
{
get
{
string? minSignalPercentString = Environment.GetEnvironmentVariable("ORCASOUND_MIN_INTELLIGIBLE_SIGNAL_PERCENT");
double minSignalPercent = double.TryParse(minSignalPercentString, out var percent) ? percent : _defaultMinSignalPercent;
return minSignalPercent / 100.0;
}
}

// Microphone audio hum typically falls within the 50 Hz to 60 Hz
// range. This hum is often caused by electrical interference from
Expand Down
28 changes: 1 addition & 27 deletions OrcanodeMonitor/Models/Orcanode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,6 @@ private static TimeSpan MaxUploadDelay
}
}

private static double MinIntelligibleStreamDeviation
{
get
{
string? minIntelligibleStreamDeviationString = Environment.GetEnvironmentVariable("ORCASOUND_MIN_INTELLIGIBLE_STREAM_DEVIATION");
double minIntelligibleStreamDeviation = double.TryParse(minIntelligibleStreamDeviationString, out var deviation) ? deviation : _defaultMinIntelligibleStreamDeviation;
return minIntelligibleStreamDeviation;
}
}

/// <summary>
/// Value in the latest.txt file, as a Local DateTime.
/// </summary>
Expand Down Expand Up @@ -303,8 +293,7 @@ public OrcanodeOnlineStatus S3StreamStatus

if (AudioStreamStatus == OrcanodeOnlineStatus.Absent && AudioStandardDeviation != 0.0)
{
// Fall back to legacy algorithm.
AudioStreamStatus = (IsUnintelligible(AudioStandardDeviation)) ? OrcanodeOnlineStatus.Unintelligible : OrcanodeOnlineStatus.Online;
AudioStreamStatus = OrcanodeOnlineStatus.Online;
}

return AudioStreamStatus ?? OrcanodeOnlineStatus.Absent;
Expand All @@ -325,21 +314,6 @@ public string OrcasoundOnlineStatusString {

#region methods

/// <summary>
/// Function used for backwards compatibility when reading a database
/// entry with no AudioStreamStatus.
/// </summary>
/// <param name="audioStandardDeviation"></param>
/// <returns></returns>
public static bool IsUnintelligible(double? audioStandardDeviation)
{
if (audioStandardDeviation.HasValue && (audioStandardDeviation < MinIntelligibleStreamDeviation))
{
return true;
}
return false;
}

public OrcanodeIftttDTO ToIftttDTO() => new OrcanodeIftttDTO(ID, DisplayName);

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion Test/UnintelligibilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private async Task TestSampleAsync(string filename, OrcanodeOnlineStatus expecte
try
{
OrcanodeOnlineStatus status = await FfmpegCoreAnalyzer.AnalyzeFileAsync(filePath);
Assert.IsTrue(status == expected_status);
Assert.IsTrue(status == expected_status);
}
catch (Exception ex)
{
Expand All @@ -38,6 +38,7 @@ private async Task TestSampleAsync(string filename, OrcanodeOnlineStatus expecte
[TestMethod]
public async Task TestUnintelligibleSample()
{
await TestSampleAsync("unintelligible\\live4869.ts", OrcanodeOnlineStatus.Unintelligible);
await TestSampleAsync("unintelligible\\live1816b.ts", OrcanodeOnlineStatus.Unintelligible);
await TestSampleAsync("unintelligible\\live1791.ts", OrcanodeOnlineStatus.Unintelligible);
await TestSampleAsync("unintelligible\\live1815.ts", OrcanodeOnlineStatus.Unintelligible);
Expand Down
Binary file added Test/samples/unintelligible/live4869.ts
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/Design.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ The following state will be stored per orcanode:

**ORCASOUND_MAX_UPLOAD_DELAY_MINUTES**: If the manifest file is older than this, the node will be considered offline. Default: 2

**ORCASOUND_MIN_INTELLIGIBLE_STREAM_DEVIATION**: The minimum standard deviation needed to determine that an audio stream is intelligible. Default: 175
**ORCASOUND_MIN_INTELLIGIBLE_SIGNAL_PERCENT**: The minimum percentage of max amplitude across all frequencies of amplitude outside the 50-60 Hz range needed to determine that an audio stream is intelligible. Default: 30

## Web page front end

Expand Down

0 comments on commit bcd27d6

Please sign in to comment.