BizHawk/ExternalCoreProjects/Virtu/Speaker.cs

103 lines
2.4 KiB
C#
Raw Normal View History

namespace Jellyfish.Virtu
2015-02-17 22:58:25 +00:00
{
Virtu cleanup (#1846) * virtu - tabs instead of spaces * virtu - use nooget for Newtonsoft.Json * virtu - target .net 4.8 * resharper - target C# 8 * virtu - remove unused usings * virtu - remove some unused code * virtu - cleanups * virtu - trace logging - add flags to trace logs * virtu - cleanups * virtu - misc cleanups * virtu - make some stuff internal and simplify the api some * virtu - clock down more things and simplify api more * virtu - lock api down more * virtu- simplify, breaks older savestates however * virtu - simplify more * virtu - cleanup * virtu- more cleanup * virtu - reorg some files * virtu - more cleanup * virtu - more reorg * virtu - more reorg * virtu - make more things internal instead of public * virtu - make more things internal * virtu - update dll * cleanup * virtu - reorg * virtu - remove unitialize from machine component since nothing was utilizing it * virtu - simplify api * virtu - cleanup * virtu - cleanup and lock things down * virtu - lock down and cleanup * virtu - cleanup * virtu - simplify - breaks savestates * virtu - make PeripheralCard an interface with default implementation, breaks savestates * virtu - minimize use of machine component * virtu - cleanup * virtu - start minimizing dependencies * virtu - cleanup * virtu - simplify * apple II - simplify * virtu - move some biz logic into bizhawk * virtu - git rid of MachineComponent * virtu - delete no longer needed code * virtu - reorg * move serialization logic out of virtu and into bizhawk, this was our shenanigans * virtu - some small cleanups * virtu - simplify * virtu - dependency minimization * virtu - minimize dependencies * minimize dependencies * virtu - move drivelight property into component that controls it * virtu - minimize dependencies * virtu - minimize depenencies * move some machine logic to memory class * move some initialize logic into constructor * move initialize logic to constructor * move logic from Initialize to constructor * move initialize logic to constructor, simplify api to bizhawk * dll * virtu - movie some logic back into bizhawk * virtu - move Lagged property from machine to memory component * move more biz logic from virtu to biz * virtu - slight reorg * virtu - move some reset logic to constructor * virtu - move some stuff around * virtu - declare dependencies in memory class, no more dependencies on the machine class * move slots from machine to memory class * move some properties from machine to memory * move more things into the memory class * remove Machine.cs from virtu and make an equivalent container in bizhawk * virtu - cleanup * interface the cassette class and create a biz empty cassette "implementation" * move some more dummy logic from virtu to biz and put an interface in virtu * virtu - use an interface for a dependency * virtu - interface more things * virtu - more interfacing of things * virtu - interface more things * apple II/virtu - some reorg * virtu - cleanup * virtu - remove unused usages of disk name in disk classes * virtu- cleanup and simplify api * virtu - remove unused BootDrive property * virtu - cleanup and interface more * cleanup * update virtu dll
2020-02-14 15:54:35 +00:00
public interface ISpeaker
{
void ToggleOutput();
// ReSharper disable once UnusedMember.Global
void Clear();
// ReSharper disable once UnusedMember.Global
void GetSamples(out short[] samples, out int nSamp);
// ReSharper disable once UnusedMember.Global
void Sync(IComponentSerializer ser);
Virtu cleanup (#1846) * virtu - tabs instead of spaces * virtu - use nooget for Newtonsoft.Json * virtu - target .net 4.8 * resharper - target C# 8 * virtu - remove unused usings * virtu - remove some unused code * virtu - cleanups * virtu - trace logging - add flags to trace logs * virtu - cleanups * virtu - misc cleanups * virtu - make some stuff internal and simplify the api some * virtu - clock down more things and simplify api more * virtu - lock api down more * virtu- simplify, breaks older savestates however * virtu - simplify more * virtu - cleanup * virtu- more cleanup * virtu - reorg some files * virtu - more cleanup * virtu - more reorg * virtu - more reorg * virtu - make more things internal instead of public * virtu - make more things internal * virtu - update dll * cleanup * virtu - reorg * virtu - remove unitialize from machine component since nothing was utilizing it * virtu - simplify api * virtu - cleanup * virtu - cleanup and lock things down * virtu - lock down and cleanup * virtu - cleanup * virtu - simplify - breaks savestates * virtu - make PeripheralCard an interface with default implementation, breaks savestates * virtu - minimize use of machine component * virtu - cleanup * virtu - start minimizing dependencies * virtu - cleanup * virtu - simplify * apple II - simplify * virtu - move some biz logic into bizhawk * virtu - git rid of MachineComponent * virtu - delete no longer needed code * virtu - reorg * move serialization logic out of virtu and into bizhawk, this was our shenanigans * virtu - some small cleanups * virtu - simplify * virtu - dependency minimization * virtu - minimize dependencies * minimize dependencies * virtu - move drivelight property into component that controls it * virtu - minimize dependencies * virtu - minimize depenencies * move some machine logic to memory class * move some initialize logic into constructor * move initialize logic to constructor * move logic from Initialize to constructor * move initialize logic to constructor, simplify api to bizhawk * dll * virtu - movie some logic back into bizhawk * virtu - move Lagged property from machine to memory component * move more biz logic from virtu to biz * virtu - slight reorg * virtu - move some reset logic to constructor * virtu - move some stuff around * virtu - declare dependencies in memory class, no more dependencies on the machine class * move slots from machine to memory class * move some properties from machine to memory * move more things into the memory class * remove Machine.cs from virtu and make an equivalent container in bizhawk * virtu - cleanup * interface the cassette class and create a biz empty cassette "implementation" * move some more dummy logic from virtu to biz and put an interface in virtu * virtu - use an interface for a dependency * virtu - interface more things * virtu - more interfacing of things * virtu - interface more things * apple II/virtu - some reorg * virtu - cleanup * virtu - remove unused usages of disk name in disk classes * virtu- cleanup and simplify api * virtu - remove unused BootDrive property * virtu - cleanup and interface more * cleanup * update virtu dll
2020-02-14 15:54:35 +00:00
}
// ReSharper disable once UnusedMember.Global
Virtu cleanup (#1846) * virtu - tabs instead of spaces * virtu - use nooget for Newtonsoft.Json * virtu - target .net 4.8 * resharper - target C# 8 * virtu - remove unused usings * virtu - remove some unused code * virtu - cleanups * virtu - trace logging - add flags to trace logs * virtu - cleanups * virtu - misc cleanups * virtu - make some stuff internal and simplify the api some * virtu - clock down more things and simplify api more * virtu - lock api down more * virtu- simplify, breaks older savestates however * virtu - simplify more * virtu - cleanup * virtu- more cleanup * virtu - reorg some files * virtu - more cleanup * virtu - more reorg * virtu - more reorg * virtu - make more things internal instead of public * virtu - make more things internal * virtu - update dll * cleanup * virtu - reorg * virtu - remove unitialize from machine component since nothing was utilizing it * virtu - simplify api * virtu - cleanup * virtu - cleanup and lock things down * virtu - lock down and cleanup * virtu - cleanup * virtu - simplify - breaks savestates * virtu - make PeripheralCard an interface with default implementation, breaks savestates * virtu - minimize use of machine component * virtu - cleanup * virtu - start minimizing dependencies * virtu - cleanup * virtu - simplify * apple II - simplify * virtu - move some biz logic into bizhawk * virtu - git rid of MachineComponent * virtu - delete no longer needed code * virtu - reorg * move serialization logic out of virtu and into bizhawk, this was our shenanigans * virtu - some small cleanups * virtu - simplify * virtu - dependency minimization * virtu - minimize dependencies * minimize dependencies * virtu - move drivelight property into component that controls it * virtu - minimize dependencies * virtu - minimize depenencies * move some machine logic to memory class * move some initialize logic into constructor * move initialize logic to constructor * move logic from Initialize to constructor * move initialize logic to constructor, simplify api to bizhawk * dll * virtu - movie some logic back into bizhawk * virtu - move Lagged property from machine to memory component * move more biz logic from virtu to biz * virtu - slight reorg * virtu - move some reset logic to constructor * virtu - move some stuff around * virtu - declare dependencies in memory class, no more dependencies on the machine class * move slots from machine to memory class * move some properties from machine to memory * move more things into the memory class * remove Machine.cs from virtu and make an equivalent container in bizhawk * virtu - cleanup * interface the cassette class and create a biz empty cassette "implementation" * move some more dummy logic from virtu to biz and put an interface in virtu * virtu - use an interface for a dependency * virtu - interface more things * virtu - more interfacing of things * virtu - interface more things * apple II/virtu - some reorg * virtu - cleanup * virtu - remove unused usages of disk name in disk classes * virtu- cleanup and simplify api * virtu - remove unused BootDrive property * virtu - cleanup and interface more * cleanup * update virtu dll
2020-02-14 15:54:35 +00:00
public sealed class Speaker : ISpeaker
{
private const int CyclesPerFlush = 23;
private readonly MachineEvents _events;
private readonly ICpu _cpu;
Virtu cleanup (#1846) * virtu - tabs instead of spaces * virtu - use nooget for Newtonsoft.Json * virtu - target .net 4.8 * resharper - target C# 8 * virtu - remove unused usings * virtu - remove some unused code * virtu - cleanups * virtu - trace logging - add flags to trace logs * virtu - cleanups * virtu - misc cleanups * virtu - make some stuff internal and simplify the api some * virtu - clock down more things and simplify api more * virtu - lock api down more * virtu- simplify, breaks older savestates however * virtu - simplify more * virtu - cleanup * virtu- more cleanup * virtu - reorg some files * virtu - more cleanup * virtu - more reorg * virtu - more reorg * virtu - make more things internal instead of public * virtu - make more things internal * virtu - update dll * cleanup * virtu - reorg * virtu - remove unitialize from machine component since nothing was utilizing it * virtu - simplify api * virtu - cleanup * virtu - cleanup and lock things down * virtu - lock down and cleanup * virtu - cleanup * virtu - simplify - breaks savestates * virtu - make PeripheralCard an interface with default implementation, breaks savestates * virtu - minimize use of machine component * virtu - cleanup * virtu - start minimizing dependencies * virtu - cleanup * virtu - simplify * apple II - simplify * virtu - move some biz logic into bizhawk * virtu - git rid of MachineComponent * virtu - delete no longer needed code * virtu - reorg * move serialization logic out of virtu and into bizhawk, this was our shenanigans * virtu - some small cleanups * virtu - simplify * virtu - dependency minimization * virtu - minimize dependencies * minimize dependencies * virtu - move drivelight property into component that controls it * virtu - minimize dependencies * virtu - minimize depenencies * move some machine logic to memory class * move some initialize logic into constructor * move initialize logic to constructor * move logic from Initialize to constructor * move initialize logic to constructor, simplify api to bizhawk * dll * virtu - movie some logic back into bizhawk * virtu - move Lagged property from machine to memory component * move more biz logic from virtu to biz * virtu - slight reorg * virtu - move some reset logic to constructor * virtu - move some stuff around * virtu - declare dependencies in memory class, no more dependencies on the machine class * move slots from machine to memory class * move some properties from machine to memory * move more things into the memory class * remove Machine.cs from virtu and make an equivalent container in bizhawk * virtu - cleanup * interface the cassette class and create a biz empty cassette "implementation" * move some more dummy logic from virtu to biz and put an interface in virtu * virtu - use an interface for a dependency * virtu - interface more things * virtu - more interfacing of things * virtu - interface more things * apple II/virtu - some reorg * virtu - cleanup * virtu - remove unused usages of disk name in disk classes * virtu- cleanup and simplify api * virtu - remove unused BootDrive property * virtu - cleanup and interface more * cleanup * update virtu dll
2020-02-14 15:54:35 +00:00
private bool _isHigh;
private int _highCycles;
private int _totalCycles;
private long _lastCycles;
// only relevant if trying to savestate mid-frame
Virtu cleanup (#1846) * virtu - tabs instead of spaces * virtu - use nooget for Newtonsoft.Json * virtu - target .net 4.8 * resharper - target C# 8 * virtu - remove unused usings * virtu - remove some unused code * virtu - cleanups * virtu - trace logging - add flags to trace logs * virtu - cleanups * virtu - misc cleanups * virtu - make some stuff internal and simplify the api some * virtu - clock down more things and simplify api more * virtu - lock api down more * virtu- simplify, breaks older savestates however * virtu - simplify more * virtu - cleanup * virtu- more cleanup * virtu - reorg some files * virtu - more cleanup * virtu - more reorg * virtu - more reorg * virtu - make more things internal instead of public * virtu - make more things internal * virtu - update dll * cleanup * virtu - reorg * virtu - remove unitialize from machine component since nothing was utilizing it * virtu - simplify api * virtu - cleanup * virtu - cleanup and lock things down * virtu - lock down and cleanup * virtu - cleanup * virtu - simplify - breaks savestates * virtu - make PeripheralCard an interface with default implementation, breaks savestates * virtu - minimize use of machine component * virtu - cleanup * virtu - start minimizing dependencies * virtu - cleanup * virtu - simplify * apple II - simplify * virtu - move some biz logic into bizhawk * virtu - git rid of MachineComponent * virtu - delete no longer needed code * virtu - reorg * move serialization logic out of virtu and into bizhawk, this was our shenanigans * virtu - some small cleanups * virtu - simplify * virtu - dependency minimization * virtu - minimize dependencies * minimize dependencies * virtu - move drivelight property into component that controls it * virtu - minimize dependencies * virtu - minimize depenencies * move some machine logic to memory class * move some initialize logic into constructor * move initialize logic to constructor * move logic from Initialize to constructor * move initialize logic to constructor, simplify api to bizhawk * dll * virtu - movie some logic back into bizhawk * virtu - move Lagged property from machine to memory component * move more biz logic from virtu to biz * virtu - slight reorg * virtu - move some reset logic to constructor * virtu - move some stuff around * virtu - declare dependencies in memory class, no more dependencies on the machine class * move slots from machine to memory class * move some properties from machine to memory * move more things into the memory class * remove Machine.cs from virtu and make an equivalent container in bizhawk * virtu - cleanup * interface the cassette class and create a biz empty cassette "implementation" * move some more dummy logic from virtu to biz and put an interface in virtu * virtu - use an interface for a dependency * virtu - interface more things * virtu - more interfacing of things * virtu - interface more things * apple II/virtu - some reorg * virtu - cleanup * virtu - remove unused usages of disk name in disk classes * virtu- cleanup and simplify api * virtu - remove unused BootDrive property * virtu - cleanup and interface more * cleanup * update virtu dll
2020-02-14 15:54:35 +00:00
private readonly short[] _buffer = new short[4096];
private int _position;
public Speaker(MachineEvents events, ICpu cpu)
{
_events = events;
_cpu = cpu;
_events.AddEventDelegate(EventCallbacks.FlushOutput, FlushOutputEvent);
_events.AddEvent(CyclesPerFlush * _cpu.Multiplier, EventCallbacks.FlushOutput);
_isHigh = false;
_highCycles = _totalCycles = 0;
}
public void Sync(IComponentSerializer ser)
{
ser.Sync(nameof(_isHigh), ref _isHigh);
ser.Sync(nameof(_highCycles), ref _highCycles);
ser.Sync(nameof(_totalCycles), ref _totalCycles);
ser.Sync(nameof(_lastCycles), ref _lastCycles);
}
Virtu cleanup (#1846) * virtu - tabs instead of spaces * virtu - use nooget for Newtonsoft.Json * virtu - target .net 4.8 * resharper - target C# 8 * virtu - remove unused usings * virtu - remove some unused code * virtu - cleanups * virtu - trace logging - add flags to trace logs * virtu - cleanups * virtu - misc cleanups * virtu - make some stuff internal and simplify the api some * virtu - clock down more things and simplify api more * virtu - lock api down more * virtu- simplify, breaks older savestates however * virtu - simplify more * virtu - cleanup * virtu- more cleanup * virtu - reorg some files * virtu - more cleanup * virtu - more reorg * virtu - more reorg * virtu - make more things internal instead of public * virtu - make more things internal * virtu - update dll * cleanup * virtu - reorg * virtu - remove unitialize from machine component since nothing was utilizing it * virtu - simplify api * virtu - cleanup * virtu - cleanup and lock things down * virtu - lock down and cleanup * virtu - cleanup * virtu - simplify - breaks savestates * virtu - make PeripheralCard an interface with default implementation, breaks savestates * virtu - minimize use of machine component * virtu - cleanup * virtu - start minimizing dependencies * virtu - cleanup * virtu - simplify * apple II - simplify * virtu - move some biz logic into bizhawk * virtu - git rid of MachineComponent * virtu - delete no longer needed code * virtu - reorg * move serialization logic out of virtu and into bizhawk, this was our shenanigans * virtu - some small cleanups * virtu - simplify * virtu - dependency minimization * virtu - minimize dependencies * minimize dependencies * virtu - move drivelight property into component that controls it * virtu - minimize dependencies * virtu - minimize depenencies * move some machine logic to memory class * move some initialize logic into constructor * move initialize logic to constructor * move logic from Initialize to constructor * move initialize logic to constructor, simplify api to bizhawk * dll * virtu - movie some logic back into bizhawk * virtu - move Lagged property from machine to memory component * move more biz logic from virtu to biz * virtu - slight reorg * virtu - move some reset logic to constructor * virtu - move some stuff around * virtu - declare dependencies in memory class, no more dependencies on the machine class * move slots from machine to memory class * move some properties from machine to memory * move more things into the memory class * remove Machine.cs from virtu and make an equivalent container in bizhawk * virtu - cleanup * interface the cassette class and create a biz empty cassette "implementation" * move some more dummy logic from virtu to biz and put an interface in virtu * virtu - use an interface for a dependency * virtu - interface more things * virtu - more interfacing of things * virtu - interface more things * apple II/virtu - some reorg * virtu - cleanup * virtu - remove unused usages of disk name in disk classes * virtu- cleanup and simplify api * virtu - remove unused BootDrive property * virtu - cleanup and interface more * cleanup * update virtu dll
2020-02-14 15:54:35 +00:00
public void Clear()
{
_position = 0;
}
public void GetSamples(out short[] samples, out int nSamp)
{
samples = _buffer;
nSamp = _position / 2;
_position = 0;
}
public void ToggleOutput()
{
UpdateCycles();
_isHigh ^= true;
}
private void FlushOutputEvent()
{
UpdateCycles();
2015-05-18 00:14:00 +00:00
// TODO: better than simple decimation here!!
Virtu cleanup (#1846) * virtu - tabs instead of spaces * virtu - use nooget for Newtonsoft.Json * virtu - target .net 4.8 * resharper - target C# 8 * virtu - remove unused usings * virtu - remove some unused code * virtu - cleanups * virtu - trace logging - add flags to trace logs * virtu - cleanups * virtu - misc cleanups * virtu - make some stuff internal and simplify the api some * virtu - clock down more things and simplify api more * virtu - lock api down more * virtu- simplify, breaks older savestates however * virtu - simplify more * virtu - cleanup * virtu- more cleanup * virtu - reorg some files * virtu - more cleanup * virtu - more reorg * virtu - more reorg * virtu - make more things internal instead of public * virtu - make more things internal * virtu - update dll * cleanup * virtu - reorg * virtu - remove unitialize from machine component since nothing was utilizing it * virtu - simplify api * virtu - cleanup * virtu - cleanup and lock things down * virtu - lock down and cleanup * virtu - cleanup * virtu - simplify - breaks savestates * virtu - make PeripheralCard an interface with default implementation, breaks savestates * virtu - minimize use of machine component * virtu - cleanup * virtu - start minimizing dependencies * virtu - cleanup * virtu - simplify * apple II - simplify * virtu - move some biz logic into bizhawk * virtu - git rid of MachineComponent * virtu - delete no longer needed code * virtu - reorg * move serialization logic out of virtu and into bizhawk, this was our shenanigans * virtu - some small cleanups * virtu - simplify * virtu - dependency minimization * virtu - minimize dependencies * minimize dependencies * virtu - move drivelight property into component that controls it * virtu - minimize dependencies * virtu - minimize depenencies * move some machine logic to memory class * move some initialize logic into constructor * move initialize logic to constructor * move logic from Initialize to constructor * move initialize logic to constructor, simplify api to bizhawk * dll * virtu - movie some logic back into bizhawk * virtu - move Lagged property from machine to memory component * move more biz logic from virtu to biz * virtu - slight reorg * virtu - move some reset logic to constructor * virtu - move some stuff around * virtu - declare dependencies in memory class, no more dependencies on the machine class * move slots from machine to memory class * move some properties from machine to memory * move more things into the memory class * remove Machine.cs from virtu and make an equivalent container in bizhawk * virtu - cleanup * interface the cassette class and create a biz empty cassette "implementation" * move some more dummy logic from virtu to biz and put an interface in virtu * virtu - use an interface for a dependency * virtu - interface more things * virtu - more interfacing of things * virtu - interface more things * apple II/virtu - some reorg * virtu - cleanup * virtu - remove unused usages of disk name in disk classes * virtu- cleanup and simplify api * virtu - remove unused BootDrive property * virtu - cleanup and interface more * cleanup * update virtu dll
2020-02-14 15:54:35 +00:00
Output(_highCycles * short.MaxValue / _totalCycles);
_highCycles = _totalCycles = 0;
_events.AddEvent(CyclesPerFlush * _cpu.Multiplier, EventCallbacks.FlushOutput);
Virtu cleanup (#1846) * virtu - tabs instead of spaces * virtu - use nooget for Newtonsoft.Json * virtu - target .net 4.8 * resharper - target C# 8 * virtu - remove unused usings * virtu - remove some unused code * virtu - cleanups * virtu - trace logging - add flags to trace logs * virtu - cleanups * virtu - misc cleanups * virtu - make some stuff internal and simplify the api some * virtu - clock down more things and simplify api more * virtu - lock api down more * virtu- simplify, breaks older savestates however * virtu - simplify more * virtu - cleanup * virtu- more cleanup * virtu - reorg some files * virtu - more cleanup * virtu - more reorg * virtu - more reorg * virtu - make more things internal instead of public * virtu - make more things internal * virtu - update dll * cleanup * virtu - reorg * virtu - remove unitialize from machine component since nothing was utilizing it * virtu - simplify api * virtu - cleanup * virtu - cleanup and lock things down * virtu - lock down and cleanup * virtu - cleanup * virtu - simplify - breaks savestates * virtu - make PeripheralCard an interface with default implementation, breaks savestates * virtu - minimize use of machine component * virtu - cleanup * virtu - start minimizing dependencies * virtu - cleanup * virtu - simplify * apple II - simplify * virtu - move some biz logic into bizhawk * virtu - git rid of MachineComponent * virtu - delete no longer needed code * virtu - reorg * move serialization logic out of virtu and into bizhawk, this was our shenanigans * virtu - some small cleanups * virtu - simplify * virtu - dependency minimization * virtu - minimize dependencies * minimize dependencies * virtu - move drivelight property into component that controls it * virtu - minimize dependencies * virtu - minimize depenencies * move some machine logic to memory class * move some initialize logic into constructor * move initialize logic to constructor * move logic from Initialize to constructor * move initialize logic to constructor, simplify api to bizhawk * dll * virtu - movie some logic back into bizhawk * virtu - move Lagged property from machine to memory component * move more biz logic from virtu to biz * virtu - slight reorg * virtu - move some reset logic to constructor * virtu - move some stuff around * virtu - declare dependencies in memory class, no more dependencies on the machine class * move slots from machine to memory class * move some properties from machine to memory * move more things into the memory class * remove Machine.cs from virtu and make an equivalent container in bizhawk * virtu - cleanup * interface the cassette class and create a biz empty cassette "implementation" * move some more dummy logic from virtu to biz and put an interface in virtu * virtu - use an interface for a dependency * virtu - interface more things * virtu - more interfacing of things * virtu - interface more things * apple II/virtu - some reorg * virtu - cleanup * virtu - remove unused usages of disk name in disk classes * virtu- cleanup and simplify api * virtu - remove unused BootDrive property * virtu - cleanup and interface more * cleanup * update virtu dll
2020-02-14 15:54:35 +00:00
}
private void UpdateCycles()
{
int delta = (int)(_cpu.Cycles - _lastCycles);
if (_isHigh)
{
_highCycles += delta;
}
_totalCycles += delta;
_lastCycles = _cpu.Cycles;
}
private void Output(int data) // machine thread
{
data = (int)(data * 0.2);
if (_position < _buffer.Length - 2)
{
_buffer[_position++] = (short)data;
_buffer[_position++] = (short)data;
}
}
}
2015-02-17 22:58:25 +00:00
}