Label runtime audio spectra
This commit is contained in:
parent
a07bb2c8cf
commit
31504718d9
6 changed files with 45 additions and 11 deletions
|
|
@ -7,6 +7,7 @@ public sealed record MimirAudioSpectrumBin(double FrequencyHz, double Decibels,
|
|||
|
||||
public sealed record MimirAudioSpectrumSnapshot(
|
||||
string SourceId,
|
||||
string Label,
|
||||
int SampleRate,
|
||||
int FftSize,
|
||||
int WindowSamples,
|
||||
|
|
@ -85,7 +86,7 @@ public sealed class MimirAudioSpectrumAnalyzer
|
|||
spectrum[index] = new Complex(window[index], 0.0);
|
||||
}
|
||||
|
||||
return AnalyzePreparedSpectrum(sourceId, sampleRate, written, edgeNs: 0);
|
||||
return AnalyzePreparedSpectrum(sourceId, sourceId, sampleRate, written, edgeNs: 0);
|
||||
}
|
||||
|
||||
private MimirAudioSpectrumSnapshot? AnalyzeBuffer(MimirRollingStreamBuffer buffer)
|
||||
|
|
@ -103,11 +104,12 @@ public sealed class MimirAudioSpectrumAnalyzer
|
|||
return null;
|
||||
}
|
||||
|
||||
return AnalyzePreparedSpectrum(buffer.Descriptor.SourceId, latestBlock.SampleRate, written, buffer.EdgeNs);
|
||||
return AnalyzePreparedSpectrum(buffer.Descriptor.SourceId, buffer.Descriptor.Label, latestBlock.SampleRate, written, buffer.EdgeNs);
|
||||
}
|
||||
|
||||
private MimirAudioSpectrumSnapshot AnalyzePreparedSpectrum(
|
||||
string sourceId,
|
||||
string label,
|
||||
int sampleRate,
|
||||
int written,
|
||||
long edgeNs)
|
||||
|
|
@ -136,6 +138,7 @@ public sealed class MimirAudioSpectrumAnalyzer
|
|||
var floor = bands.Count == 0 ? -120.0 : bands.OrderBy(value => value).ElementAt(Math.Clamp(bands.Count / 4, 0, bands.Count - 1));
|
||||
return new MimirAudioSpectrumSnapshot(
|
||||
sourceId,
|
||||
label,
|
||||
sampleRate,
|
||||
fftSize,
|
||||
written,
|
||||
|
|
|
|||
|
|
@ -101,7 +101,8 @@ public sealed class MimirRuntimeConfiguration
|
|||
stream.SourceId,
|
||||
ParseKind(stream.Kind),
|
||||
ParseOrigin(stream.Origin),
|
||||
stream.Enabled);
|
||||
stream.Enabled,
|
||||
stream.DisplayName);
|
||||
}
|
||||
|
||||
private static IEnumerable<MimirStreamDescriptor> ToDescriptors(MimirStreamConfig stream)
|
||||
|
|
@ -118,7 +119,8 @@ public sealed class MimirRuntimeConfiguration
|
|||
sourceId,
|
||||
ParseKind(stream.Kind),
|
||||
ParseOrigin(stream.Origin),
|
||||
stream.Enabled);
|
||||
stream.Enabled,
|
||||
stream.DisplayNameForSource(sourceId));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -282,6 +284,8 @@ public sealed class MimirStreamConfig
|
|||
{
|
||||
public string SourceId { get; set; } = "";
|
||||
|
||||
public string DisplayName { get; set; } = "";
|
||||
|
||||
public string Kind { get; set; } = "Video";
|
||||
|
||||
public string Origin { get; set; } = "LocalDevice";
|
||||
|
|
@ -296,9 +300,21 @@ public sealed class MimirStreamConfig
|
|||
|
||||
public string[] AcceptSourceIds { get; set; } = [];
|
||||
|
||||
public Dictionary<string, string> SourceLabels { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public int ChunkBytes { get; set; } = 65_536;
|
||||
|
||||
public int SampleRate { get; set; } = 192_000;
|
||||
|
||||
public string DriverClsid { get; set; } = "";
|
||||
|
||||
public string DisplayNameForSource(string sourceId)
|
||||
{
|
||||
if (SourceLabels.TryGetValue(sourceId, out var label) && !string.IsNullOrWhiteSpace(label))
|
||||
{
|
||||
return label.Trim();
|
||||
}
|
||||
|
||||
return sourceId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,12 @@ public sealed record MimirStreamDescriptor(
|
|||
string SourceId,
|
||||
MimirStreamKind Kind,
|
||||
MimirStreamOrigin Origin,
|
||||
bool Enabled = true)
|
||||
bool Enabled = true,
|
||||
string DisplayName = "")
|
||||
{
|
||||
public string BufferKey => $"{Kind}:{Origin}:{SourceId}";
|
||||
|
||||
public string Label => string.IsNullOrWhiteSpace(DisplayName)
|
||||
? SourceId
|
||||
: DisplayName;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue