开发者

iPhone AudioQueue - Reading incoming audio data to determine BPM

开发者 https://www.devze.com 2023-03-03 19:15 出处:网络
I\'m trying to determine Beats Per Minute (BPM) from the microphone using sound energy, I think I\'ve figured out the part determining BPM but having a little trouble obtaining the RAW data.

I'm trying to determine Beats Per Minute (BPM) from the microphone using sound energy, I think I've figured out the part determining BPM but having a little trouble obtaining the RAW data.

The example is based on Apples SpeakHere app - on the AudioQueue callback function I'm using:

SInt16 *buffer = (SInt16*)inBuffer->mAudioData;   
for (int i = 0; i < (inBuffer->mAudioDataByteSize)/sizeof(SInt16); i++)
{      
  printf("before modification %d\n", (int)*buffer); 
  buffer++;
}  

But I'm getting some interesting values - any chance someone can point me in the right direction of where I'm going wrong and let me know what the range I should be getting back.

Audio Format Setup:

mRecordFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
mRecordFormat.mB开发者_StackOverflowitsPerChannel = 16;
mRecordFormat.mBytesPerPacket = mRecordFormat.mBytesPerFrame = (mRecordFormat.mBitsPerChannel / 8) * mRecordFormat.mChannelsPerFrame;
mRecordFormat.mFramesPerPacket = 1;

Cheers,


Solved...

Audio Format Setup:

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;

And now to iterate through it:

int sampleCount = inBuffer->mAudioDataBytesCapacity / sizeof (SInt16);
SInt16 *p = (SInt16*)inBuffer->mAudioData;
for (int i = 0; i < sampleCount; i++) {    
 SInt16 val = p[i];
}


In what format (AudioStreamBasicDescription: endianess, bits per channel, channel per frame, etc.) did you configure your Audio Queue? It's possible for the configuration to be very different from a C array of SInt16.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号