Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehjohn committed Aug 16, 2024
1 parent 0b2d6df commit e3c9245
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/Zen.Desktop.Host/Infrastructure/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private void SetMotherboard(Model model)
if (AppSettings.Instance.Speed == Speed.Locked)
{
_motherboard.Worker.Locked = true;
_motherboard.AyAudio.Locked = true;

TargetElapsedTime = TimeSpan.FromMilliseconds(20);
}
Expand Down Expand Up @@ -272,6 +273,7 @@ private void MenuFinished(MenuResult result, object arguments)
_motherboard.Fast = false;
_motherboard.Slow = false;
_motherboard.Worker.Locked = false;
_motherboard.AyAudio.Locked = false;

TargetElapsedTime = TimeSpan.FromTicks(166667L);

Expand All @@ -281,6 +283,7 @@ private void MenuFinished(MenuResult result, object arguments)
_motherboard.Fast = false;
_motherboard.Slow = false;
_motherboard.Worker.Locked = true;
_motherboard.AyAudio.Locked = true;

TargetElapsedTime = TimeSpan.FromMilliseconds(20);

Expand All @@ -290,7 +293,8 @@ private void MenuFinished(MenuResult result, object arguments)
_motherboard.Fast = true;
_motherboard.Slow = false;
_motherboard.Worker.Locked = false;

_motherboard.AyAudio.Locked = false;

TargetElapsedTime = TimeSpan.FromTicks(166667L);

break;
Expand All @@ -299,7 +303,8 @@ private void MenuFinished(MenuResult result, object arguments)
_motherboard.Fast = false;
_motherboard.Slow = true;
_motherboard.Worker.Locked = false;

_motherboard.AyAudio.Locked = false;

TargetElapsedTime = TimeSpan.FromTicks(166667L);

break;
Expand Down
17 changes: 15 additions & 2 deletions src/Zen.System/Modules/AyAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public IZenAudioEngine AudioEngine
get => _engine;
}

public bool Locked { get; set; }

public bool Silent { get; set; }

public Action<float[]>? AySignalHook { get; set; }
Expand All @@ -78,7 +80,18 @@ public AyAudio(IZenAudioEngine engine)

public void Start()
{
_audioThread = Task.Run(RunFrame, _cancellationToken);
_audioThread = Task.Run(() =>
{
if (! Locked)
{
RunFrameInternal();
}
}, _cancellationToken);
}

public void RunFrame()
{
RunFrameInternal();
}

public void FrameReady(ManualResetEvent resetEvent)
Expand Down Expand Up @@ -267,7 +280,7 @@ public void Dispose()
_engine.Dispose();
}

private void RunFrame()
private void RunFrameInternal()
{
var signals = new float[3];

Expand Down
5 changes: 5 additions & 0 deletions src/Zen.System/Modules/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ public void RunFrame()

_ayAudio.FrameReady(_resetEvent);

if (Locked)
{
_ayAudio.RunFrame();
}

_resetEvent.Reset();
}
catch (Exception exception)
Expand Down

0 comments on commit e3c9245

Please sign in to comment.