From 1b83110a377c38d0a66f94e8c9a9f3fdec36d62f Mon Sep 17 00:00:00 2001 From: goyuken Date: Sat, 8 Dec 2012 16:05:00 +0000 Subject: [PATCH] C64: connect audio to speexresampler. consider this commit a demonstration on "how it could be done"... --- .../Computers/Commodore64/C64.cs | 6 ++-- .../Computers/Commodore64/MOS/MOS6581.cs | 2 +- .../Commodore64/MOS/Sid.SoundProvider.cs | 10 +++++-- .../Commodore64/MOS/Sid.SyncSoundProvider.cs | 13 ++++++++- .../Computers/Commodore64/MOS/Sid.cs | 29 ++++++++++--------- 5 files changed, 40 insertions(+), 20 deletions(-) diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.cs b/BizHawk.Emulation/Computers/Commodore64/C64.cs index 60b70716a4..2aee37c0b0 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.cs @@ -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 diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6581.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6581.cs index eda6647af0..7d5cb6069d 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6581.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6581.cs @@ -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[][] { diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.SoundProvider.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.SoundProvider.cs index 7aab04dfab..6048ce8fa6 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.SoundProvider.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.SoundProvider.cs @@ -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 } } + */ } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.SyncSoundProvider.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.SyncSoundProvider.cs index 46e856d17c..72d0d1c3b3 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.SyncSoundProvider.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.SyncSoundProvider.cs @@ -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; + } + } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs index 7bc09636a7..8019915230 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs @@ -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--; } }