Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler committed Jan 29, 2025
1 parent 5c7bd37 commit 421768e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion OrcanodeMonitor/Core/FfmpegCoreAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace OrcanodeMonitor.Core
{
public class FfmpegCoreAnalyzer
public class FfmpegCoreAnalyzer
{
/// <summary>
/// Analyze frequencies.
Expand Down
12 changes: 11 additions & 1 deletion OrcanodeMonitor/Core/FrequencyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,17 @@ public Dictionary<double, double> GetFrequencyMagnitudes(int? channel = null)
}

public double GetMaxMagnitude(int? channel = null) => GetFrequencyMagnitudes(channel).Values.Max();
public double GetSignalRatio(int? channel = null) => GetTotalNonHumMagnitude(channel) / GetTotalHumMagnitude(channel);

/// <summary>
/// Compute the sound-to-hum ratio.
/// </summary>
/// <param name="channel">Channel number, or null for an aggregate</param>
/// <returns>Ratio</returns>
public double GetSignalRatio(int? channel = null)
{
double hum = Math.Max(GetTotalHumMagnitude(channel), 1);
return GetTotalNonHumMagnitude(channel) / hum;
}

// Microphone audio hum typically falls within the 50 Hz or 60 Hz
// range. This hum is often caused by electrical interference from
Expand Down
22 changes: 18 additions & 4 deletions OrcanodeMonitor/Pages/SpectralDensity.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,15 @@ private async Task UpdateNodeFrequencyDataAsync()
TimestampResult? result = await GetLatestS3TimestampAsync(_node, false, _logger);
if (result != null)
{
_frequencyInfo = await Fetcher.GetLatestAudioSampleAsync(_node, result.UnixTimestampString, false, _logger);
UpdateFrequencyInfo();
try
{
_frequencyInfo = await Fetcher.GetLatestAudioSampleAsync(_node, result.UnixTimestampString, false, _logger);
UpdateFrequencyInfo();
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to fetch audio sample for node {NodeId}", _node.ID);
}
}
}

Expand All @@ -199,8 +206,15 @@ private async Task UpdateEventFrequencyDataAsync()
DateTime? lastModified = await Fetcher.GetLastModifiedAsync(uri);
LastModified = lastModified?.ToLocalTime().ToString() ?? "Unknown";

_frequencyInfo = await Fetcher.GetExactAudioSampleAsync(_node, uri, _logger);
UpdateFrequencyInfo();
try
{
_frequencyInfo = await Fetcher.GetExactAudioSampleAsync(_node, uri, _logger);
UpdateFrequencyInfo();
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to fetch audio sample for event {EventId}", _id);
}
}

public async Task OnGetAsync(string id)
Expand Down

0 comments on commit 421768e

Please sign in to comment.