【问题标题】:iPhone AudioQueue - Reading incoming audio data to determine BPMiPhone AudioQueue - 读取传入的音频数据以确定 BPM
【发布时间】:2011-05-05 17:29:51
【问题描述】:

我正在尝试使用声能确定麦克风的每分钟节拍数 (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;

干杯,

【问题讨论】:

  • 它有什么有趣的地方?尝试将您的文本输出导入 excel,按空格分割并绘制值。你有波形吗?

标签: iphone core-audio audioqueue audio-processing


【解决方案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];
}

【讨论】:

    【解决方案2】:

    您以什么格式(AudioStreamBasicDescription:字节序、每通道位数、每帧通道等)配置了音频队列?配置可能与 SInt16 的 C 数组有很大不同。

    【讨论】:

    • 感谢您的回复;设置:mRecordFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked; mRecordFormat.mBitsPerChannel = 16; mRecordFormat.mBytesPerPacket = mRecordFormat.mBytesPerFrame = (mRecordFormat.mBitsPerChannel / 8) * mRecordFormat.mChannelsPerFrame; mRecordFormat.mFramesPerPacket = 1;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多