using System; using System.Diagnostics; namespace BizHawk.Emulation.Sound { public sealed partial class YM2612 : ISoundProvider { public readonly Channel[] Channels; int frameStartClock; int frameEndClock; public YM2612() { Channels = new Channel[6]; Channels[0] = new Channel(); Channels[1] = new Channel(); Channels[2] = new Channel(); Channels[3] = new Channel(); Channels[4] = new Channel(); Channels[5] = new Channel(); InitTimers(); } public void Reset() { throw new Exception("something is resetting the ym2612"); } public void BeginFrame(int clock) { frameStartClock = clock; while (commands.Count > 0) { var cmd = commands.Dequeue(); WriteCommand(cmd); } } public void EndFrame(int clock) { frameEndClock = clock; } public void DiscardSamples() { } public int MaxVolume { get; set; } public void GetSamples(short[] samples) { int elapsedCycles = frameEndClock - frameStartClock; int start = 0; while (commands.Count > 0) { var cmd = commands.Dequeue(); int pos = ((cmd.Clock * samples.Length) / elapsedCycles) & ~1; GetSamplesImmediate(samples, start, pos - start); start = pos; WriteCommand(cmd); } GetSamplesImmediate(samples, start, samples.Length - start); } void GetSamplesImmediate(short[] samples, int pos, int length) { int channelVolume = MaxVolume / 6; for (int i=0; i