C64: connect audio to speexresampler. consider this commit a demonstration on "how it could be done"...

This commit is contained in:
goyuken 2012-12-08 16:05:00 +00:00
parent 1d3ff8524a
commit 1b83110a37
5 changed files with 40 additions and 20 deletions

View File

@ -57,9 +57,9 @@ namespace BizHawk.Emulation.Computers.Commodore64
// audio/video
public void EndAsyncSound() { } //TODO
public ISoundProvider SoundProvider { get { return board.sid; } }
public bool StartAsyncSound() { return true; } //TODO
public ISyncSoundProvider SyncSoundProvider { get { return board.sid; } }
public ISoundProvider SoundProvider { get { return null; } }
public bool StartAsyncSound() { return false; } //TODO
public ISyncSoundProvider SyncSoundProvider { get { return board.sid.resampler; } }
public IVideoProvider VideoProvider { get { return board.vic; } }
// controller

View File

@ -6,7 +6,7 @@ using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
// sid
public class MOS6581 : Sid, ISoundProvider, ISyncSoundProvider
public class MOS6581 : Sid
{
static uint[][] waveTable = new uint[][]
{

View File

@ -5,16 +5,21 @@ using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
public abstract partial class Sid : ISoundProvider
/*
* this wasn't sounding as good as a vecna metaspu
*/
public abstract partial class Sid //: ISoundProvider
{
/*
private short[] buffer;
private uint bufferCounter;
private uint bufferFrequency;
private uint bufferIndex;
private uint bufferLength;
private uint bufferReadOffset;
*/
private uint cyclesPerSec;
/*
public void GetSamples(short[] samples)
{
bool overrun = false;
@ -57,5 +62,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// no change in volume
}
}
*/
}
}

View File

@ -5,8 +5,10 @@ using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
public abstract partial class Sid : ISyncSoundProvider
public abstract partial class Sid : IDisposable
{
public Sound.Utilities.SpeexResampler resampler;
/*
public void GetSamples(out short[] samples, out int nsamp)
{
if (bufferIndex > bufferReadOffset)
@ -31,5 +33,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
bufferIndex = 0;
bufferReadOffset = 0;
}
*/
public void Dispose()
{
if (resampler != null)
{
resampler.Dispose();
resampler = null;
}
}
}
}

View File

@ -645,11 +645,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
switch (newRegion)
{
case Region.NTSC: cyclesPerSec = 14318181 / 14; bufferLength = (newSampleRate / 60) * 4; break;
case Region.PAL: cyclesPerSec = 17734472 / 18; bufferLength = (newSampleRate / 50) * 4; break;
case Region.NTSC: cyclesPerSec = 14318181 / 14; /*bufferLength = (newSampleRate / 60) * 4;*/ break;
case Region.PAL: cyclesPerSec = 17734472 / 18; /*bufferLength = (newSampleRate / 50) * 4;*/ break;
}
bufferFrequency = cyclesPerSec / newSampleRate;
buffer = new short[bufferLength];
//bufferFrequency = cyclesPerSec / newSampleRate;
//buffer = new short[bufferLength];
waveformTable = newWaveformTable;
@ -666,6 +666,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
filterEnable = new bool[3];
for (int i = 0; i < 3; i++)
filterEnable[i] = false;
resampler = new Sound.Utilities.SpeexResampler(0, cyclesPerSec, 44100, cyclesPerSec, 44100, null, null);
}
// ------------------------------------
@ -722,11 +724,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
envelopeOutput[2] = envelopes[2].Level;
// process output
if (bufferCounter == 0)
{
//if (bufferCounter == 0)
//{
uint mixer;
short sample;
bufferCounter = bufferFrequency;
//bufferCounter = bufferFrequency;
// mix each channel (20 bits)
mixer = ((voiceOutput[0] * envelopeOutput[0]) >> 7);
@ -735,12 +737,13 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
mixer = (mixer * volume) >> 4;
sample = (short)mixer;
buffer[bufferIndex++] = sample;
buffer[bufferIndex++] = sample;
if (bufferIndex == bufferLength)
bufferIndex = 0;
}
bufferCounter--;
//buffer[bufferIndex++] = sample;
//buffer[bufferIndex++] = sample;
resampler.EnqueueSample(sample, sample);
//if (bufferIndex == bufferLength)
// bufferIndex = 0;
//}
//bufferCounter--;
}
}