Skip to content

Commit

Permalink
Show max silence and min signal lines
Browse files Browse the repository at this point in the history
Addresses more of #217

Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler committed Dec 28, 2024
1 parent 256b93d commit 1ddb6e8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
4 changes: 2 additions & 2 deletions OrcanodeMonitor/Core/FfmpegCoreAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static Dictionary<double, double> ComputeFrequencyMagnitudes(float[] dat

// We consider anything above this average magnitude as not silence.
const double _defaultMaxSilenceMagnitude = 20.0;
private static double MaxSilenceMagnitude
public static double MaxSilenceMagnitude
{
get
{
Expand All @@ -86,7 +86,7 @@ private static double MaxSilenceMagnitude

// We consider anything below this average magnitude as silence.
const double _defaultMinNoiseMagnitude = 15.0;
private static double MinNoiseMagnitude
public static double MinNoiseMagnitude
{
get
{
Expand Down
42 changes: 33 additions & 9 deletions OrcanodeMonitor/Pages/SpectralDensity.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,47 @@
<h1 class="display-4">Spectral Density of Audio From @Model.NodeName</h1>

<!-- Include Chart.js from CDN -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.1"></script>

<!-- Canvas for Chart.js -->
<canvas id="frequencyChart" width="400" height="200"></canvas>
<script>
var ctx = document.getElementById('frequencyChart').getContext('2d');
var myBarChart = new Chart(ctx, {
var myLineChart = new Chart(ctx, {
type: 'line',
data: {
labels: @Html.Raw(Json.Serialize(Model.Labels)),
datasets: [{
label: 'Last Sample',
data: @Html.Raw(Json.Serialize(Model.MaxBucketMagnitude)),
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1
}]
datasets: [
{
label: 'Last Sample',
data: @Html.Raw(Json.Serialize(Model.MaxBucketMagnitude)),
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1
},
{
label: 'Max Silence Magnitude',
data: [
{ x: @Html.Raw(Json.Serialize(Model.Labels[0])), y: @Html.Raw(Model.MaxSilenceMagnitude) },
{ x: @Html.Raw(Json.Serialize(Model.Labels[Model.Labels.Count - 1])), y: @Html.Raw(Model.MaxSilenceMagnitude) }
],
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 2,
fill: false,
pointRadius: 0 // Hide points on this line
},
{
label: 'Min Noise Magnitude',
data: [
{ x: @Html.Raw(Json.Serialize(Model.Labels[0])), y: @Html.Raw(Model.MinNoiseMagnitude) },
{ x: @Html.Raw(Json.Serialize(Model.Labels[Model.Labels.Count - 1])), y: @Html.Raw(Model.MinNoiseMagnitude) }
],
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 2,
fill: false,
pointRadius: 0 // Hide points on this line
}
]
},
options: {
scales: {
Expand Down
2 changes: 2 additions & 0 deletions OrcanodeMonitor/Pages/SpectralDensity.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class SpectralDensityModel : PageModel
public int MaxNonHumMagnitude { get; private set; }
public int SignalRatio { get; private set; }
public string Status { get; private set; }
public double MaxSilenceMagnitude => FrequencyInfo.MaxSilenceMagnitude;
public double MinNoiseMagnitude => FrequencyInfo.MinNoiseMagnitude;

public SpectralDensityModel(OrcanodeMonitorContext context, ILogger<SpectralDensityModel> logger)
{
Expand Down

0 comments on commit 1ddb6e8

Please sign in to comment.