我需要读取音频样本值。我正在使用(来自苹果SpeakHere示例的) audioQueue回调:
UInt32 samplesCount = inCompleteAQBuffer->mAudioDataBytesCapacity / 2;
UInt16 *samples = (UInt16 *)inCompleteAQBuffer->mAudioData;
for (int i=0; i < samplesCount; i++)
{
printf("%i\n", samples[i]);
}返回了值,但当我将它们与audacity中的图形进行比较时,它们似乎是错误的:

Audacity值从1 (65535)到-1 (0)。因此,逻辑上第一个样本值应该是32767,第二个样本值应该是~50000…
但我收到了其他结果:
value - position
65535 - 0
29501 - 1
26086 - 2
63656 - 3
28477 - 4
65407 - 5
36802 - 6
36546 - 7
18244 - 8
17220 - 9
player settings:
(Float64) mSampleRate = 44100
(UInt32) mBytesPerPacket = 2
(UInt32) mFramesPerPacket = 1
(UInt32) mBytesPerFrame = 2
(UInt32) mChannelsPerFrame = 1
(UInt32) mBitsPerChannel = 16
(UInt32) mReserved = 0问题-为什么从mAudioData返回的样本值是错误的?
发布于 2012-03-30 00:22:36
该文件的字节顺序与您的系统不同。您必须交换每个样本的字节顺序。此外,样本是带符号的16位整数(SInt16),而不是UInt16。因此,最大值为32767 (而不是65535),最小值为-32767。
查看ExtendedAudioFile.h和AudioConverter.h中的转换帮助。
https://stackoverflow.com/questions/9926944
复制相似问题