Skip to content

Commit

Permalink
Improve unintelligibility algorithm (#139)
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler authored Sep 29, 2024
1 parent 7653dde commit 036b51c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions OrcanodeMonitor/Core/FfmpegCoreAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ namespace OrcanodeMonitor.Core
{
public class FfmpegCoreAnalyzer
{
// We consider anything below this amplitude as silence.
// We consider anything below this average amplitude as silence.
const double MaxSilenceAmplitude = 20.0;

// We consider anything above this frequency amplitude as signal.
const double MinSignalAmplitude = 200.0;

// Microphone audio hum typically falls within the 50 Hz to 60 Hz
// range. This hum is often caused by electrical interference from
// power lines and other electronic devices.
Expand All @@ -40,15 +43,15 @@ private static OrcanodeOnlineStatus AnalyzeFrequencies(float[] data, int sampleR

// Look for signal in frequencies other than the audio hum range.
double halfOfMax = amplitudes.Max() / 2.0;
var majorOtherIndices = new List<int>();
var majorOtherIndices = new Dictionary<double, double>();
for (int i = 0; i < amplitudes.Length; i++)
{
if (amplitudes[i] > halfOfMax)
if (amplitudes[i] > MinSignalAmplitude)
{
double frequency = (((double)i) * sampleRate) / n;
if (frequency < MinHumFrequency || frequency > MaxHumFrequency)
{
majorOtherIndices.Add(i);
majorOtherIndices[frequency] = amplitudes[i];
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Test/UnintelligibilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public async Task TestUnintelligibleSample()
[TestMethod]
public async Task TestNormalSample()
{
await TestSampleAsync("normal\\live2649.ts", OrcanodeOnlineStatus.Online);
await TestSampleAsync("normal\\live2289.ts", OrcanodeOnlineStatus.Online);
await TestSampleAsync("normal\\live385.ts", OrcanodeOnlineStatus.Online);
await TestSampleAsync("normal\\live839.ts", OrcanodeOnlineStatus.Online);
await TestSampleAsync("normal\\live1184.ts", OrcanodeOnlineStatus.Online);
Expand Down
Binary file added Test/samples/normal/live2289.ts
Binary file not shown.
Binary file added Test/samples/normal/live2649.ts
Binary file not shown.

0 comments on commit 036b51c

Please sign in to comment.