diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 115d895efb..6e9a4fe243 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -998,7 +998,7 @@ namespace BizHawk.Client.EmuHawk //avi/wav state private IVideoWriter CurrAviWriter; private ISoundProvider AviSoundInput; - private Emulation.Sound.MetaspuSoundProvider DumpProxy; //an audio proxy used for dumping + private MetaspuSoundProvider DumpProxy; //an audio proxy used for dumping private long SoundRemainder; //audio timekeeping for video dumping private int avwriter_resizew; private int avwriter_resizeh; @@ -1412,7 +1412,7 @@ namespace BizHawk.Client.EmuHawk if (!Global.Emulator.StartAsyncSound()) { // if the core doesn't support async mode, use a standard vecna wrapper - GlobalWin.Sound.SetAsyncInputPin(new Emulation.Sound.MetaspuAsync(Global.Emulator.SyncSoundProvider, Emulation.Sound.ESynchMethod.ESynchMethod_V)); + GlobalWin.Sound.SetAsyncInputPin(new MetaspuAsync(Global.Emulator.SyncSoundProvider, ESynchMethod.ESynchMethod_V)); } else { @@ -2854,10 +2854,10 @@ namespace BizHawk.Client.EmuHawk // do sound rewire. the plan is to eventually have AVI writing support syncsound input, but it doesn't for the moment if (!Global.Emulator.StartAsyncSound()) - AviSoundInput = new Emulation.Sound.MetaspuAsync(Global.Emulator.SyncSoundProvider, Emulation.Sound.ESynchMethod.ESynchMethod_V); + AviSoundInput = new MetaspuAsync(Global.Emulator.SyncSoundProvider, ESynchMethod.ESynchMethod_V); else AviSoundInput = Global.Emulator.SoundProvider; - DumpProxy = new Emulation.Sound.MetaspuSoundProvider(Emulation.Sound.ESynchMethod.ESynchMethod_V); + DumpProxy = new MetaspuSoundProvider(ESynchMethod.ESynchMethod_V); SoundRemainder = 0; RewireSound(); } diff --git a/BizHawk.Client.EmuHawk/Sound.cs b/BizHawk.Client.EmuHawk/Sound.cs index 915c67291d..62388a2823 100644 --- a/BizHawk.Client.EmuHawk/Sound.cs +++ b/BizHawk.Client.EmuHawk/Sound.cs @@ -1,13 +1,13 @@ using System; -using BizHawk.Emulation.Sound; using System.Collections.Generic; + #if WINDOWS using SlimDX.DirectSound; using SlimDX.Multimedia; #endif -using BizHawk.Client.Common; using BizHawk.Emulation.Common; +using BizHawk.Client.Common; namespace BizHawk.Client.EmuHawk { diff --git a/BizHawk.Emulation/CPUs/MOS 6502X/Execute.cs b/BizHawk.Emulation/CPUs/MOS 6502X/Execute.cs index 0d3ce95e00..f0954fd4ca 100644 --- a/BizHawk.Emulation/CPUs/MOS 6502X/Execute.cs +++ b/BizHawk.Emulation/CPUs/MOS 6502X/Execute.cs @@ -12,20 +12,20 @@ namespace BizHawk.Emulation.Common.Components.M6502 //static ShortBuffer MicrocodeIndex; static MOS6502X() { - // int index = 0; - // MicrocodeIndex = new ShortBuffer(VOP_NUM); - // List temp = new List(); - // for (int i = 0; i < VOP_NUM; i++) - // { - // MicrocodeIndex[i] = (short)index; - // int numUops = Microcode[i].Length; - // for (int j = 0; j < numUops; j++) - // temp.Add(Microcode[i][j]); - // index += numUops; - // } - // CompiledMicrocode = new ShortBuffer(temp.Count); - // for (int i = 0; i < temp.Count; i++) - // CompiledMicrocode[i] = (short)temp[i]; + // int index = 0; + // MicrocodeIndex = new ShortBuffer(VOP_NUM); + // List temp = new List(); + // for (int i = 0; i < VOP_NUM; i++) + // { + // MicrocodeIndex[i] = (short)index; + // int numUops = Microcode[i].Length; + // for (int j = 0; j < numUops; j++) + // temp.Add(Microcode[i][j]); + // index += numUops; + // } + // CompiledMicrocode = new ShortBuffer(temp.Count); + // for (int i = 0; i < temp.Count; i++) + // CompiledMicrocode[i] = (short)temp[i]; } static Uop[][] Microcode = new Uop[][] @@ -513,7 +513,7 @@ namespace BizHawk.Emulation.Common.Components.M6502 int ea, alu_temp; //cpu internal temp variables int mi; //microcode index bool iflag_pending; //iflag must be stored after it is checked in some cases (CLI and SEI). - bool rdy_freeze; //true if the CPU must be frozen + bool rdy_freeze; //true if the CPU must be frozen //tracks whether an interrupt condition has popped up recently. //not sure if this is real or not but it helps with the branch_irq_hack @@ -584,31 +584,31 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void Fetch1_Real() { - rdy_freeze = !RDY; - if (RDY) - { - if (debug) Console.WriteLine(State()); - branch_irq_hack = false; - if (OnExecFetch != null) OnExecFetch(PC); - opcode = ReadMemory(PC++); - mi = -1; - } + rdy_freeze = !RDY; + if (RDY) + { + if (debug) Console.WriteLine(State()); + branch_irq_hack = false; + if (OnExecFetch != null) OnExecFetch(PC); + opcode = ReadMemory(PC++); + mi = -1; + } } void Fetch2() { - rdy_freeze = !RDY; - if (RDY) - { - opcode2 = ReadMemory(PC++); - } + rdy_freeze = !RDY; + if (RDY) + { + opcode2 = ReadMemory(PC++); + } } void Fetch3() { - rdy_freeze = !RDY; - if (RDY) - { - opcode3 = ReadMemory(PC++); - } + rdy_freeze = !RDY; + if (RDY) + { + opcode3 = ReadMemory(PC++); + } } void PushPCH() { @@ -656,64 +656,64 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void FetchPCLVector() { - rdy_freeze = !RDY; - if (RDY) - { - if (ea == BRKVector && FlagB && NMI) - { - NMI = false; - ea = NMIVector; - } - if (ea == IRQVector && !FlagB && NMI) - { - NMI = false; - ea = NMIVector; - } - alu_temp = ReadMemory((ushort)ea); - } + rdy_freeze = !RDY; + if (RDY) + { + if (ea == BRKVector && FlagB && NMI) + { + NMI = false; + ea = NMIVector; + } + if (ea == IRQVector && !FlagB && NMI) + { + NMI = false; + ea = NMIVector; + } + alu_temp = ReadMemory((ushort)ea); + } } void FetchPCHVector() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp += ReadMemory((ushort)(ea + 1)) << 8; - PC = (ushort)alu_temp; - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp += ReadMemory((ushort)(ea + 1)) << 8; + PC = (ushort)alu_temp; + } } void Imp_INY() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); Y++; NZ_Y(); - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); Y++; NZ_Y(); + } } void Imp_DEY() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); Y--; NZ_Y(); - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); Y--; NZ_Y(); + } } void Imp_INX() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); X++; NZ_X(); - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); X++; NZ_X(); + } } void Imp_DEX() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); X--; NZ_X(); - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); X--; NZ_X(); + } } void NZ_A() { @@ -730,108 +730,108 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void Imp_TSX() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); X = S; NZ_X(); - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); X = S; NZ_X(); + } } void Imp_TXS() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); S = X; - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); S = X; + } } void Imp_TAX() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); X = A; NZ_X(); - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); X = A; NZ_X(); + } } void Imp_TAY() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); Y = A; NZ_Y(); - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); Y = A; NZ_Y(); + } } void Imp_TYA() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); A = Y; NZ_A(); - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); A = Y; NZ_A(); + } } void Imp_TXA() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); A = X; NZ_A(); - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); A = X; NZ_A(); + } } void Imp_SEI() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); iflag_pending = true; - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); iflag_pending = true; + } } void Imp_CLI() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); iflag_pending = false; - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); iflag_pending = false; + } } void Imp_SEC() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); FlagC = true; - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); FlagC = true; + } } void Imp_CLC() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); FlagC = false; - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); FlagC = false; + } } void Imp_SED() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); FlagD = true; - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); FlagD = true; + } } void Imp_CLD() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); FlagD = false; - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); FlagD = false; + } } void Imp_CLV() { - rdy_freeze = !RDY; - if (RDY) - { - FetchDummy(); FlagV = false; - } + rdy_freeze = !RDY; + if (RDY) + { + FetchDummy(); FlagV = false; + } } void Abs_WRITE_STA() @@ -870,61 +870,61 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void IndIdx_Stage3() { - rdy_freeze = !RDY; - if (RDY) - { - ea = ReadMemory(opcode2); - } + rdy_freeze = !RDY; + if (RDY) + { + ea = ReadMemory(opcode2); + } } void IndIdx_Stage4() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ea + Y; - ea = (ReadMemory((byte)(opcode2 + 1)) << 8) - | ((alu_temp & 0xFF)); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ea + Y; + ea = (ReadMemory((byte)(opcode2 + 1)) << 8) + | ((alu_temp & 0xFF)); + } } void IndIdx_WRITE_Stage5() { - rdy_freeze = !RDY; - if (RDY) - { - ReadMemory((ushort)ea); - ea += (alu_temp >> 8) << 8; - } + rdy_freeze = !RDY; + if (RDY) + { + ReadMemory((ushort)ea); + ea += (alu_temp >> 8) << 8; + } } void IndIdx_READ_Stage5() { - rdy_freeze = !RDY; - if (RDY) - { - if (!alu_temp.Bit(8)) - { - mi++; - ExecuteOneRetry(); - return; - } - else - { - ReadMemory((ushort)ea); - ea = (ushort)(ea + 0x100); - } - } + rdy_freeze = !RDY; + if (RDY) + { + if (!alu_temp.Bit(8)) + { + mi++; + ExecuteOneRetry(); + return; + } + else + { + ReadMemory((ushort)ea); + ea = (ushort)(ea + 0x100); + } + } } void IndIdx_RMW_Stage5() { - rdy_freeze = !RDY; - if (RDY) - { - if (alu_temp.Bit(8)) - ea = (ushort)(ea + 0x100); - ReadMemory((ushort)ea); - } + rdy_freeze = !RDY; + if (RDY) + { + if (alu_temp.Bit(8)) + ea = (ushort)(ea + 0x100); + ReadMemory((ushort)ea); + } } void IndIdx_WRITE_Stage6_STA() @@ -939,83 +939,83 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void IndIdx_READ_Stage6_LDA() { - rdy_freeze = !RDY; - if (RDY) - { - A = ReadMemory((ushort)ea); - NZ_A(); - } + rdy_freeze = !RDY; + if (RDY) + { + A = ReadMemory((ushort)ea); + NZ_A(); + } } void IndIdx_READ_Stage6_CMP() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _Cmp(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _Cmp(); + } } void IndIdx_READ_Stage6_AND() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _And(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _And(); + } } void IndIdx_READ_Stage6_EOR() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _Eor(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _Eor(); + } } void IndIdx_READ_Stage6_LAX() { - rdy_freeze = !RDY; - if (RDY) - { - A = X = ReadMemory((ushort)ea); - NZ_A(); - } + rdy_freeze = !RDY; + if (RDY) + { + A = X = ReadMemory((ushort)ea); + NZ_A(); + } } void IndIdx_READ_Stage6_ADC() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _Adc(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _Adc(); + } } void IndIdx_READ_Stage6_SBC() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _Sbc(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _Sbc(); + } } void IndIdx_READ_Stage6_ORA() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _Ora(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _Ora(); + } } void IndIdx_RMW_Stage6() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + } } void IndIdx_RMW_Stage7_SLO() @@ -1117,18 +1117,18 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void RelBranch_Stage2() { - rdy_freeze = !RDY; - if (RDY) - { - opcode2 = ReadMemory(PC++); - if (branch_taken) - { - branch_taken = false; - //if the branch is taken, we enter a different bit of microcode to calculate the PC and complete the branch - opcode = VOP_RelativeStuff; - mi = -1; - } - } + rdy_freeze = !RDY; + if (RDY) + { + opcode2 = ReadMemory(PC++); + if (branch_taken) + { + branch_taken = false; + //if the branch is taken, we enter a different bit of microcode to calculate the PC and complete the branch + opcode = VOP_RelativeStuff; + mi = -1; + } + } } void RelBranch_Stage3() @@ -1174,198 +1174,198 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void JSR() { - rdy_freeze = !RDY; - if (RDY) - { - PC = (ushort)((ReadMemory((ushort)(PC)) << 8) + opcode2); - } + rdy_freeze = !RDY; + if (RDY) + { + PC = (ushort)((ReadMemory((ushort)(PC)) << 8) + opcode2); + } } void PullP() { - rdy_freeze = !RDY; - if (RDY) - { - P = ReadMemory((ushort)(S++ + 0x100)); - FlagT = true; //force T always to remain true - } + rdy_freeze = !RDY; + if (RDY) + { + P = ReadMemory((ushort)(S++ + 0x100)); + FlagT = true; //force T always to remain true + } } void PullPCL() { - rdy_freeze = !RDY; - if (RDY) - { - PC &= 0xFF00; - PC |= ReadMemory((ushort)(S++ + 0x100)); - } + rdy_freeze = !RDY; + if (RDY) + { + PC &= 0xFF00; + PC |= ReadMemory((ushort)(S++ + 0x100)); + } } void PullPCH_NoInc() { - rdy_freeze = !RDY; - if (RDY) - { - PC &= 0xFF; - PC |= (ushort)(ReadMemory((ushort)(S + 0x100)) << 8); - } + rdy_freeze = !RDY; + if (RDY) + { + PC &= 0xFF; + PC |= (ushort)(ReadMemory((ushort)(S + 0x100)) << 8); + } } void Abs_READ_LDA() { - rdy_freeze = !RDY; - if (RDY) - { - A = ReadMemory((ushort)((opcode3 << 8) + opcode2)); - NZ_A(); - } + rdy_freeze = !RDY; + if (RDY) + { + A = ReadMemory((ushort)((opcode3 << 8) + opcode2)); + NZ_A(); + } } void Abs_READ_LDY() { - rdy_freeze = !RDY; - if (RDY) - { - Y = ReadMemory((ushort)((opcode3 << 8) + opcode2)); - NZ_Y(); - } + rdy_freeze = !RDY; + if (RDY) + { + Y = ReadMemory((ushort)((opcode3 << 8) + opcode2)); + NZ_Y(); + } } void Abs_READ_LDX() { - rdy_freeze = !RDY; - if (RDY) - { - X = ReadMemory((ushort)((opcode3 << 8) + opcode2)); - NZ_X(); - } + rdy_freeze = !RDY; + if (RDY) + { + X = ReadMemory((ushort)((opcode3 << 8) + opcode2)); + NZ_X(); + } } void Abs_READ_BIT() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); - _Bit(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); + _Bit(); + } } void Abs_READ_LAX() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); - A = ReadMemory((ushort)((opcode3 << 8) + opcode2)); - X = A; - NZ_A(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); + A = ReadMemory((ushort)((opcode3 << 8) + opcode2)); + X = A; + NZ_A(); + } } void Abs_READ_AND() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); - _And(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); + _And(); + } } void Abs_READ_EOR() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); - _Eor(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); + _Eor(); + } } void Abs_READ_ORA() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); - _Ora(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); + _Ora(); + } } void Abs_READ_ADC() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); - _Adc(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); + _Adc(); + } } void Abs_READ_CMP() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); - _Cmp(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); + _Cmp(); + } } void Abs_READ_CPY() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); - _Cpy(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); + _Cpy(); + } } void Abs_READ_NOP() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); + } } void Abs_READ_CPX() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); - _Cpx(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); + _Cpx(); + } } void Abs_READ_SBC() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); - _Sbc(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)((opcode3 << 8) + opcode2)); + _Sbc(); + } } void ZpIdx_Stage3_X() { - rdy_freeze = !RDY; - if (RDY) - { - ReadMemory(opcode2); - opcode2 = (byte)(opcode2 + X); //a bit sneaky to shove this into opcode2... but we can reuse all the zero page uops if we do that - } + rdy_freeze = !RDY; + if (RDY) + { + ReadMemory(opcode2); + opcode2 = (byte)(opcode2 + X); //a bit sneaky to shove this into opcode2... but we can reuse all the zero page uops if we do that + } } void ZpIdx_Stage3_Y() { - rdy_freeze = !RDY; - if (RDY) - { - ReadMemory(opcode2); - opcode2 = (byte)(opcode2 + Y); //a bit sneaky to shove this into opcode2... but we can reuse all the zero page uops if we do that - } + rdy_freeze = !RDY; + if (RDY) + { + ReadMemory(opcode2); + opcode2 = (byte)(opcode2 + Y); //a bit sneaky to shove this into opcode2... but we can reuse all the zero page uops if we do that + } } void ZpIdx_RMW_Stage4() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(opcode2); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(opcode2); + } } void ZpIdx_RMW_Stage6() @@ -1376,131 +1376,131 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void ZP_READ_EOR() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(opcode2); - _Eor(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(opcode2); + _Eor(); + } } void ZP_READ_BIT() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(opcode2); - _Bit(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(opcode2); + _Bit(); + } } void ZP_READ_LDA() { - rdy_freeze = !RDY; - if (RDY) - { - A = ReadMemory(opcode2); - NZ_A(); - } + rdy_freeze = !RDY; + if (RDY) + { + A = ReadMemory(opcode2); + NZ_A(); + } } void ZP_READ_LDY() { - rdy_freeze = !RDY; - if (RDY) - { - Y = ReadMemory(opcode2); - NZ_Y(); - } + rdy_freeze = !RDY; + if (RDY) + { + Y = ReadMemory(opcode2); + NZ_Y(); + } } void ZP_READ_LDX() { - rdy_freeze = !RDY; - if (RDY) - { - X = ReadMemory(opcode2); - NZ_X(); - } + rdy_freeze = !RDY; + if (RDY) + { + X = ReadMemory(opcode2); + NZ_X(); + } } void ZP_READ_LAX() { - rdy_freeze = !RDY; - if (RDY) - { - //?? is this right?? - X = ReadMemory(opcode2); - A = X; - NZ_A(); - } + rdy_freeze = !RDY; + if (RDY) + { + //?? is this right?? + X = ReadMemory(opcode2); + A = X; + NZ_A(); + } } void ZP_READ_CPY() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(opcode2); - _Cpy(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(opcode2); + _Cpy(); + } } void ZP_READ_CMP() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(opcode2); - _Cmp(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(opcode2); + _Cmp(); + } } void ZP_READ_CPX() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(opcode2); - _Cpx(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(opcode2); + _Cpx(); + } } void ZP_READ_ORA() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(opcode2); - _Ora(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(opcode2); + _Ora(); + } } void ZP_READ_NOP() { - rdy_freeze = !RDY; - if (RDY) - { - ReadMemory(opcode2); //just a dummy - } + rdy_freeze = !RDY; + if (RDY) + { + ReadMemory(opcode2); //just a dummy + } } void ZP_READ_SBC() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(opcode2); - _Sbc(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(opcode2); + _Sbc(); + } } void ZP_READ_ADC() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(opcode2); - _Adc(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(opcode2); + _Adc(); + } } void ZP_READ_AND() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(opcode2); - _And(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(opcode2); + _And(); + } } void _Cpx() @@ -1657,257 +1657,257 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void Imm_EOR() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(PC++); - _Eor(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(PC++); + _Eor(); + } } void Imm_ANC() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(PC++); - _Anc(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(PC++); + _Anc(); + } } void Imm_ASR() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(PC++); - _Asr(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(PC++); + _Asr(); + } } void Imm_AXS() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(PC++); - _Axs(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(PC++); + _Axs(); + } } void Imm_ARR() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(PC++); - _Arr(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(PC++); + _Arr(); + } } void Imm_LXA() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(PC++); - _Lxa(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(PC++); + _Lxa(); + } } void Imm_ORA() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(PC++); - _Ora(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(PC++); + _Ora(); + } } void Imm_CPY() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(PC++); - _Cpy(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(PC++); + _Cpy(); + } } void Imm_CPX() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(PC++); - _Cpx(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(PC++); + _Cpx(); + } } void Imm_CMP() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(PC++); - _Cmp(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(PC++); + _Cmp(); + } } void Imm_SBC() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(PC++); - _Sbc(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(PC++); + _Sbc(); + } } void Imm_AND() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(PC++); - _And(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(PC++); + _And(); + } } void Imm_ADC() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(PC++); - _Adc(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(PC++); + _Adc(); + } } void Imm_LDA() { - rdy_freeze = !RDY; - if (RDY) - { - A = ReadMemory(PC++); - NZ_A(); - } + rdy_freeze = !RDY; + if (RDY) + { + A = ReadMemory(PC++); + NZ_A(); + } } void Imm_LDX() { - rdy_freeze = !RDY; - if (RDY) - { - X = ReadMemory(PC++); - NZ_X(); - } + rdy_freeze = !RDY; + if (RDY) + { + X = ReadMemory(PC++); + NZ_X(); + } } void Imm_LDY() { - rdy_freeze = !RDY; - if (RDY) - { - Y = ReadMemory(PC++); - NZ_Y(); - } + rdy_freeze = !RDY; + if (RDY) + { + Y = ReadMemory(PC++); + NZ_Y(); + } } void Imm_Unsupported() { - rdy_freeze = !RDY; - if (RDY) - { - ReadMemory(PC++); - } + rdy_freeze = !RDY; + if (RDY) + { + ReadMemory(PC++); + } } void IdxInd_Stage3() { - rdy_freeze = !RDY; - if (RDY) - { - ReadMemory(opcode2); //dummy? - alu_temp = (opcode2 + X) & 0xFF; - } + rdy_freeze = !RDY; + if (RDY) + { + ReadMemory(opcode2); //dummy? + alu_temp = (opcode2 + X) & 0xFF; + } } void IdxInd_Stage4() { - rdy_freeze = !RDY; - if (RDY) - { - ea = ReadMemory((ushort)alu_temp); - } + rdy_freeze = !RDY; + if (RDY) + { + ea = ReadMemory((ushort)alu_temp); + } } void IdxInd_Stage5() { - rdy_freeze = !RDY; - if (RDY) - { - ea += (ReadMemory((byte)(alu_temp + 1)) << 8); - } + rdy_freeze = !RDY; + if (RDY) + { + ea += (ReadMemory((byte)(alu_temp + 1)) << 8); + } } void IdxInd_Stage6_READ_LDA() { - rdy_freeze = !RDY; - if (RDY) - { - //TODO make uniform with others - A = ReadMemory((ushort)ea); - NZ_A(); - } + rdy_freeze = !RDY; + if (RDY) + { + //TODO make uniform with others + A = ReadMemory((ushort)ea); + NZ_A(); + } } void IdxInd_Stage6_READ_ORA() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _Ora(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _Ora(); + } } void IdxInd_Stage6_READ_LAX() { - rdy_freeze = !RDY; - if (RDY) - { - A = X = ReadMemory((ushort)ea); - NZ_A(); - } + rdy_freeze = !RDY; + if (RDY) + { + A = X = ReadMemory((ushort)ea); + NZ_A(); + } } void IdxInd_Stage6_READ_CMP() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _Cmp(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _Cmp(); + } } void IdxInd_Stage6_READ_ADC() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _Adc(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _Adc(); + } } void IdxInd_Stage6_READ_AND() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _And(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _And(); + } } void IdxInd_Stage6_READ_EOR() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _Eor(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _Eor(); + } } void IdxInd_Stage6_READ_SBC() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _Sbc(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _Sbc(); + } } void IdxInd_Stage6_WRITE_STA() { @@ -1923,11 +1923,11 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void IdxInd_Stage6_RMW() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + } } void IdxInd_Stage7_RMW_SLO() @@ -1999,17 +1999,17 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void PullA_NoInc() { - rdy_freeze = !RDY; - if (RDY) - { - A = ReadMemory((ushort)(S + 0x100)); - NZ_A(); - } + rdy_freeze = !RDY; + if (RDY) + { + A = ReadMemory((ushort)(S + 0x100)); + NZ_A(); + } } void PullP_NoInc() { - rdy_freeze = !RDY; - if (RDY) + rdy_freeze = !RDY; + if (RDY) { my_iflag = FlagI; P = ReadMemory((ushort)(S + 0x100)); @@ -2053,11 +2053,11 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void JMP_abs() { - rdy_freeze = !RDY; - if (RDY) - { - PC = (ushort)((ReadMemory(PC) << 8) + opcode2); - } + rdy_freeze = !RDY; + if (RDY) + { + PC = (ushort)((ReadMemory(PC) << 8) + opcode2); + } } void IncPC() @@ -2068,11 +2068,11 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void ZP_RMW_Stage3() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory(opcode2); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory(opcode2); + } } void ZP_RMW_Stage5() @@ -2183,59 +2183,59 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void AbsIdx_Stage3_Y() { - rdy_freeze = !RDY; - if (RDY) - { - opcode3 = ReadMemory(PC++); - alu_temp = opcode2 + Y; - ea = (opcode3 << 8) + (alu_temp & 0xFF); + rdy_freeze = !RDY; + if (RDY) + { + opcode3 = ReadMemory(PC++); + alu_temp = opcode2 + Y; + ea = (opcode3 << 8) + (alu_temp & 0xFF); - //new Uop[] { Uop.Fetch2, Uop.AbsIdx_Stage3_Y, Uop.AbsIdx_Stage4, Uop.AbsIdx_WRITE_Stage5_STA, Uop.End }, - } + //new Uop[] { Uop.Fetch2, Uop.AbsIdx_Stage3_Y, Uop.AbsIdx_Stage4, Uop.AbsIdx_WRITE_Stage5_STA, Uop.End }, + } } void AbsIdx_Stage3_X() { - rdy_freeze = !RDY; - if (RDY) - { - opcode3 = ReadMemory(PC++); - alu_temp = opcode2 + X; - ea = (opcode3 << 8) + (alu_temp & 0xFF); - } + rdy_freeze = !RDY; + if (RDY) + { + opcode3 = ReadMemory(PC++); + alu_temp = opcode2 + X; + ea = (opcode3 << 8) + (alu_temp & 0xFF); + } } void AbsIdx_READ_Stage4() { - rdy_freeze = !RDY; - if (RDY) - { - if (!alu_temp.Bit(8)) - { - mi++; - ExecuteOneRetry(); - return; - } - else - { - alu_temp = ReadMemory((ushort)ea); - ea = (ushort)(ea + 0x100); - } - } + rdy_freeze = !RDY; + if (RDY) + { + if (!alu_temp.Bit(8)) + { + mi++; + ExecuteOneRetry(); + return; + } + else + { + alu_temp = ReadMemory((ushort)ea); + ea = (ushort)(ea + 0x100); + } + } } void AbsIdx_Stage4() { - rdy_freeze = !RDY; - if (RDY) - { - //bleh.. redundant code to make sure we dont clobber alu_temp before using it to decide whether to change ea - if (alu_temp.Bit(8)) - { - alu_temp = ReadMemory((ushort)ea); - ea = (ushort)(ea + 0x100); - } - else alu_temp = ReadMemory((ushort)ea); - } + rdy_freeze = !RDY; + if (RDY) + { + //bleh.. redundant code to make sure we dont clobber alu_temp before using it to decide whether to change ea + if (alu_temp.Bit(8)) + { + alu_temp = ReadMemory((ushort)ea); + ea = (ushort)(ea + 0x100); + } + else alu_temp = ReadMemory((ushort)ea); + } } void AbsIdx_WRITE_Stage5_STA() @@ -2259,21 +2259,21 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void AbsIdx_WRITE_Stage5_ERROR() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - //throw new InvalidOperationException("UNSUPPORTED OPCODE [probably SHS] PLEASE REPORT"); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + //throw new InvalidOperationException("UNSUPPORTED OPCODE [probably SHS] PLEASE REPORT"); + } } void AbsIdx_RMW_Stage5() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + } } void AbsIdx_RMW_Stage7() @@ -2381,142 +2381,142 @@ namespace BizHawk.Emulation.Common.Components.M6502 } void AbsIdx_READ_Stage5_LDA() { - rdy_freeze = !RDY; - if (RDY) - { - A = ReadMemory((ushort)ea); - NZ_A(); - } + rdy_freeze = !RDY; + if (RDY) + { + A = ReadMemory((ushort)ea); + NZ_A(); + } } void AbsIdx_READ_Stage5_LDX() { - rdy_freeze = !RDY; - if (RDY) - { - X = ReadMemory((ushort)ea); - NZ_X(); - } + rdy_freeze = !RDY; + if (RDY) + { + X = ReadMemory((ushort)ea); + NZ_X(); + } } void AbsIdx_READ_Stage5_LAX() { - rdy_freeze = !RDY; - if (RDY) - { - A = ReadMemory((ushort)ea); - X = A; - NZ_A(); - } + rdy_freeze = !RDY; + if (RDY) + { + A = ReadMemory((ushort)ea); + X = A; + NZ_A(); + } } void AbsIdx_READ_Stage5_LDY() { - rdy_freeze = !RDY; - if (RDY) - { - Y = ReadMemory((ushort)ea); - NZ_Y(); - } + rdy_freeze = !RDY; + if (RDY) + { + Y = ReadMemory((ushort)ea); + NZ_Y(); + } } void AbsIdx_READ_Stage5_ORA() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _Ora(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _Ora(); + } } void AbsIdx_READ_Stage5_NOP() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + } } void AbsIdx_READ_Stage5_CMP() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _Cmp(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _Cmp(); + } } void AbsIdx_READ_Stage5_SBC() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _Sbc(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _Sbc(); + } } void AbsIdx_READ_Stage5_ADC() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _Adc(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _Adc(); + } } void AbsIdx_READ_Stage5_EOR() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _Eor(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _Eor(); + } } void AbsIdx_READ_Stage5_AND() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - _And(); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + _And(); + } } void AbsIdx_READ_Stage5_ERROR() { - rdy_freeze = !RDY; - if (RDY) - { - alu_temp = ReadMemory((ushort)ea); - //throw new InvalidOperationException("UNSUPPORTED OPCODE [probably LAS] PLEASE REPORT"); - } + rdy_freeze = !RDY; + if (RDY) + { + alu_temp = ReadMemory((ushort)ea); + //throw new InvalidOperationException("UNSUPPORTED OPCODE [probably LAS] PLEASE REPORT"); + } } void AbsInd_JMP_Stage4() { - rdy_freeze = !RDY; - if (RDY) - { - ea = (opcode3 << 8) + opcode2; - alu_temp = ReadMemory((ushort)ea); - } + rdy_freeze = !RDY; + if (RDY) + { + ea = (opcode3 << 8) + opcode2; + alu_temp = ReadMemory((ushort)ea); + } } void AbsInd_JMP_Stage5() { - rdy_freeze = !RDY; - if (RDY) - { - ea = (opcode3 << 8) + (byte)(opcode2 + 1); - alu_temp += ReadMemory((ushort)ea) << 8; - PC = (ushort)alu_temp; - } + rdy_freeze = !RDY; + if (RDY) + { + ea = (opcode3 << 8) + (byte)(opcode2 + 1); + alu_temp += ReadMemory((ushort)ea) << 8; + PC = (ushort)alu_temp; + } } void Abs_RMW_Stage4() { - rdy_freeze = !RDY; - if (RDY) - { - ea = (opcode3 << 8) + opcode2; - alu_temp = ReadMemory((ushort)ea); - } + rdy_freeze = !RDY; + if (RDY) + { + ea = (opcode3 << 8) + opcode2; + alu_temp = ReadMemory((ushort)ea); + } } void Abs_RMW_Stage5_INC() @@ -2914,19 +2914,19 @@ namespace BizHawk.Emulation.Common.Components.M6502 public void ExecuteOne() { - if (!rdy_freeze) - { - TotalExecutedCycles++; + if (!rdy_freeze) + { + TotalExecutedCycles++; - interrupt_pending |= Interrupted; - } - rdy_freeze = false; - - //i tried making ExecuteOneRetry not re-entrant by having it set a flag instead, then exit from the call below, check the flag, and GOTO if it was flagged, but it wasnt faster + interrupt_pending |= Interrupted; + } + rdy_freeze = false; + + //i tried making ExecuteOneRetry not re-entrant by having it set a flag instead, then exit from the call below, check the flag, and GOTO if it was flagged, but it wasnt faster ExecuteOneRetry(); - if (!rdy_freeze) - mi++; + if (!rdy_freeze) + mi++; } //ExecuteOne } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs index bad7dee90a..9a520f1d09 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs @@ -1,5 +1,7 @@ using System; + using BizHawk.Common; +using BizHawk.Emulation.Common; #pragma warning disable 649 //adelikat: Disable dumb warnings until this file is complete #pragma warning disable 169 //adelikat: Disable dumb warnings until this file is complete @@ -14,12 +16,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 // ------------------------------------ - public Sound.Utilities.SpeexResampler resampler; + public SpeexResampler resampler; static int[] syncNextTable = new int[] { 1, 2, 0 }; static int[] syncPrevTable = new int[] { 2, 0, 1 }; - int cachedCycles; + int cachedCycles; bool disableVoice3; int[] envelopeOutput; Envelope[] envelopes; @@ -29,12 +31,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 bool filterSelectBandPass; bool filterSelectLoPass; bool filterSelectHiPass; - int mixer; - int potCounter; + int mixer; + int potCounter; int potX; - int potY; - short sample; - int[] voiceOutput; + int potY; + short sample; + int[] voiceOutput; Voice[] voices; int volume; int[][] waveformTable; @@ -45,15 +47,15 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 public Sid(int[][] newWaveformTable, int newSampleRate, Region newRegion) { uint cyclesPerSec = 0; - uint cyclesNum; - uint cyclesDen; - uint sampleRate = 44100; + uint cyclesNum; + uint cyclesDen; + uint sampleRate = 44100; switch (newRegion) { - case Region.NTSC: cyclesNum = 14318181; cyclesDen = 14; break; + case Region.NTSC: cyclesNum = 14318181; cyclesDen = 14; break; case Region.PAL: cyclesNum = 17734472; cyclesDen = 18; break; - default: return; + default: return; } waveformTable = newWaveformTable; @@ -72,7 +74,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 for (int i = 0; i < 3; i++) filterEnable[i] = false; - resampler = new Sound.Utilities.SpeexResampler(0, cyclesNum, sampleRate * cyclesDen, cyclesNum, sampleRate * cyclesDen, null, null); + resampler = new SpeexResampler(0, cyclesNum, sampleRate * cyclesDen, cyclesNum, sampleRate * cyclesDen, null, null); } public void Dispose() @@ -100,55 +102,55 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 // ------------------------------------ - public void ExecutePhase2() + public void ExecutePhase2() { - cachedCycles++; + cachedCycles++; - // potentiometer values refresh every 512 cycles - if (potCounter == 0) - { - potCounter = 512; - potX = ReadPotX(); - potY = ReadPotY(); - Flush(); //this is here unrelated to the pots, just to keep the buffer somewhat loaded - } - potCounter--; - } + // potentiometer values refresh every 512 cycles + if (potCounter == 0) + { + potCounter = 512; + potX = ReadPotX(); + potY = ReadPotY(); + Flush(); //this is here unrelated to the pots, just to keep the buffer somewhat loaded + } + potCounter--; + } - public void Flush() - { - while (cachedCycles > 0) - { - // process voices and envelopes - voices[0].ExecutePhase2(); - voices[1].ExecutePhase2(); - voices[2].ExecutePhase2(); - envelopes[0].ExecutePhase2(); - envelopes[1].ExecutePhase2(); - envelopes[2].ExecutePhase2(); + public void Flush() + { + while (cachedCycles > 0) + { + // process voices and envelopes + voices[0].ExecutePhase2(); + voices[1].ExecutePhase2(); + voices[2].ExecutePhase2(); + envelopes[0].ExecutePhase2(); + envelopes[1].ExecutePhase2(); + envelopes[2].ExecutePhase2(); - // process sync - for (int i = 0; i < 3; i++) - voices[i].Synchronize(voices[syncNextTable[i]], voices[syncPrevTable[i]]); + // process sync + for (int i = 0; i < 3; i++) + voices[i].Synchronize(voices[syncNextTable[i]], voices[syncPrevTable[i]]); - // get output - voiceOutput[0] = voices[0].Output(voices[2]); - voiceOutput[1] = voices[1].Output(voices[0]); - voiceOutput[2] = voices[2].Output(voices[1]); - envelopeOutput[0] = envelopes[0].Level; - envelopeOutput[1] = envelopes[1].Level; - envelopeOutput[2] = envelopes[2].Level; + // get output + voiceOutput[0] = voices[0].Output(voices[2]); + voiceOutput[1] = voices[1].Output(voices[0]); + voiceOutput[2] = voices[2].Output(voices[1]); + envelopeOutput[0] = envelopes[0].Level; + envelopeOutput[1] = envelopes[1].Level; + envelopeOutput[2] = envelopes[2].Level; - mixer = ((voiceOutput[0] * envelopeOutput[0]) >> 7); - mixer += ((voiceOutput[1] * envelopeOutput[1]) >> 7); - mixer += ((voiceOutput[2] * envelopeOutput[2]) >> 7); - mixer = (mixer * volume) >> 4; + mixer = ((voiceOutput[0] * envelopeOutput[0]) >> 7); + mixer += ((voiceOutput[1] * envelopeOutput[1]) >> 7); + mixer += ((voiceOutput[2] * envelopeOutput[2]) >> 7); + mixer = (mixer * volume) >> 4; - sample = (short)mixer; - resampler.EnqueueSample(sample, sample); - cachedCycles--; - } - } + sample = (short)mixer; + resampler.EnqueueSample(sample, sample); + cachedCycles--; + } + } // ------------------------------------ @@ -172,7 +174,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 case 0x1A: case 0x1B: case 0x1C: - Flush(); + Flush(); result = ReadRegister(addr); break; } @@ -204,7 +206,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 (envelopes[0].Decay) ); break; - case 0x06: + case 0x06: result = (byte)( (envelopes[0].Sustain << 4) | (envelopes[0].Release) @@ -280,7 +282,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 ); break; case 0x19: result = (byte)potX; break; - case 0x1A: result = (byte)potY; break; + case 0x1A: result = (byte)potY; break; case 0x1B: result = (byte)(voiceOutput[2] >> 4); break; case 0x1C: result = (byte)(envelopeOutput[2]); break; } @@ -303,7 +305,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 // can't write to these break; default: - Flush(); + Flush(); WriteRegister(addr, val); break; } @@ -360,10 +362,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 // ---------------------------------- - public void SyncState(Serializer ser) + public void SyncState(Serializer ser) { - SaveState.SyncObject(ser, this); - ser.BeginSection("env0"); + SaveState.SyncObject(ser, this); + ser.BeginSection("env0"); envelopes[0].SyncState(ser); ser.EndSection(); ser.BeginSection("wav0"); diff --git a/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs b/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs index d30113b889..78968b0372 100644 --- a/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs +++ b/BizHawk.Emulation/Consoles/Atari/2600/Atari2600.Core.cs @@ -1,6 +1,7 @@ using System; using BizHawk.Common; +using BizHawk.Emulation.Common; using BizHawk.Emulation.Common.Components.M6502; @@ -12,7 +13,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 public MOS6502X cpu; public M6532 m6532; public TIA tia; - public Emulation.Sound.Utilities.DCFilter dcfilter; + public DCFilter dcfilter; public byte[] ram = new byte[128]; public MapperBase mapper; @@ -183,7 +184,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 //tia = new TIA(this, frameBuffer); tia = new TIA(this); // dcfilter coefficent is from real observed hardware behavior: a latched "1" will fully decay by ~170 or so tia sound cycles - dcfilter = Emulation.Sound.Utilities.DCFilter.AsISoundProvider(tia, 256); + dcfilter = DCFilter.AsISoundProvider(tia, 256); // Setup 6532 m6532 = new M6532(this); diff --git a/BizHawk.Emulation/Consoles/Atari/7800/Atari7800.cs b/BizHawk.Emulation/Consoles/Atari/7800/Atari7800.cs index 5e43ceedaf..3b8a4a1083 100644 --- a/BizHawk.Emulation/Consoles/Atari/7800/Atari7800.cs +++ b/BizHawk.Emulation/Consoles/Atari/7800/Atari7800.cs @@ -344,16 +344,16 @@ namespace BizHawk.Emulation.Cores.Atari.Atari7800 // really shouldn't happen (after init), but if it does, we're ready if (resampler != null) resampler.Dispose(); - resampler = new Emulation.Sound.Utilities.SpeexResampler(3, newsamplerate, 44100, newsamplerate, 44100, null, null); + resampler = new SpeexResampler(3, newsamplerate, 44100, newsamplerate, 44100, null, null); samplerate = newsamplerate; - dcfilter = Emulation.Sound.Utilities.DCFilter.DetatchedMode(256); + dcfilter = DCFilter.DetatchedMode(256); } } uint samplerate; int[] vidbuffer; - Emulation.Sound.Utilities.SpeexResampler resampler; - Emulation.Sound.Utilities.DCFilter dcfilter; + SpeexResampler resampler; + DCFilter dcfilter; public void FillFrameBuffer() { diff --git a/BizHawk.Emulation/Consoles/Coleco/ColecoVision.cs b/BizHawk.Emulation/Consoles/Coleco/ColecoVision.cs index 0488208ac1..fcff0736e6 100644 --- a/BizHawk.Emulation/Consoles/Coleco/ColecoVision.cs +++ b/BizHawk.Emulation/Consoles/Coleco/ColecoVision.cs @@ -4,8 +4,8 @@ using System.IO; using BizHawk.Common; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.Components; using BizHawk.Emulation.Common.Components.Z80; -using BizHawk.Emulation.Sound; namespace BizHawk.Emulation.Cores.ColecoVision { diff --git a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs index 5d25db6555..12c8231f86 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -826,10 +826,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy int latchaudio = 0; - //Sound.Utilities.SpeexResampler resampler; - //Sound.Utilities.DCFilter dcfilter; + //SpeexResampler resampler; + //DCFilter dcfilter; - Sound.Utilities.BlipBuffer blip; + BlipBuffer blip; void ProcessSound() { @@ -862,7 +862,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy //dcfilter = Sound.Utilities.DCFilter.AsISyncSoundProvider(resampler, 65536); // lowpass filtering on an actual GB was probably pretty aggressive? //dcfilter = Sound.Utilities.DCFilter.AsISyncSoundProvider(resampler, 2048); - blip = new Sound.Utilities.BlipBuffer(1024); + blip = new BlipBuffer(1024); blip.SetRates(2097152, 44100); } diff --git a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/GambatteLink.cs b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/GambatteLink.cs index c774c58ae5..5e46dc24a3 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -60,8 +60,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy LagCount = 0; IsLagFrame = false; - blip_left = new Sound.Utilities.BlipBuffer(1024); - blip_right = new Sound.Utilities.BlipBuffer(1024); + blip_left = new BlipBuffer(1024); + blip_right = new BlipBuffer(1024); blip_left.SetRates(2097152 * 2, 44100); blip_right.SetRates(2097152 * 2, 44100); @@ -357,9 +357,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy // i tried using the left and right buffers and then mixing them together... it was kind of a mess of code, and slow - Sound.Utilities.BlipBuffer blip_left; - Sound.Utilities.BlipBuffer blip_right; - + BlipBuffer blip_left; + BlipBuffer blip_right; short[] LeftBuffer = new short[(35112 + 2064) * 2]; short[] RightBuffer = new short[(35112 + 2064) * 2]; diff --git a/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs b/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs index de4ed22ada..dfd08499a4 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs @@ -33,7 +33,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 public int BackgroundColor { get { return 0; } } - public Sound.Utilities.SpeexResampler resampler; + public SpeexResampler resampler; public ISoundProvider SoundProvider { get { return null; } } public ISyncSoundProvider SyncSoundProvider { get { return resampler; } } diff --git a/BizHawk.Emulation/Consoles/Nintendo/N64/mupen64plusApi.cs b/BizHawk.Emulation/Consoles/Nintendo/N64/mupen64plusApi.cs index cc1c86e2b3..8b211a9826 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/N64/mupen64plusApi.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/N64/mupen64plusApi.cs @@ -5,6 +5,8 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading; +using BizHawk.Emulation.Common; + namespace BizHawk.Emulation.Cores.Nintendo.N64 { public class mupen64plusApi : IDisposable @@ -515,7 +517,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 // Set up the resampler m64pSamplingRate = (uint)AudGetAudioRate(); - bizhawkCore.resampler = new Sound.Utilities.SpeexResampler(6, m64pSamplingRate, 44100, m64pSamplingRate, 44100, null, null); + bizhawkCore.resampler = new SpeexResampler(6, m64pSamplingRate, 44100, m64pSamplingRate, 44100, null, null); AttachedCore = this; } diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/BisqAPU.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/BisqAPU.cs index 86c261baa5..01ec5629d0 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/BisqAPU.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/BisqAPU.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using BizHawk.Common; using BizHawk.Emulation.Common; -using BizHawk.Emulation.Sound; //http://wiki.nesdev.com/w/index.php/APU_Mixer_Emulation //http://wiki.nesdev.com/w/index.php/APU diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/ExROM.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/ExROM.cs index c652fb7565..2a94a2b6b3 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/ExROM.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/ExROM.cs @@ -2,6 +2,7 @@ using BizHawk.Common; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.Components; //simplifications/approximations: //* "Note that no commercial games rely on this mirroring -- therefore you can take the easy way out and simply give all MMC5 games 64k PRG-RAM." @@ -38,7 +39,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES int wram_bank; byte[] EXRAM = new byte[1024]; byte multiplicand, multiplier; - Sound.MMC5Audio audio; + MMC5Audio audio; //regeneratable state IntBuffer a_banks_1k = new IntBuffer(8); IntBuffer b_banks_1k = new IntBuffer(8); @@ -119,7 +120,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES PoweronState(); if (NES.apu != null) - audio = new Sound.MMC5Audio(NES.apu.ExternalQueue, (e) => { irq_audio = e; SyncIRQ(); }); + audio = new MMC5Audio(NES.apu.ExternalQueue, (e) => { irq_audio = e; SyncIRQ(); }); return true; } diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper069.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper069.cs index 9f2f26d508..8ebe7bf442 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper069.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Mapper069.cs @@ -1,4 +1,5 @@ using BizHawk.Common; +using BizHawk.Emulation.Common.Components; namespace BizHawk.Emulation.Cores.Nintendo.NES { @@ -7,7 +8,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public sealed class Sunsoft_5 : Sunsoft_FME7 { - Sound.Sunsoft5BAudio audio; + Sunsoft5BAudio audio; public override bool Configure(NES.EDetectionOrigin origin) { @@ -23,7 +24,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES BaseConfigure(); if (NES.apu != null) - audio = new Sound.Sunsoft5BAudio(NES.apu.ExternalQueue); + audio = new Sunsoft5BAudio(NES.apu.ExternalQueue); return true; } diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Namcot1xx/Namco163Audio.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Namcot1xx/Namco163Audio.cs index a9e6fe20bf..9e441698fd 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Namcot1xx/Namco163Audio.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Namcot1xx/Namco163Audio.cs @@ -1,5 +1,7 @@ using System; + using BizHawk.Common; +using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.NES { @@ -116,15 +118,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES ser.Sync("ch", ref ch); } - Sound.Utilities.SpeexResampler resampler; - Sound.Utilities.DCFilter dc; - Sound.MetaspuAsync metaspu; + SpeexResampler resampler; + DCFilter dc; + MetaspuAsync metaspu; public Namco163Audio() { - resampler = new Sound.Utilities.SpeexResampler(2, 119318, 44100, 119318, 44100, null, null); - dc = Sound.Utilities.DCFilter.DetatchedMode(4096); - metaspu = new Sound.MetaspuAsync(resampler, Sound.ESynchMethod.ESynchMethod_V); + resampler = new SpeexResampler(2, 119318, 44100, 119318, 44100, null, null); + dc = DCFilter.DetatchedMode(4096); + metaspu = new MetaspuAsync(resampler, ESynchMethod.ESynchMethod_V); } public void ApplyCustomAudio(short[] samples) diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/VRC6.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/VRC6.cs index 0d688c0e9b..0fd74b7932 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/VRC6.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/VRC6.cs @@ -1,5 +1,7 @@ using System; + using BizHawk.Common; +using BizHawk.Emulation.Common.Components; namespace BizHawk.Emulation.Cores.Nintendo.NES { @@ -12,7 +14,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES bool newer_variant; //Sound.VRC6 VRC6Sound = new Sound.VRC6(); - Sound.VRC6Alt VRC6Sound; + VRC6Alt VRC6Sound; //state int prg_bank_16k, prg_bank_8k; @@ -96,7 +98,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES SetMirrorType(EMirrorType.Vertical); if (NES.apu != null) // don't start up sound when in configurator - VRC6Sound = new Sound.VRC6Alt((uint)NES.cpuclockrate, NES.apu.ExternalQueue); + VRC6Sound = new VRC6Alt((uint)NES.cpuclockrate, NES.apu.ExternalQueue); return true; } diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/VRC7.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/VRC7.cs index 216d86c141..868a5f6509 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/VRC7.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/VRC7.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using BizHawk.Common; +using BizHawk.Emulation.Common.Components; namespace BizHawk.Emulation.Cores.Nintendo.NES { @@ -14,7 +15,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES Func remap; //state - BizHawk.Emulation.Sound.YM2413 fm; //= new Sound.YM2413(Sound.YM2413.ChipType.VRC7); + YM2413 fm; //= new Sound.YM2413(Sound.YM2413.ChipType.VRC7); ByteBuffer prg_banks_8k = new ByteBuffer(4); ByteBuffer chr_banks_1k = new ByteBuffer(8); @@ -94,7 +95,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES // presumably the only reason a homebrew would use mapper085 is for the sound? // so initialize like lagrange point remap = (addr) => ((addr & 0xF000) | ((addr & 0x30) >> 4)); - fm = new Sound.YM2413(Sound.YM2413.ChipType.VRC7); + fm = new YM2413(YM2413.ChipType.VRC7); break; case "KONAMI-VRC-7": AssertPrg(128, 512); AssertChr(0, 128); AssertVram(0, 8); AssertWram(0, 8); @@ -109,7 +110,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { //lagrange point remap = (addr) => ((addr & 0xF000) | ((addr & 0x30) >> 4)); - fm = new Sound.YM2413(Sound.YM2413.ChipType.VRC7); + fm = new YM2413(YM2413.ChipType.VRC7); } else throw new Exception("Unknown PCB type for VRC7"); diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs index 06230f6d96..0349fa4207 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs @@ -66,7 +66,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES class MagicSoundProvider : ISoundProvider, ISyncSoundProvider, IDisposable { - Sound.Utilities.BlipBuffer blip; + BlipBuffer blip; NES nes; const int blipbuffsize = 4096; @@ -75,7 +75,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { this.nes = nes; - blip = new Sound.Utilities.BlipBuffer(blipbuffsize); + blip = new BlipBuffer(blipbuffsize); blip.SetRates(infreq, 44100); //var actualMetaspu = new Sound.MetaspuSoundProvider(Sound.ESynchMethod.ESynchMethod_V); diff --git a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs index 4dc4a72d0a..11c481d0b9 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -975,11 +975,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES #region audio stuff - Sound.Utilities.SpeexResampler resampler; + SpeexResampler resampler; void InitAudio() { - resampler = new Sound.Utilities.SpeexResampler(6, 64081, 88200, 32041, 44100); + resampler = new SpeexResampler(6, 64081, 88200, 32041, 44100); } void snes_audio_sample(ushort left, ushort right) diff --git a/BizHawk.Emulation/Consoles/PC Engine/ADPCM.cs b/BizHawk.Emulation/Consoles/PC Engine/ADPCM.cs index 74a9877974..29b5023a13 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/ADPCM.cs +++ b/BizHawk.Emulation/Consoles/PC Engine/ADPCM.cs @@ -1,5 +1,4 @@ using System; -using BizHawk.Emulation.Sound; using System.IO; using System.Globalization; diff --git a/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs b/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs index 26fb771276..7c1d265806 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs +++ b/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs @@ -5,9 +5,9 @@ using System.IO; using BizHawk.Common; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.Components; using BizHawk.Emulation.Common.Components.H6280; using BizHawk.Emulation.DiscSystem; -using BizHawk.Emulation.Sound; namespace BizHawk.Emulation.Cores.PCEngine { diff --git a/BizHawk.Emulation/Consoles/PC Engine/ScsiCDBus.cs b/BizHawk.Emulation/Consoles/PC Engine/ScsiCDBus.cs index 7d9542a64c..83146fc0e8 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/ScsiCDBus.cs +++ b/BizHawk.Emulation/Consoles/PC Engine/ScsiCDBus.cs @@ -3,8 +3,8 @@ using System.IO; using System.Globalization; using BizHawk.Common; +using BizHawk.Emulation.Common; using BizHawk.Emulation.DiscSystem; -using BizHawk.Emulation.Sound; namespace BizHawk.Emulation.Cores.PCEngine { diff --git a/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs b/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs index e4743b74b3..aba76acaf6 100644 --- a/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs +++ b/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs @@ -7,12 +7,11 @@ using System.Runtime.InteropServices; using BizHawk.Common; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.Components; using BizHawk.Emulation.Common.Components.M68000; using BizHawk.Emulation.Common.Components.Z80; -using BizHawk.Emulation.Sound; using Native68000; - namespace BizHawk.Emulation.Cores.Sega.Genesis { public sealed partial class Genesis : IEmulator diff --git a/BizHawk.Emulation/Consoles/Sega/SMS/SMS.cs b/BizHawk.Emulation/Consoles/Sega/SMS/SMS.cs index 3f7bcfb70f..65e6150935 100644 --- a/BizHawk.Emulation/Consoles/Sega/SMS/SMS.cs +++ b/BizHawk.Emulation/Consoles/Sega/SMS/SMS.cs @@ -5,8 +5,8 @@ using System.IO; using BizHawk.Common; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.Components; using BizHawk.Emulation.Common.Components.Z80; -using BizHawk.Emulation.Sound; /***************************************************** diff --git a/BizHawk.Emulation/Sound/CDAudio.cs b/BizHawk.Emulation/Sound/CDAudio.cs index ab96ee2e6d..c5801897e9 100644 --- a/BizHawk.Emulation/Sound/CDAudio.cs +++ b/BizHawk.Emulation/Sound/CDAudio.cs @@ -9,7 +9,7 @@ using BizHawk.Emulation.DiscSystem; // I decided not to let the perfect be the enemy of the good. // It can always be refactored. It's at least deterministic. -namespace BizHawk.Emulation.Sound +namespace BizHawk.Emulation.Common { public sealed class CDAudio : ISoundProvider { diff --git a/BizHawk.Emulation/Sound/HuC6280PSG.cs b/BizHawk.Emulation/Sound/HuC6280PSG.cs index 0931bd03c5..4f50e41be1 100644 --- a/BizHawk.Emulation/Sound/HuC6280PSG.cs +++ b/BizHawk.Emulation/Sound/HuC6280PSG.cs @@ -6,7 +6,7 @@ using System.IO; using BizHawk.Common; using BizHawk.Emulation.Common; -namespace BizHawk.Emulation.Sound +namespace BizHawk.Emulation.Common.Components { // Emulates PSG audio unit of a PC Engine / Turbografx-16 / SuperGrafx. // It is embedded on the CPU and doesn't have its own part number. None the less, it is emulated separately from the 6280 CPU. diff --git a/BizHawk.Emulation/Sound/MMC5Audio.cs b/BizHawk.Emulation/Sound/MMC5Audio.cs index aa38541da1..d6b8883761 100644 --- a/BizHawk.Emulation/Sound/MMC5Audio.cs +++ b/BizHawk.Emulation/Sound/MMC5Audio.cs @@ -5,7 +5,7 @@ using System.Text; using BizHawk.Common; -namespace BizHawk.Emulation.Sound +namespace BizHawk.Emulation.Common.Components { public class MMC5Audio { diff --git a/BizHawk.Emulation/Sound/SN76489.cs b/BizHawk.Emulation/Sound/SN76489.cs index 97f1c5a4b8..b0b4cd1e9d 100644 --- a/BizHawk.Emulation/Sound/SN76489.cs +++ b/BizHawk.Emulation/Sound/SN76489.cs @@ -5,11 +5,13 @@ using System.IO; using BizHawk.Emulation.Common; -// Emulates a Texas Instruments SN76489 // TODO the freq->note translation should be moved to a separate utility class. -namespace BizHawk.Emulation.Sound +namespace BizHawk.Emulation.Common.Components { + /// + /// Emulates a Texas Instruments SN76489 + /// public sealed class SN76489 : ISoundProvider { public sealed class Channel diff --git a/BizHawk.Emulation/Sound/Sunsoft5BAudio.cs b/BizHawk.Emulation/Sound/Sunsoft5BAudio.cs index caf8e1c8c1..5e7ac5912d 100644 --- a/BizHawk.Emulation/Sound/Sunsoft5BAudio.cs +++ b/BizHawk.Emulation/Sound/Sunsoft5BAudio.cs @@ -5,11 +5,13 @@ using System.Text; using BizHawk.Common; -namespace BizHawk.Emulation.Sound +namespace BizHawk.Emulation.Common.Components { - // YM2149F variant - // this implementation is quite incomplete - // http://wiki.nesdev.com/w/index.php/Sunsoft_5B_audio + /// + /// YM2149F variant + /// this implementation is quite incomplete + /// http://wiki.nesdev.com/w/index.php/Sunsoft_5B_audio + /// public class Sunsoft5BAudio { class Pulse diff --git a/BizHawk.Emulation/Sound/Utilities/BlipBuffer.cs b/BizHawk.Emulation/Sound/Utilities/BlipBuffer.cs index 404c31a162..dde87a94ee 100644 --- a/BizHawk.Emulation/Sound/Utilities/BlipBuffer.cs +++ b/BizHawk.Emulation/Sound/Utilities/BlipBuffer.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Runtime.InteropServices; -namespace BizHawk.Emulation.Sound.Utilities +namespace BizHawk.Emulation.Common { /// /// wrapper around blargg's unmanaged blip_buf @@ -16,18 +16,18 @@ namespace BizHawk.Emulation.Sound.Utilities static class BlipBufDll { - /** Creates new buffer that can hold at most sample_count samples. Sets rates - so that there are blip_max_ratio clocks per sample. Returns pointer to new + /** Creates new buffer that can hold at most sample_count samples. Sets rates + so that there are blip_max_ratio clocks per sample. Returns pointer to new buffer, or NULL if insufficient memory. */ [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr blip_new(int sample_count); - /** Sets approximate input clock rate and output sample rate. For every + /** Sets approximate input clock rate and output sample rate. For every clock_rate input clocks, approximately sample_rate samples are generated. */ [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void blip_set_rates(IntPtr context, double clock_rate, double sample_rate); - /** Maximum clock_rate/sample_rate ratio. For a given sample_rate, + /** Maximum clock_rate/sample_rate ratio. For a given sample_rate, clock_rate must not be greater than sample_rate*blip_max_ratio. */ public const int blip_max_ratio = 1 << 20; @@ -43,7 +43,7 @@ namespace BizHawk.Emulation.Sound.Utilities [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void blip_add_delta_fast(IntPtr context, uint clock_time, int delta); - /** Length of time frame, in clocks, needed to make sample_count additional + /** Length of time frame, in clocks, needed to make sample_count additional samples available. */ [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int blip_clocks_needed(IntPtr context, int sample_count); @@ -51,10 +51,10 @@ namespace BizHawk.Emulation.Sound.Utilities /** Maximum number of samples that can be generated from one time frame. */ public const int blip_max_frame = 4000; - /** Makes input clocks before clock_duration available for reading as output - samples. Also begins new time frame at clock_duration, so that clock time 0 in - the new time frame specifies the same clock as clock_duration in the old time - frame specified. Deltas can have been added slightly past clock_duration (up to + /** Makes input clocks before clock_duration available for reading as output + samples. Also begins new time frame at clock_duration, so that clock time 0 in + the new time frame specifies the same clock as clock_duration in the old time + frame specified. Deltas can have been added slightly past clock_duration (up to however many clocks there are in two output samples). */ [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void blip_end_frame(IntPtr context, uint clock_duration); @@ -63,9 +63,9 @@ namespace BizHawk.Emulation.Sound.Utilities [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int blip_samples_avail(IntPtr context); - /** Reads and removes at most 'count' samples and writes them to 'out'. If - 'stereo' is true, writes output to every other element of 'out', allowing easy - interleaving of two buffers into a stereo sample stream. Outputs 16-bit signed + /** Reads and removes at most 'count' samples and writes them to 'out'. If + 'stereo' is true, writes output to every other element of 'out', allowing easy + interleaving of two buffers into a stereo sample stream. Outputs 16-bit signed samples. Returns number of samples actually read. */ [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int blip_read_samples(IntPtr context, short[] @out, int count, int stereo); diff --git a/BizHawk.Emulation/Sound/Utilities/BufferedAsync.cs b/BizHawk.Emulation/Sound/Utilities/BufferedAsync.cs index 30f17dbb07..169b3883f6 100644 --- a/BizHawk.Emulation/Sound/Utilities/BufferedAsync.cs +++ b/BizHawk.Emulation/Sound/Utilities/BufferedAsync.cs @@ -2,18 +2,18 @@ using BizHawk.Emulation.Common; -namespace BizHawk.Emulation.Sound +namespace BizHawk.Emulation.Common { - // Generates SEMI-synchronous sound, or "buffered asynchronous" sound. + // Generates SEMI-synchronous sound, or "buffered asynchronous" sound. - // This class will try as hard as it can to request the correct number of samples on each frame and then - // send them out to the sound card as it needs them. + // This class will try as hard as it can to request the correct number of samples on each frame and then + // send them out to the sound card as it needs them. - // However, it has minimum/maximum buffer targets and will request smaller or larger frames if it has to. - // The ultimate goal of this strategy is to make MOST frames 100% correct, and if errors must occur, - // concentrate it on a single frame, rather than distribute small errors across most frames, as - // distributing error to most frames tends to result in persistently distorted audio, especially when - // sample playback is involved. + // However, it has minimum/maximum buffer targets and will request smaller or larger frames if it has to. + // The ultimate goal of this strategy is to make MOST frames 100% correct, and if errors must occur, + // concentrate it on a single frame, rather than distribute small errors across most frames, as + // distributing error to most frames tends to result in persistently distorted audio, especially when + // sample playback is involved. /* @@ -30,15 +30,15 @@ namespace BizHawk.Emulation.Sound * that and then bypass the BufferedAsync. */ - public sealed class BufferedAsync : ISoundProvider - { - public ISoundProvider BaseSoundProvider; + public sealed class BufferedAsync : ISoundProvider + { + public ISoundProvider BaseSoundProvider; - Queue buffer = new Queue(4096); + Queue buffer = new Queue(4096); - int SamplesInOneFrame = 1470; - int TargetExtraSamples = 882; - const int MaxExcessSamples = 4096; + int SamplesInOneFrame = 1470; + int TargetExtraSamples = 882; + const int MaxExcessSamples = 4096; /// /// recalculates some internal parameters based on the IEmulator's framerate @@ -52,31 +52,31 @@ namespace BizHawk.Emulation.Sound public void DiscardSamples() { - if(BaseSoundProvider != null) + if (BaseSoundProvider != null) BaseSoundProvider.DiscardSamples(); } - public int MaxVolume { get; set; } + public int MaxVolume { get; set; } - public void GetSamples(short[] samples) - { - int samplesToGenerate = SamplesInOneFrame; - if (buffer.Count > samples.Length + MaxExcessSamples) - samplesToGenerate = 0; - if (buffer.Count - samples.Length < TargetExtraSamples) - samplesToGenerate += SamplesInOneFrame; - if (samplesToGenerate + buffer.Count < samples.Length) - samplesToGenerate = samples.Length - buffer.Count; + public void GetSamples(short[] samples) + { + int samplesToGenerate = SamplesInOneFrame; + if (buffer.Count > samples.Length + MaxExcessSamples) + samplesToGenerate = 0; + if (buffer.Count - samples.Length < TargetExtraSamples) + samplesToGenerate += SamplesInOneFrame; + if (samplesToGenerate + buffer.Count < samples.Length) + samplesToGenerate = samples.Length - buffer.Count; - var mySamples = new short[samplesToGenerate]; + var mySamples = new short[samplesToGenerate]; - BaseSoundProvider.GetSamples(mySamples); + BaseSoundProvider.GetSamples(mySamples); - for (int i = 0; i < mySamples.Length; i++) - buffer.Enqueue(mySamples[i]); + for (int i = 0; i < mySamples.Length; i++) + buffer.Enqueue(mySamples[i]); - for (int i = 0; i < samples.Length; i++) - samples[i] = buffer.Dequeue(); - } - } + for (int i = 0; i < samples.Length; i++) + samples[i] = buffer.Dequeue(); + } + } } \ No newline at end of file diff --git a/BizHawk.Emulation/Sound/Utilities/DCFilter.cs b/BizHawk.Emulation/Sound/Utilities/DCFilter.cs index 274895f502..7675bd63cd 100644 --- a/BizHawk.Emulation/Sound/Utilities/DCFilter.cs +++ b/BizHawk.Emulation/Sound/Utilities/DCFilter.cs @@ -5,7 +5,7 @@ using System.Text; using BizHawk.Emulation.Common; -namespace BizHawk.Emulation.Sound.Utilities +namespace BizHawk.Emulation.Common { /// /// implements a DC block filter on top of an ISoundProvider. rather simple. @@ -39,7 +39,7 @@ namespace BizHawk.Emulation.Sound.Utilities } int depth; - + public static DCFilter AsISoundProvider(ISoundProvider input, int filterwidth) { if (input == null) @@ -59,7 +59,7 @@ namespace BizHawk.Emulation.Sound.Utilities return new DCFilter(null, null, filterwidth); } - DCFilter(ISoundProvider input, ISyncSoundProvider syncinput, int filterwidth) + DCFilter(ISoundProvider input, ISyncSoundProvider syncinput, int filterwidth) { if (filterwidth < 8 || filterwidth > 65536) throw new ArgumentOutOfRangeException(); @@ -67,7 +67,7 @@ namespace BizHawk.Emulation.Sound.Utilities this.syncinput = syncinput; depth = DepthFromFilterwidth(filterwidth); } - + /// /// pass a set of samples through the filter. should only be used in detached mode /// diff --git a/BizHawk.Emulation/Sound/Utilities/Equalizer.cs b/BizHawk.Emulation/Sound/Utilities/Equalizer.cs index ae30719242..0a0c1c6618 100644 --- a/BizHawk.Emulation/Sound/Utilities/Equalizer.cs +++ b/BizHawk.Emulation/Sound/Utilities/Equalizer.cs @@ -5,94 +5,94 @@ using System.Collections.Generic; using System.Linq; using System.Text; -namespace BizHawk.Emulation.Sound +namespace BizHawk.Emulation.Common { - public sealed class Equalizer - { - double lowFilter; - double lowFilterPole0; - double lowFilterPole1; - double lowFilterPole2; - double lowFilterPole3; + public sealed class Equalizer + { + double lowFilter; + double lowFilterPole0; + double lowFilterPole1; + double lowFilterPole2; + double lowFilterPole3; - double highFilter; - double highFilterPole0; - double highFilterPole1; - double highFilterPole2; - double highFilterPole3; + double highFilter; + double highFilterPole0; + double highFilterPole1; + double highFilterPole2; + double highFilterPole3; - double sampleDataMinus1; - double sampleDataMinus2; - double sampleDataMinus3; + double sampleDataMinus1; + double sampleDataMinus2; + double sampleDataMinus3; - double lowGain; - double midGain; - double highGain; - - const double sampleRate = 44100.0; - const double verySmallAmount = (1.0 / 4294967295.0); + double lowGain; + double midGain; + double highGain; - double lowfreq; - public double LowFreqCutoff - { - get { return lowfreq; } - set - { - lowfreq = value; - lowFilter = 2 * Math.Sin(Math.PI * (lowfreq / sampleRate)); - } - } + const double sampleRate = 44100.0; + const double verySmallAmount = (1.0 / 4294967295.0); - double highfreq; - public double HighFreqCutoff - { - get { return highfreq; } - set - { - highfreq = value; - highFilter = 2 * Math.Sin(Math.PI * (highfreq / sampleRate)); - } - } + double lowfreq; + public double LowFreqCutoff + { + get { return lowfreq; } + set + { + lowfreq = value; + lowFilter = 2 * Math.Sin(Math.PI * (lowfreq / sampleRate)); + } + } - public Equalizer(double lowFreq=880, double highFreq=5000) - { - lowGain = 1.3; - midGain = 0.9; - highGain = 1.3; - LowFreqCutoff = lowFreq; - HighFreqCutoff = highFreq; - } + double highfreq; + public double HighFreqCutoff + { + get { return highfreq; } + set + { + highfreq = value; + highFilter = 2 * Math.Sin(Math.PI * (highfreq / sampleRate)); + } + } - public short EqualizeSample(short sample) - { - lowFilterPole0 += (lowFilter * (sample - lowFilterPole0)) + verySmallAmount; - lowFilterPole1 += lowFilter * (lowFilterPole0 - lowFilterPole1); - lowFilterPole2 += lowFilter * (lowFilterPole1 - lowFilterPole2); - lowFilterPole3 += lowFilter * (lowFilterPole2 - lowFilterPole3); - double l = lowFilterPole3; + public Equalizer(double lowFreq = 880, double highFreq = 5000) + { + lowGain = 1.3; + midGain = 0.9; + highGain = 1.3; + LowFreqCutoff = lowFreq; + HighFreqCutoff = highFreq; + } - highFilterPole0 += (highFilter * (sample - highFilterPole0)) + verySmallAmount; - highFilterPole1 += highFilter * (highFilterPole0 - highFilterPole1); - highFilterPole2 += highFilter * (highFilterPole1 - highFilterPole2); - highFilterPole3 += highFilter * (highFilterPole2 - highFilterPole3); - double h = sampleDataMinus3 - highFilterPole3; + public short EqualizeSample(short sample) + { + lowFilterPole0 += (lowFilter * (sample - lowFilterPole0)) + verySmallAmount; + lowFilterPole1 += lowFilter * (lowFilterPole0 - lowFilterPole1); + lowFilterPole2 += lowFilter * (lowFilterPole1 - lowFilterPole2); + lowFilterPole3 += lowFilter * (lowFilterPole2 - lowFilterPole3); + double l = lowFilterPole3; - double m = sample - (h + l); - l *= lowGain; - m *= midGain; - h *= highGain; + highFilterPole0 += (highFilter * (sample - highFilterPole0)) + verySmallAmount; + highFilterPole1 += highFilter * (highFilterPole0 - highFilterPole1); + highFilterPole2 += highFilter * (highFilterPole1 - highFilterPole2); + highFilterPole3 += highFilter * (highFilterPole2 - highFilterPole3); + double h = sampleDataMinus3 - highFilterPole3; - sampleDataMinus3 = sampleDataMinus2; - sampleDataMinus2 = sampleDataMinus1; - sampleDataMinus1 = sample; + double m = sample - (h + l); + l *= lowGain; + m *= midGain; + h *= highGain; - return (short) (l + m + h); - } + sampleDataMinus3 = sampleDataMinus2; + sampleDataMinus2 = sampleDataMinus1; + sampleDataMinus1 = sample; - public void Equalize(short[] samples) - { - for (int i = 0; i < samples.Length; i++) - samples[i] = EqualizeSample(samples[i]); - } - } + return (short)(l + m + h); + } + + public void Equalize(short[] samples) + { + for (int i = 0; i < samples.Length; i++) + samples[i] = EqualizeSample(samples[i]); + } + } } \ No newline at end of file diff --git a/BizHawk.Emulation/Sound/Utilities/Metaspu.cs b/BizHawk.Emulation/Sound/Utilities/Metaspu.cs index fc9d895603..41830fe1ff 100644 --- a/BizHawk.Emulation/Sound/Utilities/Metaspu.cs +++ b/BizHawk.Emulation/Sound/Utilities/Metaspu.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using BizHawk.Emulation.Common; -namespace BizHawk.Emulation.Sound +namespace BizHawk.Emulation.Common { /// /// uses Metaspu to have an ISyncSoundProvider input to a ISoundProvider @@ -36,8 +36,6 @@ namespace BizHawk.Emulation.Sound public int MaxVolume { get; set; } } - - public class MetaspuSoundProvider : ISoundProvider { public ISynchronizingAudioBuffer buffer; @@ -46,17 +44,18 @@ namespace BizHawk.Emulation.Sound buffer = Metaspu.metaspu_construct(method); } - public MetaspuSoundProvider() : this(ESynchMethod.ESynchMethod_V) + public MetaspuSoundProvider() + : this(ESynchMethod.ESynchMethod_V) { } - short[] pullBuffer = new short[1470]; - public void PullSamples(ISoundProvider source) - { - Array.Clear(pullBuffer, 0, 1470); - source.GetSamples(pullBuffer); - buffer.enqueue_samples(pullBuffer, 735); - } + short[] pullBuffer = new short[1470]; + public void PullSamples(ISoundProvider source) + { + Array.Clear(pullBuffer, 0, 1470); + source.GetSamples(pullBuffer); + buffer.enqueue_samples(pullBuffer, 735); + } public void GetSamples(short[] samples) { @@ -68,15 +67,15 @@ namespace BizHawk.Emulation.Sound buffer.clear(); } - public int MaxVolume { get; set; } - } + public int MaxVolume { get; set; } + } public interface ISynchronizingAudioBuffer { void enqueue_samples(short[] buf, int samples_provided); void enqueue_sample(short left, short right); void clear(); - + //returns the number of samples actually supplied, which may not match the number requested // ^^ what the hell is that supposed to mean. // the entire point of an ISynchronzingAudioBuffer @@ -90,9 +89,9 @@ namespace BizHawk.Emulation.Sound ESynchMethod_N, //nitsuja's ESynchMethod_Z, //zero's //ESynchMethod_P, //PCSX2 spu2-x //ohno! not available yet in c# - ESynchMethod_V // vecna + ESynchMethod_V // vecna }; - + public static class Metaspu { public static ISynchronizingAudioBuffer metaspu_construct(ESynchMethod method) @@ -103,15 +102,15 @@ namespace BizHawk.Emulation.Sound return new ZeromusSynchronizer(); case ESynchMethod.ESynchMethod_N: return new NitsujaSynchronizer(); - case ESynchMethod.ESynchMethod_V: - return new VecnaSynchronizer(); + case ESynchMethod.ESynchMethod_V: + return new VecnaSynchronizer(); default: return new NitsujaSynchronizer(); } } } - + class ZeromusSynchronizer : ISynchronizingAudioBuffer { public ZeromusSynchronizer() @@ -121,7 +120,7 @@ namespace BizHawk.Emulation.Sound //#else //adjustobuf = new Adjustobuf(22000, 44000); //#endif - + } //adjustobuf(200,1000) @@ -151,7 +150,7 @@ namespace BizHawk.Emulation.Sound //returns the number of samples actually supplied, which may not match the number requested public int output_samples(short[] buf, int samples_requested) { - int ctr=0; + int ctr = 0; int done = 0; if (!mixqueue_go) { @@ -208,7 +207,7 @@ namespace BizHawk.Emulation.Sound size = 0; } - public void enqueue(short left, short right) + public void enqueue(short left, short right) { buffer.Enqueue(left); buffer.Enqueue(right); @@ -232,14 +231,16 @@ namespace BizHawk.Emulation.Sound //static int ctr=0; ctr++; if((ctr&127)==0) printf("avg size: %f curr size: %d rate: %f\n",averageSize,size,rate); { float targetRate; - if(averageSize < targetLatency) + if (averageSize < targetLatency) { - targetRate = 1.0f - (targetLatency-averageSize)/kAverageSize; + targetRate = 1.0f - (targetLatency - averageSize) / kAverageSize; } - else if(averageSize > targetLatency) { - targetRate = 1.0f + (averageSize-targetLatency)/kAverageSize; - } else targetRate = 1.0f; - + else if (averageSize > targetLatency) + { + targetRate = 1.0f + (averageSize - targetLatency) / kAverageSize; + } + else targetRate = 1.0f; + //rate = moveValueTowards(rate,targetRate,0.001f); rate = targetRate; } @@ -251,19 +252,21 @@ namespace BizHawk.Emulation.Sound public void dequeue(out short left, out short right) { - left = right = 0; + left = right = 0; addStatistic(); - if(size==0) { return; } + if (size == 0) { return; } cursor += rate; - while(cursor>1.0f) { + while (cursor > 1.0f) + { cursor -= 1.0f; - if(size>0) { + if (size > 0) + { curr[0] = buffer.Dequeue(); curr[1] = buffer.Dequeue(); size--; } } - left = curr[0]; + left = curr[0]; right = curr[1]; } } @@ -282,9 +285,9 @@ namespace BizHawk.Emulation.Sound // returns values going between 0 and y-1 in a saw wave pattern, based on x static int pingpong(int x, int y) { - x %= 2*y; - if(x >= y) - x = 2*y - x - 1; + x %= 2 * y; + if (x >= y) + x = 2 * y - x - 1; return x; // in case we want to switch to odd buffer sizes for more sharpness @@ -294,11 +297,11 @@ namespace BizHawk.Emulation.Sound //return x; } - static ssamp crossfade (ssamp lhs, ssamp rhs, int cur, int start, int end) + static ssamp crossfade(ssamp lhs, ssamp rhs, int cur, int start, int end) { - if(cur <= start) + if (cur <= start) return lhs; - if(cur >= end) + if (cur >= end) return rhs; // in case we want sine wave interpolation instead of linear here @@ -312,7 +315,7 @@ namespace BizHawk.Emulation.Sound int lrv = ((int)lhs.l * outNum + (int)rhs.l * inNum) / denom; int rrv = ((int)lhs.r * outNum + (int)rhs.r * inNum) / denom; - return new ssamp((short)lrv,(short)rrv); + return new ssamp((short)lrv, (short)rrv); } public void clear() @@ -328,8 +331,8 @@ namespace BizHawk.Emulation.Sound static void emit_samples(short[] outbuf, ref int outcursor, ssamp[] samplebuf, int incursor, int samples) { - for(int i=0;i 0x200 && audiosize > 0) // is there any work to do? - { - // are we going at normal speed? - // or more precisely, are the input and output queues/buffers of similar size? - if(queued > 900 || audiosize > queued * 2) + if (queued > 0x200 && audiosize > 0) // is there any work to do? { - // not normal speed. we have to resample it somehow in this case. - if(audiosize <= queued) + // are we going at normal speed? + // or more precisely, are the input and output queues/buffers of similar size? + if (queued > 900 || audiosize > queued * 2) { - // fast forward speed - // this is the easy case, just crossfade it and it sounds ok - for(int i = 0; i < audiosize; i++) + // not normal speed. we have to resample it somehow in this case. + if (audiosize <= queued) { - int j = i + queued - audiosize; - ssamp outsamp = crossfade(sampleQueue[i],sampleQueue[j], i,0,audiosize); - emit_sample(buf,ref bufcursor,outsamp); - } - } - else - { - // slow motion speed - // here we take a very different approach, - // instead of crossfading it, we select a single sample from the queue - // and make sure that the index we use to select a sample is constantly moving - // and that it starts at the first sample in the queue and ends on the last one. - // - // hopefully the index doesn't move discontinuously or we'll get slight crackling - // (there might still be a minor bug here that causes this occasionally) - // - // here's a diagram of how the index we sample from moves: - // - // queued (this axis represents the index we sample from. the top means the end of the queue) - // ^ - // | --> audiosize (this axis represents the output index we write to, right meaning forward in output time/position) - // | A C C end - // A A B C C C - // A A A B C C C - // A A A B C C - // A A C - // start - // - // yes, this means we are spending some stretches of time playing the sound backwards, - // but the stretches are short enough that this doesn't sound weird. - // this lets us avoid most crackling problems due to the endpoints matching up. - - // first calculate a shorter-than-full window - // that has minimal slope at the endpoints - // (to further reduce crackling, especially in sine waves) - int beststart = 0, extraAtEnd = 0; - { - int bestend = queued; - const int worstdiff = 99999999; - int beststartdiff = worstdiff; - int bestenddiff = worstdiff; - for(int i = 0; i < 128; i+=2) + // fast forward speed + // this is the easy case, just crossfade it and it sounds ok + for (int i = 0; i < audiosize; i++) { - int diff = abs(sampleQueue[i].l - sampleQueue[i+1].l) + abs(sampleQueue[i].r - sampleQueue[i+1].r); - if(diff < beststartdiff) - { - beststartdiff = diff; - beststart = i; - } + int j = i + queued - audiosize; + ssamp outsamp = crossfade(sampleQueue[i], sampleQueue[j], i, 0, audiosize); + emit_sample(buf, ref bufcursor, outsamp); } - for(int i = queued-3; i > queued-3-128; i-=2) + } + else + { + // slow motion speed + // here we take a very different approach, + // instead of crossfading it, we select a single sample from the queue + // and make sure that the index we use to select a sample is constantly moving + // and that it starts at the first sample in the queue and ends on the last one. + // + // hopefully the index doesn't move discontinuously or we'll get slight crackling + // (there might still be a minor bug here that causes this occasionally) + // + // here's a diagram of how the index we sample from moves: + // + // queued (this axis represents the index we sample from. the top means the end of the queue) + // ^ + // | --> audiosize (this axis represents the output index we write to, right meaning forward in output time/position) + // | A C C end + // A A B C C C + // A A A B C C C + // A A A B C C + // A A C + // start + // + // yes, this means we are spending some stretches of time playing the sound backwards, + // but the stretches are short enough that this doesn't sound weird. + // this lets us avoid most crackling problems due to the endpoints matching up. + + // first calculate a shorter-than-full window + // that has minimal slope at the endpoints + // (to further reduce crackling, especially in sine waves) + int beststart = 0, extraAtEnd = 0; { - int diff = abs(sampleQueue[i].l - sampleQueue[i+1].l) + abs(sampleQueue[i].r - sampleQueue[i+1].r); - if(diff < bestenddiff) + int bestend = queued; + const int worstdiff = 99999999; + int beststartdiff = worstdiff; + int bestenddiff = worstdiff; + for (int i = 0; i < 128; i += 2) { - bestenddiff = diff; - bestend = i+1; + int diff = abs(sampleQueue[i].l - sampleQueue[i + 1].l) + abs(sampleQueue[i].r - sampleQueue[i + 1].r); + if (diff < beststartdiff) + { + beststartdiff = diff; + beststart = i; + } + } + for (int i = queued - 3; i > queued - 3 - 128; i -= 2) + { + int diff = abs(sampleQueue[i].l - sampleQueue[i + 1].l) + abs(sampleQueue[i].r - sampleQueue[i + 1].r); + if (diff < bestenddiff) + { + bestenddiff = diff; + bestend = i + 1; + } + } + + extraAtEnd = queued - bestend; + queued = bestend - beststart; + + int oksize = queued; + while (oksize + queued * 2 + beststart + extraAtEnd <= samples_requested) + oksize += queued * 2; + audiosize = oksize; + + for (int x = 0; x < beststart; x++) + { + emit_sample(buf, ref bufcursor, sampleQueue[x]); + } + //sampleQueue.erase(sampleQueue.begin(), sampleQueue.begin() + beststart); + sampleQueue.RemoveRange(0, beststart); + //zero 08-nov-2010: did i do this right? + } + + + int midpointX = audiosize >> 1; + int midpointY = queued >> 1; + + // all we need to do here is calculate the X position of the leftmost "B" in the above diagram. + // TODO: we should calculate it with a simple equation like + // midpointXOffset = min(something,somethingElse); + // but it's a little difficult to work it out exactly + // so here's a stupid search for the value for now: + + int prevA = 999999; + int midpointXOffset = queued / 2; + while (true) + { + int a = abs(pingpong(midpointX - midpointXOffset, queued) - midpointY) - midpointXOffset; + if (((a > 0) != (prevA > 0) || (a < 0) != (prevA < 0)) && prevA != 999999) + { + if (((a + prevA) & 1) != 0) // there's some sort of off-by-one problem with this search since we're moving diagonally... + midpointXOffset++; // but this fixes it most of the time... + break; // found it + } + prevA = a; + midpointXOffset--; + if (midpointXOffset < 0) + { + midpointXOffset = 0; + break; // failed to find it. the two sides probably meet exactly in the center. } } - extraAtEnd = queued - bestend; - queued = bestend - beststart; + int leftMidpointX = midpointX - midpointXOffset; + int rightMidpointX = midpointX + midpointXOffset; + int leftMidpointY = pingpong(leftMidpointX, queued); + int rightMidpointY = (queued - 1) - pingpong((int)audiosize - 1 - rightMidpointX + queued * 2, queued); - int oksize = queued; - while(oksize + queued*2 + beststart + extraAtEnd <= samples_requested) - oksize += queued*2; - audiosize = oksize; - - for(int x = 0; x < beststart; x++) + // output the left almost-half of the sound (section "A") + for (int x = 0; x < leftMidpointX; x++) { - emit_sample(buf,ref bufcursor,sampleQueue[x]); + int i = pingpong(x, queued); + emit_sample(buf, ref bufcursor, sampleQueue[i]); } - //sampleQueue.erase(sampleQueue.begin(), sampleQueue.begin() + beststart); - sampleQueue.RemoveRange(0, beststart); - //zero 08-nov-2010: did i do this right? - } + // output the middle stretch (section "B") + int y = leftMidpointY; + int dyMidLeft = (leftMidpointY < midpointY) ? 1 : -1; + int dyMidRight = (rightMidpointY > midpointY) ? 1 : -1; + for (int x = leftMidpointX; x < midpointX; x++, y += dyMidLeft) + emit_sample(buf, ref bufcursor, sampleQueue[y]); + for (int x = midpointX; x < rightMidpointX; x++, y += dyMidRight) + emit_sample(buf, ref bufcursor, sampleQueue[y]); - int midpointX = audiosize >> 1; - int midpointY = queued >> 1; - - // all we need to do here is calculate the X position of the leftmost "B" in the above diagram. - // TODO: we should calculate it with a simple equation like - // midpointXOffset = min(something,somethingElse); - // but it's a little difficult to work it out exactly - // so here's a stupid search for the value for now: - - int prevA = 999999; - int midpointXOffset = queued/2; - while(true) - { - int a = abs(pingpong(midpointX - midpointXOffset, queued) - midpointY) - midpointXOffset; - if(((a > 0) != (prevA > 0) || (a < 0) != (prevA < 0)) && prevA != 999999) + // output the end of the queued sound (section "C") + for (int x = rightMidpointX; x < audiosize; x++) { - if(((a + prevA)&1)!=0) // there's some sort of off-by-one problem with this search since we're moving diagonally... - midpointXOffset++; // but this fixes it most of the time... - break; // found it + int i = (queued - 1) - pingpong((int)audiosize - 1 - x + queued * 2, queued); + emit_sample(buf, ref bufcursor, sampleQueue[i]); } - prevA = a; - midpointXOffset--; - if(midpointXOffset < 0) + + for (int x = 0; x < extraAtEnd; x++) { - midpointXOffset = 0; - break; // failed to find it. the two sides probably meet exactly in the center. + int i = queued + x; + emit_sample(buf, ref bufcursor, sampleQueue[i]); } - } + queued += extraAtEnd; + audiosize += beststart + extraAtEnd; + } //end else - int leftMidpointX = midpointX - midpointXOffset; - int rightMidpointX = midpointX + midpointXOffset; - int leftMidpointY = pingpong(leftMidpointX, queued); - int rightMidpointY = (queued-1) - pingpong((int)audiosize-1 - rightMidpointX + queued*2, queued); - - // output the left almost-half of the sound (section "A") - for(int x = 0; x < leftMidpointX; x++) - { - int i = pingpong(x, queued); - emit_sample(buf,ref bufcursor,sampleQueue[i]); - } - - // output the middle stretch (section "B") - int y = leftMidpointY; - int dyMidLeft = (leftMidpointY < midpointY) ? 1 : -1; - int dyMidRight = (rightMidpointY > midpointY) ? 1 : -1; - for(int x = leftMidpointX; x < midpointX; x++, y+=dyMidLeft) - emit_sample(buf,ref bufcursor,sampleQueue[y]); - for(int x = midpointX; x < rightMidpointX; x++, y+=dyMidRight) - emit_sample(buf, ref bufcursor, sampleQueue[y]); - - // output the end of the queued sound (section "C") - for(int x = rightMidpointX; x < audiosize; x++) - { - int i = (queued-1) - pingpong((int)audiosize-1 - x + queued*2, queued); - emit_sample(buf,ref bufcursor,sampleQueue[i]); - } - - for(int x = 0; x < extraAtEnd; x++) - { - int i = queued + x; - emit_sample(buf,ref bufcursor,sampleQueue[i]); - } - queued += extraAtEnd; - audiosize += beststart + extraAtEnd; - } //end else - - //sampleQueue.erase(sampleQueue.begin(), sampleQueue.begin() + queued); - sampleQueue.RemoveRange(0, queued); - //zero 08-nov-2010: did i do this right? - return audiosize; - } - else - { - // normal speed - // just output the samples straightforwardly. - // - // at almost-full speeds (like 50/60 FPS) - // what will happen is that we rapidly fluctuate between entering this branch - // and entering the "slow motion speed" branch above. - // but that's ok! because all of these branches sound similar enough that we can get away with it. - // so the two cases actually complement each other. - - if(audiosize >= queued) - { - emit_samples(buf,ref bufcursor, sampleQueue.ToArray(),0,queued); //sampleQueue.erase(sampleQueue.begin(), sampleQueue.begin() + queued); sampleQueue.RemoveRange(0, queued); //zero 08-nov-2010: did i do this right? - return queued; + return audiosize; } else { - emit_samples(buf,ref bufcursor, sampleQueue.ToArray(),0,audiosize); - //sampleQueue.erase(sampleQueue.begin(), sampleQueue.begin()+audiosize); - sampleQueue.RemoveRange(0, audiosize); - //zero 08-nov-2010: did i do this right? - return audiosize; - } + // normal speed + // just output the samples straightforwardly. + // + // at almost-full speeds (like 50/60 FPS) + // what will happen is that we rapidly fluctuate between entering this branch + // and entering the "slow motion speed" branch above. + // but that's ok! because all of these branches sound similar enough that we can get away with it. + // so the two cases actually complement each other. - } //end normal speed + if (audiosize >= queued) + { + emit_samples(buf, ref bufcursor, sampleQueue.ToArray(), 0, queued); + //sampleQueue.erase(sampleQueue.begin(), sampleQueue.begin() + queued); + sampleQueue.RemoveRange(0, queued); + //zero 08-nov-2010: did i do this right? + return queued; + } + else + { + emit_samples(buf, ref bufcursor, sampleQueue.ToArray(), 0, audiosize); + //sampleQueue.erase(sampleQueue.begin(), sampleQueue.begin()+audiosize); + sampleQueue.RemoveRange(0, audiosize); + //zero 08-nov-2010: did i do this right? + return audiosize; + } - } //end if there is any work to do - else + } //end normal speed + + } //end if there is any work to do + else + { + return 0; + } + + } //output_samples + + + }; //NitsujaSynchronizer + + class VecnaSynchronizer : ISynchronizingAudioBuffer + { + // vecna's attempt at a fully synchronous sound provider. + // It's similar in philosophy to my "BufferedAsync" provider, but BufferedAsync is not + // fully synchronous. + + // Like BufferedAsync, it tries to make most frames 100% correct and just suck it up + // periodically and have a big bad-sounding mistake frame if it has to. + + // It is significantly less ambitious and elaborate than the other methods. + // We'll see if it works better or not! + + // It has a min and maximum amount of excess buffer to deal with minor overflows. + // When fastforwarding, it will discard samples above the maximum excess buffer. + + // When underflowing, it will attempt to resample to a certain threshhold. + // If it underflows beyond that threshhold, it will give up and output silence. + // Since it has done this, it will go ahead and generate some excess silence in order + // to restock its excess buffer. + + struct Sample { - return 0; + public short left, right; + public Sample(short l, short r) + { + left = l; + right = r; + } } - } //output_samples + Queue buffer; + Sample[] resampleBuffer; + const int SamplesInOneFrame = 735; + const int MaxExcessSamples = 2048; -}; //NitsujaSynchronizer + public VecnaSynchronizer() + { + buffer = new Queue(2048); + resampleBuffer = new Sample[2730]; // 2048 * 1.25 - class VecnaSynchronizer : ISynchronizingAudioBuffer - { - // vecna's attempt at a fully synchronous sound provider. - // It's similar in philosophy to my "BufferedAsync" provider, but BufferedAsync is not - // fully synchronous. + // Give us a little buffer wiggle-room + for (int i = 0; i < 367; i++) + buffer.Enqueue(new Sample(0, 0)); + } - // Like BufferedAsync, it tries to make most frames 100% correct and just suck it up - // periodically and have a big bad-sounding mistake frame if it has to. - - // It is significantly less ambitious and elaborate than the other methods. - // We'll see if it works better or not! + public void enqueue_samples(short[] buf, int samples_provided) + { + int ctr = 0; + for (int i = 0; i < samples_provided; i++) + { + short left = buf[ctr++]; + short right = buf[ctr++]; + enqueue_sample(left, right); + } + } - // It has a min and maximum amount of excess buffer to deal with minor overflows. - // When fastforwarding, it will discard samples above the maximum excess buffer. - - // When underflowing, it will attempt to resample to a certain threshhold. - // If it underflows beyond that threshhold, it will give up and output silence. - // Since it has done this, it will go ahead and generate some excess silence in order - // to restock its excess buffer. + public void enqueue_sample(short left, short right) + { + if (buffer.Count >= MaxExcessSamples - 1) + { + // if buffer is overfull, dequeue old samples to make room for new samples. + buffer.Dequeue(); + } + buffer.Enqueue(new Sample(left, right)); + } - struct Sample - { - public short left, right; - public Sample(short l, short r) - { - left = l; - right = r; - } - } + public void clear() + { + buffer.Clear(); + } - Queue buffer; - Sample[] resampleBuffer; + public int output_samples(short[] buf, int samples_requested) + { + if (samples_requested > buffer.Count) + { + // underflow! + if (buffer.Count > samples_requested * 3 / 4) + { + // if we're within 75% of target, then I guess we suck it up and resample. + // we sample in a goofy way, we could probably do it a bit smarter, if we cared more. - const int SamplesInOneFrame = 735; - const int MaxExcessSamples = 2048; + int samples_available = buffer.Count; + for (int i = 0; buffer.Count > 0; i++) + resampleBuffer[i] = buffer.Dequeue(); - public VecnaSynchronizer() - { - buffer = new Queue(2048); - resampleBuffer = new Sample[2730]; // 2048 * 1.25 - - // Give us a little buffer wiggle-room - for (int i=0; i<367; i++) - buffer.Enqueue(new Sample(0,0)); - } - - public void enqueue_samples(short[] buf, int samples_provided) - { - int ctr = 0; - for (int i = 0; i < samples_provided; i++) - { - short left = buf[ctr++]; - short right = buf[ctr++]; - enqueue_sample(left, right); - } - } - - public void enqueue_sample(short left, short right) - { - if (buffer.Count >= MaxExcessSamples - 1) - { - // if buffer is overfull, dequeue old samples to make room for new samples. - buffer.Dequeue(); - } - buffer.Enqueue(new Sample(left, right)); - } - - public void clear() - { - buffer.Clear(); - } - - public int output_samples(short[] buf, int samples_requested) - { - if (samples_requested > buffer.Count) - { - // underflow! - if (buffer.Count > samples_requested * 3 / 4) - { - // if we're within 75% of target, then I guess we suck it up and resample. - // we sample in a goofy way, we could probably do it a bit smarter, if we cared more. - - int samples_available = buffer.Count; - for (int i = 0; buffer.Count > 0; i++) - resampleBuffer[i] = buffer.Dequeue(); - - int index = 0; - for (int i = 0; i 0; i++) - { - Sample sample = buffer.Dequeue(); - buf[index++] += sample.left; - buf[index++] += sample.right; - } - } - return samples_requested; - } - } + int index = 0; + for (int i = 0; i < samples_requested; i++) + { + Sample sample = resampleBuffer[i * samples_available / samples_requested]; + buf[index++] += sample.left; + buf[index++] += sample.right; + } + } + else + { + // we're outside of a "reasonable" underflow. Give up and output silence. + // Do nothing. The whole frame will be excess buffer. + } + } + else + { + // normal operation + //Console.WriteLine("samples in buffer {0}, requested {1}", buffer.Count, samples_requested); + int index = 0; + for (int i = 0; i < samples_requested && buffer.Count > 0; i++) + { + Sample sample = buffer.Dequeue(); + buf[index++] += sample.left; + buf[index++] += sample.right; + } + } + return samples_requested; + } + } } \ No newline at end of file diff --git a/BizHawk.Emulation/Sound/Utilities/SoundMixer.cs b/BizHawk.Emulation/Sound/Utilities/SoundMixer.cs index 40abf99b57..6a8197f730 100644 --- a/BizHawk.Emulation/Sound/Utilities/SoundMixer.cs +++ b/BizHawk.Emulation/Sound/Utilities/SoundMixer.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using BizHawk.Emulation.Common; -namespace BizHawk.Emulation.Sound +namespace BizHawk.Emulation.Common { // This is a straightforward class to mix/chain multiple ISoundProvider sources. diff --git a/BizHawk.Emulation/Sound/Utilities/SpeexResampler.cs b/BizHawk.Emulation/Sound/Utilities/SpeexResampler.cs index fcb745c871..dae26171bc 100644 --- a/BizHawk.Emulation/Sound/Utilities/SpeexResampler.cs +++ b/BizHawk.Emulation/Sound/Utilities/SpeexResampler.cs @@ -6,7 +6,7 @@ using System.Runtime.InteropServices; using BizHawk.Emulation.Common; -namespace BizHawk.Emulation.Sound.Utilities +namespace BizHawk.Emulation.Common { /// /// junk wrapper around LibSpeexDSP. quite inefficient. will be replaced diff --git a/BizHawk.Emulation/Sound/Utilities/Waves.cs b/BizHawk.Emulation/Sound/Utilities/Waves.cs index 427c71d347..89991ebf1c 100644 --- a/BizHawk.Emulation/Sound/Utilities/Waves.cs +++ b/BizHawk.Emulation/Sound/Utilities/Waves.cs @@ -1,53 +1,53 @@ -namespace BizHawk.Emulation.Sound +namespace BizHawk.Emulation.Common { - public static class Waves - { - public static short[] SquareWave; - public static short[] ImperfectSquareWave; - public static short[] NoiseWave; - public static short[] PeriodicWave16; + public static class Waves + { + public static short[] SquareWave; + public static short[] ImperfectSquareWave; + public static short[] NoiseWave; + public static short[] PeriodicWave16; - public static void InitWaves() - { - SquareWave = new short[] - { - -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, - 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767 - }; + public static void InitWaves() + { + SquareWave = new short[] + { + -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, + 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767 + }; - ImperfectSquareWave = new short[] - { - -32768,-30145,-27852,-26213,-24902,-23592,-22282,-20971,-19988,-19005,-18350,-17694,-17366,-17039,-16711,-16711, - 32767, 30145, 27852, 26213, 24902, 23592, 22282, 20971, 19988, 19005, 18350, 17694, 17366, 17039, 16711, 16711 - }; + ImperfectSquareWave = new short[] + { + -32768,-30145,-27852,-26213,-24902,-23592,-22282,-20971,-19988,-19005,-18350,-17694,-17366,-17039,-16711,-16711, + 32767, 30145, 27852, 26213, 24902, 23592, 22282, 20971, 19988, 19005, 18350, 17694, 17366, 17039, 16711, 16711 + }; - PeriodicWave16 = new short[] { 32767, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + PeriodicWave16 = new short[] { 32767, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - NoiseWave = new short[0x1000]; - var rnd = new System.Random(unchecked((int)0xDEADBEEF)); - for (int i = 0; i < NoiseWave.Length; i++) - { - int r = rnd.Next(); - if ((r & 1) > 0) - NoiseWave[i] = short.MaxValue; - } + NoiseWave = new short[0x1000]; + var rnd = new System.Random(unchecked((int)0xDEADBEEF)); + for (int i = 0; i < NoiseWave.Length; i++) + { + int r = rnd.Next(); + if ((r & 1) > 0) + NoiseWave[i] = short.MaxValue; + } - /*TriangleWave = new short[512]; - for (int i = 0; i < 256; i++) - TriangleWave[i] = (short)((ushort.MaxValue*i/256)-short.MinValue); - for (int i = 0; i < 256; i++) - TriangleWave[256+i] = TriangleWave[256-i]; - TriangleWave[256] = short.MaxValue; + /*TriangleWave = new short[512]; + for (int i = 0; i < 256; i++) + TriangleWave[i] = (short)((ushort.MaxValue*i/256)-short.MinValue); + for (int i = 0; i < 256; i++) + TriangleWave[256+i] = TriangleWave[256-i]; + TriangleWave[256] = short.MaxValue; - SawWave = new short[512]; - for (int i = 0; i < 512; i++) - SawWave[i] = (short)((ushort.MaxValue * i / 512) - short.MinValue); + SawWave = new short[512]; + for (int i = 0; i < 512; i++) + SawWave[i] = (short)((ushort.MaxValue * i / 512) - short.MinValue); - SineWave = new short[1024]; - for (int i=0; i<1024; i++) - { - SineWave[i] = (short) (Math.Sin(i*Math.PI*2/1024d)*32767); - }*/ - } - } + SineWave = new short[1024]; + for (int i=0; i<1024; i++) + { + SineWave[i] = (short) (Math.Sin(i*Math.PI*2/1024d)*32767); + }*/ + } + } } \ No newline at end of file diff --git a/BizHawk.Emulation/Sound/VRC6Alt.cs b/BizHawk.Emulation/Sound/VRC6Alt.cs index 25e093ec82..4051088425 100644 --- a/BizHawk.Emulation/Sound/VRC6Alt.cs +++ b/BizHawk.Emulation/Sound/VRC6Alt.cs @@ -5,7 +5,7 @@ using System.Text; using BizHawk.Common; -namespace BizHawk.Emulation.Sound +namespace BizHawk.Emulation.Common.Components { public class VRC6Alt { diff --git a/BizHawk.Emulation/Sound/YM2413.cs b/BizHawk.Emulation/Sound/YM2413.cs index 90a330c7d1..6c4ce230bd 100644 --- a/BizHawk.Emulation/Sound/YM2413.cs +++ b/BizHawk.Emulation/Sound/YM2413.cs @@ -1,16 +1,15 @@ -using System; - -// Credits: +// Credits: // Original emulator written by Mitsutaka Okazaki 2001. // Original conversion to C# by Ben Ryves. // TODO The savestate support here is very simplistic and incomplete. However, this does not result in desyncs as the YM2413 is write-only. // TODO This should eventually be replaced, due to 1) uncertain licensing terms 2) This is not a native C# implementation, but a naive port. +using System; using BizHawk.Common; using BizHawk.Emulation.Common; -namespace BizHawk.Emulation.Sound +namespace BizHawk.Emulation.Common.Components { public sealed class YM2413 : ISoundProvider { diff --git a/BizHawk.Emulation/Sound/YM2612.cs b/BizHawk.Emulation/Sound/YM2612.cs index 5a02fdbcd3..838f41a112 100644 --- a/BizHawk.Emulation/Sound/YM2612.cs +++ b/BizHawk.Emulation/Sound/YM2612.cs @@ -5,7 +5,7 @@ using System.IO; using BizHawk.Emulation.Common; -namespace BizHawk.Emulation.Sound +namespace BizHawk.Emulation.Common.Components { // ====================================================================== // Yamaha YM2612 Emulation Core