fix some small bugs, add the ability to pause, add a resync timer
This commit is contained in:
parent
e696efbddd
commit
50043fd750
1 changed files with 50 additions and 9 deletions
|
@ -3,7 +3,6 @@ using System.IO.Ports;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
|
|
||||||
using SoundFlow.Abstracts;
|
|
||||||
using SoundFlow.Backends.MiniAudio;
|
using SoundFlow.Backends.MiniAudio;
|
||||||
using SoundFlow.Components;
|
using SoundFlow.Components;
|
||||||
using SoundFlow.Enums;
|
using SoundFlow.Enums;
|
||||||
|
@ -15,6 +14,8 @@ namespace ConsolePlayer
|
||||||
{
|
{
|
||||||
static SerialPort Port;
|
static SerialPort Port;
|
||||||
static System.Timers.Timer FrameTimer;
|
static System.Timers.Timer FrameTimer;
|
||||||
|
static System.Timers.Timer ResyncTimer;
|
||||||
|
static SoundPlayer AudioPlayer;
|
||||||
|
|
||||||
static int FramesPerTick = 6;
|
static int FramesPerTick = 6;
|
||||||
static int ShowtapeIndex = 0;
|
static int ShowtapeIndex = 0;
|
||||||
|
@ -26,6 +27,8 @@ namespace ConsolePlayer
|
||||||
static bool DetectedController = false;
|
static bool DetectedController = false;
|
||||||
static bool Playing = false;
|
static bool Playing = false;
|
||||||
static bool TripFlag = false;
|
static bool TripFlag = false;
|
||||||
|
static bool Paused = false;
|
||||||
|
static bool SyncMsg = false;
|
||||||
|
|
||||||
static string[] ShowtapeFrames;
|
static string[] ShowtapeFrames;
|
||||||
|
|
||||||
|
@ -65,19 +68,51 @@ namespace ConsolePlayer
|
||||||
FrameTimer.Elapsed += PlayFrame;
|
FrameTimer.Elapsed += PlayFrame;
|
||||||
FrameTimer.AutoReset = true;
|
FrameTimer.AutoReset = true;
|
||||||
|
|
||||||
using MiniAudioEngine audioEngine = new MiniAudioEngine(44100, Capability.Playback);
|
ResyncTimer = new System.Timers.Timer(15000);
|
||||||
|
ResyncTimer.Elapsed += Resync;
|
||||||
|
ResyncTimer.AutoReset = true;
|
||||||
|
|
||||||
|
using MiniAudioEngine audioEngine = new MiniAudioEngine(48000, Capability.Playback);
|
||||||
|
|
||||||
using StreamDataProvider dataProvider = new StreamDataProvider(File.OpenRead("pc3playertempaudio.tmp"));
|
using StreamDataProvider dataProvider = new StreamDataProvider(File.OpenRead("pc3playertempaudio.tmp"));
|
||||||
SoundPlayer player = new SoundPlayer(dataProvider);
|
AudioPlayer = new SoundPlayer(dataProvider);
|
||||||
|
|
||||||
Mixer.Master.AddComponent(player);
|
Mixer.Master.AddComponent(AudioPlayer);
|
||||||
|
|
||||||
Console.WriteLine($"Playing Showtape \"{ShowtapeName}\" ({ShowtapeFormattedLength})");
|
Console.WriteLine($"Playing Showtape \"{ShowtapeName}\" ({ShowtapeFormattedLength})");
|
||||||
|
Console.WriteLine("Controls:\n[SPACE] to pause and unpause\n[TAB] to toggle sync messages");
|
||||||
Playing = true;
|
Playing = true;
|
||||||
player.Play();
|
AudioPlayer.Play();
|
||||||
FrameTimer.Start();
|
FrameTimer.Start();
|
||||||
while (Playing) Thread.Sleep(1000);
|
ResyncTimer.Start();
|
||||||
Mixer.Master.RemoveComponent(player);
|
while (Playing)
|
||||||
|
{
|
||||||
|
ConsoleKeyInfo input = Console.ReadKey();
|
||||||
|
if (Playing)
|
||||||
|
{
|
||||||
|
if (input.Key == ConsoleKey.Spacebar)
|
||||||
|
{
|
||||||
|
if (Paused)
|
||||||
|
{
|
||||||
|
Paused = false;
|
||||||
|
FrameTimer.Start();
|
||||||
|
ResyncTimer.Start();
|
||||||
|
AudioPlayer.Seek((float)(((float)ShowtapeIndex) / 60.0));
|
||||||
|
AudioPlayer.Play();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Paused = true;
|
||||||
|
FrameTimer.Stop();
|
||||||
|
ResyncTimer.Stop();
|
||||||
|
AudioPlayer.Pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (input.Key == ConsoleKey.Tab) SyncMsg = !SyncMsg;
|
||||||
|
}
|
||||||
|
else if (!Playing) break;
|
||||||
|
}
|
||||||
|
Mixer.Master.RemoveComponent(AudioPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OpenSerialPortSpecific(string specifiedPortName)
|
static void OpenSerialPortSpecific(string specifiedPortName)
|
||||||
|
@ -155,7 +190,7 @@ namespace ConsolePlayer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception) {}
|
} catch (Exception) { continue; }
|
||||||
}
|
}
|
||||||
if (!DetectedController)
|
if (!DetectedController)
|
||||||
{
|
{
|
||||||
|
@ -256,12 +291,18 @@ namespace ConsolePlayer
|
||||||
{
|
{
|
||||||
FrameTimer.Stop();
|
FrameTimer.Stop();
|
||||||
Playing = false;
|
Playing = false;
|
||||||
Console.WriteLine("Complete!");
|
Console.WriteLine("Complete! Press any key to exit.");
|
||||||
if (File.Exists("pc3playertempaudio.tmp")) File.Delete("pc3playertempaudio.tmp");
|
if (File.Exists("pc3playertempaudio.tmp")) File.Delete("pc3playertempaudio.tmp");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Port.Write(ShowtapeFrames[ShowtapeIndex]);
|
Port.Write(ShowtapeFrames[ShowtapeIndex]);
|
||||||
ShowtapeIndex += FramesPerTick;
|
ShowtapeIndex += FramesPerTick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void Resync(Object sender, ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
if (SyncMsg) Console.WriteLine($"Resynced by {(int)(AudioPlayer.Time * 60) - ShowtapeIndex} frames");
|
||||||
|
ShowtapeIndex = (int)(AudioPlayer.Time * 60);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue