feat: mix music and microphone on one program output
Songs and the microphone now go through one audio channel, ProgramOutput, instead of each opening its own device. ProgramMixer builds two mixes in one pass: the broadcast for the listeners and a monitor mix for the person at the desk. With two playback devices each mix gets its own device; with one device the desk hears the monitor mix. The Schedule page gets a microphone button that works with or without a running broadcast, and sliders for the music and microphone levels on the broadcast, the music level on the monitor, and an option to hear the broadcast exactly. The Settings page lets the user choose the playback devices for the broadcast and for themselves. MusicPlayer plays its tracks into the mixer; pause takes the track out of the mix and resume puts it back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2380f233b5
commit
5d261717fe
14 files changed
+829
-89
No files matched your search
@@ -26,9 +26,9 @@ public sealed class MusicPlayerTests : IDisposable
|
||||
}
|
||||
|
||||
// Writes a short, quiet sine tone as 16-bit mono PCM.
|
||||
private string CreateWav(TimeSpan length)
|
||||
private string CreateWav(TimeSpan length, string name = "tone.wav")
|
||||
{
|
||||
var path = Path.Combine(_directory, "tone.wav");
|
||||
var path = Path.Combine(_directory, name);
|
||||
var format = new WaveFormat(44100, 16, 1);
|
||||
using var writer = new WaveFileWriter(path, format);
|
||||
var samples = (int)(format.SampleRate * length.TotalSeconds);
|
||||
@@ -37,6 +37,62 @@ public sealed class MusicPlayerTests : IDisposable
|
||||
return path;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProgramOutput_ConvertsInputsToItsFormat()
|
||||
{
|
||||
var mono = new NAudio.Wave.SampleProviders.SignalGenerator(22050, 1);
|
||||
|
||||
var converted = ProgramOutput.ToProgramFormat(mono);
|
||||
|
||||
Assert.Equal(44100, converted.WaveFormat.SampleRate);
|
||||
Assert.Equal(2, converted.WaveFormat.Channels);
|
||||
Assert.Same(ProgramOutput.Instance, ProgramOutput.Instance);
|
||||
Assert.Throws<NotSupportedException>(() => ProgramOutput.ToProgramFormat(new NAudio.Wave.SampleProviders.SignalGenerator(44100, 6)));
|
||||
}
|
||||
|
||||
[AudioDeviceFact]
|
||||
public void PauseAndResume_KeepThePosition()
|
||||
{
|
||||
var player = MusicPlayer.Instance;
|
||||
player.Play(CreateWav(TimeSpan.FromSeconds(3)));
|
||||
Thread.Sleep(400);
|
||||
|
||||
player.Pause();
|
||||
Assert.False(player.IsPlaying);
|
||||
var paused = player.Position;
|
||||
Thread.Sleep(300);
|
||||
Assert.Equal(paused, player.Position);
|
||||
|
||||
player.Resume();
|
||||
Assert.True(player.IsPlaying);
|
||||
Thread.Sleep(400);
|
||||
Assert.True(player.Position > paused);
|
||||
}
|
||||
|
||||
[AudioDeviceFact]
|
||||
public void Play_TwoTracksInARow_RaisesTrackFinishedOnlyForTheSecond()
|
||||
{
|
||||
var player = MusicPlayer.Instance;
|
||||
var finished = 0;
|
||||
using var done = new ManualResetEventSlim();
|
||||
EventHandler handler = (_, _) => { Interlocked.Increment(ref finished); done.Set(); };
|
||||
player.TrackFinished += handler;
|
||||
try
|
||||
{
|
||||
player.Play(CreateWav(TimeSpan.FromSeconds(2)));
|
||||
Thread.Sleep(200);
|
||||
player.Play(CreateWav(TimeSpan.FromSeconds(0.5), "second.wav"));
|
||||
|
||||
Assert.True(done.Wait(TimeSpan.FromSeconds(5)));
|
||||
Thread.Sleep(300);
|
||||
Assert.Equal(1, finished);
|
||||
}
|
||||
finally
|
||||
{
|
||||
player.TrackFinished -= handler;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Instance_ReturnsSameObjectOnRepeatedAccess()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user