2

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.mBitsPerChannel = 16;
mRecordFormat.mBytesPerPacket = mRecordFormat.mBytesPerFrame = (mRecordFormat.mBitsPerChannel / 8) * mRecordFormat.mChannelsPerFrame;
mRecordFormat.mFramesPerPacket = 1;

Cheers,

asheeshr
  • 4,088
  • 6
  • 31
  • 50
Josh
  • 83
  • 6
  • what's interesting about it? Try importing your text output into excel, splitting on spaces and plotting the values. Do you get a waveform? – AShelly May 05 '11 at 20:00

2 Answers2

1

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];
}
Josh
  • 83
  • 6
0

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.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • Thanks for your response; Setup: mRecordFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked; mRecordFormat.mBitsPerChannel = 16; mRecordFormat.mBytesPerPacket = mRecordFormat.mBytesPerFrame = (mRecordFormat.mBitsPerChannel / 8) * mRecordFormat.mChannelsPerFrame; mRecordFormat.mFramesPerPacket = 1; – Josh May 05 '11 at 19:46