Fix naming of ISynchronizingAudioBuffer method and param names

This commit is contained in:
adelikat 2017-04-25 13:22:25 -05:00
parent eee0ba69dc
commit 9ecf2aed7f
3 changed files with 45 additions and 46 deletions

View File

@ -9,29 +9,29 @@ namespace BizHawk.Emulation.Common
// Sound Refactor TODO: rename me to MetaspuAsyncSoundProvider // Sound Refactor TODO: rename me to MetaspuAsyncSoundProvider
public class MetaspuAsync : ISoundProvider public class MetaspuAsync : ISoundProvider
{ {
private readonly ISynchronizingAudioBuffer buffer; private readonly ISynchronizingAudioBuffer _buffer;
private readonly ISoundProvider input; private readonly ISoundProvider _input;
public MetaspuAsync(ISoundProvider input, ESynchMethod method) public MetaspuAsync(ISoundProvider input, ESynchMethod method)
{ {
input.SetSyncMode(SyncSoundMode.Sync); input.SetSyncMode(SyncSoundMode.Sync);
buffer = Metaspu.metaspu_construct(method); _buffer = Metaspu.metaspu_construct(method);
this.input = input; _input = input;
} }
public void GetSamplesAsync(short[] samples) public void GetSamplesAsync(short[] samples)
{ {
short[] sampin; short[] sampin;
int numsamp; int numsamp;
input.GetSamplesSync(out sampin, out numsamp); _input.GetSamplesSync(out sampin, out numsamp);
buffer.enqueue_samples(sampin, numsamp); _buffer.EnqueueSamples(sampin, numsamp);
buffer.output_samples(samples, samples.Length / 2); _buffer.OutputSamples(samples, samples.Length / 2);
} }
public void DiscardSamples() public void DiscardSamples()
{ {
input.DiscardSamples(); _input.DiscardSamples();
buffer.clear(); _buffer.Clear();
} }
public bool CanProvideAsync => true; public bool CanProvideAsync => true;
@ -54,16 +54,16 @@ namespace BizHawk.Emulation.Common
public interface ISynchronizingAudioBuffer public interface ISynchronizingAudioBuffer
{ {
void enqueue_samples(short[] buf, int samples_provided); void EnqueueSamples(short[] buf, int samplesProvided);
void enqueue_sample(short left, short right); void EnqueueSample(short left, short right);
void clear(); void Clear();
// returns the number of samples actually supplied, which may not match the number requested // returns the number of samples actually supplied, which may not match the number requested
// ^^ what the hell is that supposed to mean. // ^^ what the hell is that supposed to mean.
// the entire point of an ISynchronzingAudioBuffer // the entire point of an ISynchronzingAudioBuffer
// is to provide exact amounts of output samples, // is to provide exact amounts of output samples,
// even when the input provided varies.... // even when the input provided varies....
int output_samples(short[] buf, int samples_requested); int OutputSamples(short[] buf, int samplesRequested);
} }
public enum ESynchMethod public enum ESynchMethod
@ -92,7 +92,7 @@ namespace BizHawk.Emulation.Common
} }
} }
class ZeromusSynchronizer : ISynchronizingAudioBuffer internal class ZeromusSynchronizer : ISynchronizingAudioBuffer
{ {
public ZeromusSynchronizer() public ZeromusSynchronizer()
{ {
@ -105,19 +105,19 @@ namespace BizHawk.Emulation.Common
} }
//adjustobuf(200,1000) //adjustobuf(200,1000)
bool mixqueue_go; private bool mixqueue_go;
public void clear() public void Clear()
{ {
adjustobuf.clear(); adjustobuf.clear();
} }
public void enqueue_sample(short left, short right) public void EnqueueSample(short left, short right)
{ {
adjustobuf.enqueue(left, right); adjustobuf.enqueue(left, right);
} }
public void enqueue_samples(short[] buf, int samples_provided) public void EnqueueSamples(short[] buf, int samples_provided)
{ {
int ctr = 0; int ctr = 0;
for (int i = 0; i < samples_provided; i++) for (int i = 0; i < samples_provided; i++)
@ -129,7 +129,7 @@ namespace BizHawk.Emulation.Common
} }
// returns the number of samples actually supplied, which may not match the number requested // returns the number of samples actually supplied, which may not match the number requested
public int output_samples(short[] buf, int samples_requested) public int OutputSamples(short[] buf, int samples_requested)
{ {
int ctr = 0; int ctr = 0;
int done = 0; int done = 0;
@ -318,7 +318,7 @@ namespace BizHawk.Emulation.Common
return new ssamp((short)lrv, (short)rrv); return new ssamp((short)lrv, (short)rrv);
} }
public void clear() public void Clear()
{ {
sampleQueue.Clear(); sampleQueue.Clear();
} }
@ -357,7 +357,7 @@ namespace BizHawk.Emulation.Common
return value; return value;
} }
public void enqueue_samples(short[] buf, int samples_provided) public void EnqueueSamples(short[] buf, int samples_provided)
{ {
int cursor = 0; int cursor = 0;
for (int i = 0; i < samples_provided; i++) for (int i = 0; i < samples_provided; i++)
@ -367,12 +367,12 @@ namespace BizHawk.Emulation.Common
} }
} }
public void enqueue_sample(short left, short right) public void EnqueueSample(short left, short right)
{ {
sampleQueue.Add(new ssamp(left, right)); sampleQueue.Add(new ssamp(left, right));
} }
public int output_samples(short[] buf, int samples_requested) public int OutputSamples(short[] buf, int samples_requested)
{ {
Console.WriteLine("{0} {1}", samples_requested, sampleQueue.Count); //add this line Console.WriteLine("{0} {1}", samples_requested, sampleQueue.Count); //add this line
@ -588,9 +588,7 @@ namespace BizHawk.Emulation.Common
// zero 08-nov-2010: did i do this right? // zero 08-nov-2010: did i do this right?
return audiosize; return audiosize;
} }
} // end normal speed } // end normal speed
} // end if there is any work to do } // end if there is any work to do
else else
{ {
@ -618,19 +616,20 @@ namespace BizHawk.Emulation.Common
// If it underflows beyond that threshhold, it will give up and output silence. // 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 // Since it has done this, it will go ahead and generate some excess silence in order
// to restock its excess buffer. // to restock its excess buffer.
private struct Sample private struct Sample
{ {
public short left, right; public readonly short Left;
public Sample(short l, short r) public readonly short Right;
public Sample(short left, short right)
{ {
left = l; Left = left;
right = r; Right = right;
} }
} }
private Queue<Sample> buffer; private readonly Queue<Sample> buffer;
private Sample[] resampleBuffer; private readonly Sample[] resampleBuffer;
private const int SamplesInOneFrame = 735; private const int SamplesInOneFrame = 735;
private const int MaxExcessSamples = 2048; private const int MaxExcessSamples = 2048;
@ -647,18 +646,18 @@ namespace BizHawk.Emulation.Common
} }
} }
public void enqueue_samples(short[] buf, int samples_provided) public void EnqueueSamples(short[] buf, int samples_provided)
{ {
int ctr = 0; int ctr = 0;
for (int i = 0; i < samples_provided; i++) for (int i = 0; i < samples_provided; i++)
{ {
short left = buf[ctr++]; short left = buf[ctr++];
short right = buf[ctr++]; short right = buf[ctr++];
enqueue_sample(left, right); EnqueueSample(left, right);
} }
} }
public void enqueue_sample(short left, short right) public void EnqueueSample(short left, short right)
{ {
if (buffer.Count >= MaxExcessSamples - 1) if (buffer.Count >= MaxExcessSamples - 1)
{ {
@ -669,12 +668,12 @@ namespace BizHawk.Emulation.Common
buffer.Enqueue(new Sample(left, right)); buffer.Enqueue(new Sample(left, right));
} }
public void clear() public void Clear()
{ {
buffer.Clear(); buffer.Clear();
} }
public int output_samples(short[] buf, int samples_requested) public int OutputSamples(short[] buf, int samples_requested)
{ {
if (samples_requested > buffer.Count) if (samples_requested > buffer.Count)
{ {
@ -691,8 +690,8 @@ namespace BizHawk.Emulation.Common
for (int i = 0; i < samples_requested; i++) for (int i = 0; i < samples_requested; i++)
{ {
Sample sample = resampleBuffer[i * samples_available / samples_requested]; Sample sample = resampleBuffer[i * samples_available / samples_requested];
buf[index++] += sample.left; buf[index++] += sample.Left;
buf[index++] += sample.right; buf[index++] += sample.Right;
} }
} }
else else
@ -709,8 +708,8 @@ namespace BizHawk.Emulation.Common
for (int i = 0; i < samples_requested && buffer.Count > 0; i++) for (int i = 0; i < samples_requested && buffer.Count > 0; i++)
{ {
Sample sample = buffer.Dequeue(); Sample sample = buffer.Dequeue();
buf[index++] += sample.left; buf[index++] += sample.Left;
buf[index++] += sample.right; buf[index++] += sample.Right;
} }
} }

View File

@ -282,7 +282,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
private void AdpcmEmitSample() private void AdpcmEmitSample()
{ {
if (AdpcmIsPlaying == false) if (AdpcmIsPlaying == false)
SoundProvider.Buffer.enqueue_sample(0, 0); SoundProvider.Buffer.EnqueueSample(0, 0);
else else
{ {
if (nextSampleTimer <= 0) if (nextSampleTimer <= 0)
@ -302,7 +302,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
} }
short adjustedSample = (short)((playingSample - 2048) * MaxVolume / 2048); short adjustedSample = (short)((playingSample - 2048) * MaxVolume / 2048);
SoundProvider.Buffer.enqueue_sample(adjustedSample, adjustedSample); SoundProvider.Buffer.EnqueueSample(adjustedSample, adjustedSample);
} }
} }

View File

@ -99,7 +99,7 @@ namespace BizHawk.Emulation.Cores.Components
{ {
Array.Clear(pullBuffer, 0, 1470); Array.Clear(pullBuffer, 0, 1470);
source.GetSamples(pullBuffer); source.GetSamples(pullBuffer);
Buffer.enqueue_samples(pullBuffer, 735); Buffer.EnqueueSamples(pullBuffer, 735);
} }
public bool CanProvideAsync public bool CanProvideAsync
@ -127,12 +127,12 @@ namespace BizHawk.Emulation.Cores.Components
public void GetSamplesAsync(short[] samples) public void GetSamplesAsync(short[] samples)
{ {
Buffer.output_samples(samples, samples.Length / 2); Buffer.OutputSamples(samples, samples.Length / 2);
} }
public void DiscardSamples() public void DiscardSamples()
{ {
Buffer.clear(); Buffer.Clear();
} }
} }
} }