Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehjohn committed Aug 15, 2024
1 parent 8648a37 commit 93577c8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
12 changes: 5 additions & 7 deletions src/Zen.Desktop.Host/Infrastructure/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,18 @@ private void SetMotherboard(Model model)
_motherboard = null;
}

_motherboard = new Motherboard(model);
_motherboard = new Motherboard(model, AppSettings.Instance.AudioEngine switch
{
AudioEngine.Bass => new BassAudioEngine(),
_ => new PortAudioEngine()
});

_motherboard.AddPeripheral(new Peripherals.Keyboard());
_motherboard.AddPeripheral(new Peripherals.Kempston());
_motherboard.AddPeripheral(new Peripherals.DiskDrive());

_motherboard.Sound = AppSettings.Instance.Sound;

_motherboard.AudioEngine = AppSettings.Instance.AudioEngine switch
{
AudioEngine.Bass => new BassAudioEngine(),
_ => new PortAudioEngine()
};

_motherboard.Fast = AppSettings.Instance.Speed == Speed.Fast;
_motherboard.Slow = AppSettings.Instance.Speed == Speed.Slow;

Expand Down
13 changes: 10 additions & 3 deletions src/Zen.System/Modules/AyAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class AyAudio : IDisposable

private readonly MixerDac _mixerDac = new();

private IZenAudioEngine _engine = new PortAudioEngine();
private IZenAudioEngine _engine;

private readonly CancellationTokenSource _cancellationTokenSource;

Expand Down Expand Up @@ -56,7 +56,12 @@ public int BufferSize

public IZenAudioEngine AudioEngine
{
set => _engine = value;
set
{
_engine.Dispose();

_engine = value;
}
}

public bool Silent { get; set; }
Expand All @@ -65,8 +70,10 @@ public IZenAudioEngine AudioEngine

public Action<float>? BeeperSignalHook { get; set; }

public AyAudio()
public AyAudio(IZenAudioEngine engine)
{
_engine = engine;

_buffer = new float[_bufferSize];

_cancellationTokenSource = new CancellationTokenSource();
Expand Down
4 changes: 2 additions & 2 deletions src/Zen.System/Motherboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public IZenAudioEngine AudioEngine
set => _ayAudio.AudioEngine = value;
}

public Motherboard(Model model)
public Motherboard(Model model, IZenAudioEngine engine)
{
_model = model;

Expand All @@ -110,7 +110,7 @@ public Motherboard(Model model)

_videoModulator = new VideoModulator(_ram);

_ayAudio = new AyAudio();
_ayAudio = new AyAudio(engine);

_ayAudio.Start();

Expand Down

0 comments on commit 93577c8

Please sign in to comment.