2011-05-05 71 views
2

我试图从麦克风使用声音能量来确定节拍每分钟(BPM),我想我已经想出了确定BPM的部分,但有点麻烦获得原始数据。iPhone AudioQueue - 读取传入的音频数据,以确定BPM

的例子是基于苹果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

什么是它有趣吗?尝试将你的文本输出导入到excel中,分割空间并绘制值。你有波形吗? – AShelly 2011-05-05 20:00:54

回答

0

以什么格式(AudioStreamBasicDescription:字节顺序,每信道比特,每帧通道等),并配置您的音频队列?配置可能与SInt16的C数组非常不同。

+0

感谢您的回复; 设置: mRecordFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked; mRecordFormat.mBitsPerChannel = 16; mRecordFormat.mBytesPerPacket = mRecordFormat.mBytesPerFrame =(mRecordFormat.mBitsPerChannel/8)* mRecordFormat.mChannelsPerFrame; mRecordFormat.mFramesPerPacket = 1; – Josh 2011-05-05 19:46:15

+0

大还是小? – hotpaw2 2011-05-05 20:59:58

+0

签名的16位小尾数 – Josh 2011-05-05 21:52:23

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]; 
} 
相关问题