possibly make intellivision sound worse
This commit is contained in:
parent
98c1ccab4d
commit
7814c26d9d
|
@ -21,9 +21,6 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
else
|
||||
_cpu.TraceCallback = null;
|
||||
|
||||
//reset the count of audio samples
|
||||
_psg.sample_count = 0;
|
||||
|
||||
_frame++;
|
||||
stic_row = -1;
|
||||
// read the controller state here for now
|
||||
|
|
|
@ -7,16 +7,25 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
{
|
||||
public sealed class PSG : ISoundProvider
|
||||
{
|
||||
private BlipBuffer _blip = new BlipBuffer(4096);
|
||||
private short[] _sampleBuffer = new short[0];
|
||||
|
||||
|
||||
public PSG()
|
||||
{
|
||||
_blip.SetRates(894866 / 4.0, 44100);
|
||||
}
|
||||
|
||||
public ushort[] Register = new ushort[16];
|
||||
|
||||
public int total_clock;
|
||||
public int total_clock; // TODO: what is this uaed for?
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
clock_A = clock_B = clock_C = 0x1000;
|
||||
noise_clock = 0x20;
|
||||
|
||||
for (int i=0;i<16;i++)
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
Register[i] = 0x0000;
|
||||
}
|
||||
|
@ -26,7 +35,8 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
|
||||
public void DiscardSamples()
|
||||
{
|
||||
sample_count = 0;
|
||||
_blip.Clear();
|
||||
_sampleClock = 0;
|
||||
}
|
||||
|
||||
public void GetSamplesAsync(short[] samples)
|
||||
|
@ -54,28 +64,33 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
|
||||
public void GetSamplesSync(out short[] samples, out int nsamp)
|
||||
{
|
||||
short[] ret = new short[736 * 2];
|
||||
GetSamples(ret);
|
||||
samples = ret;
|
||||
nsamp = 736;
|
||||
_blip.EndFrame((uint)_sampleClock);
|
||||
_sampleClock = 0;
|
||||
|
||||
nsamp = _blip.SamplesAvailable();
|
||||
int targetLength = nsamp * 2;
|
||||
if (_sampleBuffer.Length != targetLength)
|
||||
_sampleBuffer = new short[targetLength];
|
||||
|
||||
_blip.ReadSamplesLeft(_sampleBuffer, nsamp);
|
||||
for (int i = 0; i < _sampleBuffer.Length; i += 2)
|
||||
{
|
||||
_sampleBuffer[i + 1] = _sampleBuffer[i];
|
||||
}
|
||||
|
||||
samples = _sampleBuffer;
|
||||
}
|
||||
|
||||
public void GetSamples(short[] samples)
|
||||
{
|
||||
for (int i = 0; i < samples.Length / 2; i++)
|
||||
{
|
||||
samples[i * 2] = (short)(audio_samples[(int)Math.Floor(5.072*i)]);
|
||||
samples[(i * 2) + 1] = samples[i * 2];
|
||||
}
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
// There is one audio clock for every 4 cpu clocks, and ~15000 cycles per frame
|
||||
public short[] audio_samples = new short[4000];
|
||||
|
||||
public static int[] volume_table = new int[16] {0x0000, 0x0055, 0x0079, 0x00AB, 0x00F1, 0x0155, 0x01E3, 0x02AA,
|
||||
0x03C5, 0x0555, 0x078B, 0x0AAB, 0x0F16, 0x1555, 0x1E2B, 0x2AAA};
|
||||
|
||||
public int sample_count;
|
||||
private int _sampleClock;
|
||||
private int _latchedSample;
|
||||
|
||||
public int TotalExecutedCycles;
|
||||
public int PendingCycles;
|
||||
|
@ -98,7 +113,7 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
|
||||
public int noise_clock;
|
||||
public int noise_per;
|
||||
public int noise=0x1;
|
||||
public int noise = 0x1;
|
||||
|
||||
public Func<ushort, bool, ushort> ReadMemory;
|
||||
public Func<ushort, ushort, bool, bool> WriteMemory;
|
||||
|
@ -111,7 +126,6 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
ser.Sync("Toal_executed_cycles", ref TotalExecutedCycles);
|
||||
ser.Sync("Pending_Cycles", ref PendingCycles);
|
||||
|
||||
ser.Sync("sample_count", ref sample_count);
|
||||
ser.Sync("psg_clock", ref psg_clock);
|
||||
ser.Sync("clock_A", ref clock_A);
|
||||
ser.Sync("clock_B", ref clock_B);
|
||||
|
@ -239,11 +253,11 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
bool sound_out_B;
|
||||
bool sound_out_C;
|
||||
|
||||
for (int i=0;i<cycles_to_do;i++)
|
||||
for (int i = 0; i < cycles_to_do; i++)
|
||||
{
|
||||
psg_clock++;
|
||||
|
||||
if (psg_clock==4)
|
||||
if (psg_clock == 4)
|
||||
{
|
||||
psg_clock = 0;
|
||||
|
||||
|
@ -313,13 +327,13 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
clock_A = sq_per_A;
|
||||
}
|
||||
|
||||
if (clock_B ==0)
|
||||
if (clock_B == 0)
|
||||
{
|
||||
B_up = !B_up;
|
||||
clock_B = sq_per_B;
|
||||
}
|
||||
|
||||
if (clock_C ==0)
|
||||
if (clock_C == 0)
|
||||
{
|
||||
C_up = !C_up;
|
||||
clock_C = sq_per_C;
|
||||
|
@ -331,21 +345,23 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
sound_out_C = (noise.Bit(0) | C_noise) & (C_on | C_up);
|
||||
|
||||
//now calculate the volume of each channel and add them together
|
||||
int v;
|
||||
|
||||
if (env_vol_A == 0)
|
||||
{
|
||||
audio_samples[sample_count] = (short)(sound_out_A ? volume_table[vol_A] : 0);
|
||||
v = (short)(sound_out_A ? volume_table[vol_A] : 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
int shift_A = 3-env_vol_A;
|
||||
int shift_A = 3 - env_vol_A;
|
||||
if (shift_A < 0)
|
||||
shift_A = 0;
|
||||
audio_samples[sample_count] = (short)(sound_out_A ? (volume_table[env_E]>>shift_A) : 0);
|
||||
v = (short)(sound_out_A ? (volume_table[env_E] >> shift_A) : 0);
|
||||
}
|
||||
|
||||
if (env_vol_B == 0)
|
||||
{
|
||||
audio_samples[sample_count] += (short)(sound_out_B ? volume_table[vol_B] : 0);
|
||||
v += (short)(sound_out_B ? volume_table[vol_B] : 0);
|
||||
|
||||
}
|
||||
else
|
||||
|
@ -353,22 +369,28 @@ namespace BizHawk.Emulation.Cores.Intellivision
|
|||
int shift_B = 3 - env_vol_B;
|
||||
if (shift_B < 0)
|
||||
shift_B = 0;
|
||||
audio_samples[sample_count] += (short)(sound_out_B ? (volume_table[env_E] >> shift_B) : 0);
|
||||
v += (short)(sound_out_B ? (volume_table[env_E] >> shift_B) : 0);
|
||||
}
|
||||
|
||||
if (env_vol_C == 0)
|
||||
{
|
||||
audio_samples[sample_count] += (short)(sound_out_C ? volume_table[vol_C] : 0);
|
||||
v += (short)(sound_out_C ? volume_table[vol_C] : 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
int shift_C = 3 - env_vol_C;
|
||||
if (shift_C < 0)
|
||||
shift_C = 0;
|
||||
audio_samples[sample_count] += (short)(sound_out_C ? (volume_table[env_E] >> shift_C) : 0);
|
||||
v += (short)(sound_out_C ? (volume_table[env_E] >> shift_C) : 0);
|
||||
}
|
||||
|
||||
sample_count++;
|
||||
if (v != _latchedSample)
|
||||
{
|
||||
_blip.AddDelta((uint)_sampleClock, v - _latchedSample);
|
||||
_latchedSample = v;
|
||||
}
|
||||
|
||||
_sampleClock++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue