我正在尝试使用声音从麦克风中确定每分钟节拍数(BPM),我想我已经找出确定BPM的部分,但在获取RAW数据时遇到一些麻烦。
该示例基于Apples SpeakHere应用程序 - 在我正在使用的AudioQueue回调函数上:
SInt16 *buffer = (SInt16*)inBuffer->mAudioData;
for (int i = 0; i < (inBuffer->mAudioDataByteSize)/sizeof(SInt16); i++)
{
printf("before modification %d\n", (int)*buffer);
buffer++;
}
但是我得到了一些有趣的价值 - 任何人都可以指出我在哪里出错的正确方向,让我知道我应该回归的范围。
音频格式设置:
mRecordFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
mRecordFormat.mBitsPerChannel = 16;
mRecordFormat.mBytesPerPacket = mRecordFormat.mBytesPerFrame = (mRecordFormat.mBitsPerChannel / 8) * mRecordFormat.mChannelsPerFrame;
mRecordFormat.mFramesPerPacket = 1;
干杯,
答案 0 :(得分:1)
解决了......
音频格式设置:
mRecordFormat.mFormatID = kAudioFormatLinearPCM;
mRecordFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
mRecordFormat.mBitsPerChannel = 16;
mRecordFormat.mBytesPerPacket = mRecordFormat.mBytesPerFrame = (mRecordFormat.mBitsPerChannel / 8) * mRecordFormat.mChannelsPerFrame;
mRecordFormat.mFramesPerPacket = 1;
mRecordFormat.mBytesPerPacket = 2 * mRecordFormat.mChannelsPerFrame;
mRecordFormat.mBytesPerFrame = 2 * mRecordFormat.mChannelsPerFrame;
mRecordFormat.mFramesPerPacket = 1;
mRecordFormat.mReserved = 0;
现在要迭代它:
int sampleCount = inBuffer->mAudioDataBytesCapacity / sizeof (SInt16);
SInt16 *p = (SInt16*)inBuffer->mAudioData;
for (int i = 0; i < sampleCount; i++) {
SInt16 val = p[i];
}
答案 1 :(得分:0)
您采用何种格式(AudioStreamBasicDescription:endianess,每通道位数,每帧通道数等)配置音频队列?配置可能与SInt16的C数组非常不同。