Optimize sound output buffer handling
turns out a Queue isn't the optimal data structure when you're queueing millions of elements
This commit is contained in:
parent
f3876da840
commit
0ac81016b1
|
@ -31,7 +31,7 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
private readonly Func<double> _getCoreVsyncRateCallback;
|
private readonly Func<double> _getCoreVsyncRateCallback;
|
||||||
|
|
||||||
private readonly Queue<short> _buffer = new Queue<short>();
|
private readonly List<short> _buffer = [ ];
|
||||||
private readonly bool _standaloneMode;
|
private readonly bool _standaloneMode;
|
||||||
private readonly int _targetExtraSamples;
|
private readonly int _targetExtraSamples;
|
||||||
private int _maxSamplesDeficit;
|
private int _maxSamplesDeficit;
|
||||||
|
@ -101,7 +101,7 @@ namespace BizHawk.Client.Common
|
||||||
_buffer.Clear();
|
_buffer.Clear();
|
||||||
for (int i = 0; i < _targetExtraSamples * ChannelCount; i++)
|
for (int i = 0; i < _targetExtraSamples * ChannelCount; i++)
|
||||||
{
|
{
|
||||||
_buffer.Enqueue(0);
|
_buffer.Add(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ namespace BizHawk.Client.Common
|
||||||
if (LogDebug) Console.WriteLine($"Generating {generateSampleCount} samples");
|
if (LogDebug) Console.WriteLine($"Generating {generateSampleCount} samples");
|
||||||
for (int i = 0; i < generateSampleCount * ChannelCount; i++)
|
for (int i = 0; i < generateSampleCount * ChannelCount; i++)
|
||||||
{
|
{
|
||||||
_buffer.Enqueue(0);
|
_buffer.Add(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
hardCorrected = true;
|
hardCorrected = true;
|
||||||
|
@ -174,10 +174,7 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
int discardSampleCount = extraSampleCount;
|
int discardSampleCount = extraSampleCount;
|
||||||
if (LogDebug) Console.WriteLine($"Discarding {discardSampleCount} samples");
|
if (LogDebug) Console.WriteLine($"Discarding {discardSampleCount} samples");
|
||||||
for (int i = 0; i < discardSampleCount * ChannelCount; i++)
|
_buffer.RemoveRange(0, discardSampleCount * ChannelCount);
|
||||||
{
|
|
||||||
_buffer.Dequeue();
|
|
||||||
}
|
|
||||||
|
|
||||||
hardCorrected = true;
|
hardCorrected = true;
|
||||||
}
|
}
|
||||||
|
@ -286,18 +283,13 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
private void GetSamplesFromBuffer(short[] samples, int count)
|
private void GetSamplesFromBuffer(short[] samples, int count)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < count * ChannelCount; i++)
|
_buffer.CopyTo(0, samples, 0, count * ChannelCount);
|
||||||
{
|
_buffer.RemoveRange(0, count * ChannelCount);
|
||||||
samples[i] = _buffer.Dequeue();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddSamplesToBuffer(short[] samples, int count)
|
private void AddSamplesToBuffer(short[] samples, int count)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < count * ChannelCount; i++)
|
_buffer.AddRange(new ArraySegment<short>(samples, 0, count * ChannelCount));
|
||||||
{
|
|
||||||
_buffer.Enqueue(samples[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private short[] GetOutputBuffer(int count)
|
private short[] GetOutputBuffer(int count)
|
||||||
|
|
Loading…
Reference in New Issue