我正在编程一个C#模拟器,并决定使用CScore输出PCM。 当样本大小(对于每个通道)是一个字节时,声音输出正确,但是当我将样本大小增加到16位时,声音非常嘈杂。CScore输出PCM大于一个字节
一个相关的问题,这一问题是如何将这些2个字节解释(是他们签下高位在前?)
这大约是我在做什么:
首先,我产生的样品一样
public void GenerateSamples(int sampleCount)
{
while(sampleCount > 0)
{
--sampleCount;
for(int c = 0; c < _numChannels; ++c)
{
_buffer[_sampleIndex++] = _outputValue;
}
// The amount of ticks in a sample
_tickCounter -= APU.MinimumTickThreshold;
if(_tickCounter < 0)
{
_tickCounter = _tickThreshold;
_up = !_up;
// Replicating signed behaviour
_outputValue = (short)(_up ? 32767 : -32768);
}
}
}
这将生成一个简单的方波,频率由_tickThreshold决定。如果_buffer是一个字节数组,声音是正确的。 我想输出它与短裤,因为它可以使我使用签名样本,只需添加多个通道,以混合它们。
这就是我输出声音的方式。
for(int i = 0; i < sampleCount; ++i)
{
for(int c = 0; c < _numChannels; ++c)
{
short sample = _channel.Buffer[_channelSampleIndex++];
// Outputting the samples the other way around doesn't output
// sound for me
_buffer[_sampleIndex++] = (byte)sample;
_buffer[_sampleIndex++] = (byte)(sample >> 8);
}
}
我使用的是WAVEFORMAT像这样确定的:
_waveFormat = new WaveFormat(_apu.SampleRate, // 44000
_apu.SampleSize * 8, // 16
_apu.NumChannels); // 2
我敢肯定有一些明显的我失踪,但我一直在调试这一段时间并且似乎没有明确指出问题所在。
谢谢
感谢分享。你可以将自己的答案标记为正确答案;-) – GabrielOshiro