Xinghan Chen 2016-03-11 09:01 采纳率: 100%
浏览 1018
已结题

iOS 关于audio数据的提取

static void AQInputCallback (void *inUserData,

                         AudioQueueRef inAudioQueue,

                         AudioQueueBufferRef inBuffer,

                         const AudioTimeStamp *inStartTime,UInt32 inNumPackets,

                         const AudioStreamPacketDescription * inPacketDesc)

{

getAudioDataText * engine = (__bridge getAudioDataText *) inUserData;

 //[engine processAudioBuffer:inBuffer withQueue:inAudioQueue];

if (inNumPackets > 0)

{
   NSDate *datenow = [NSDate date];
    [engine processAudioBuffer:inBuffer withQueue:inAudioQueue];
     NSString *timeSp = [NSString stringWithFormat:@"%f", (CGFloat)[datenow timeIntervalSince1970]];
    NSLog(@"---------------%@", timeSp);
}

if (engine.aqc.run)

{

    AudioQueueEnqueueBuffer(engine.aqc.queue, inBuffer, 0, NULL);

}

}

  • (id) initWithSampleRate:(NSInteger)sampleRate atChannels:(UInt32)channels

{

self = [super init];

if (self)

{

    aqc.mDataFormat.mSampleRate = sampleRate;

    aqc.mDataFormat.mFormatID = kAudioFormatLinearPCM;

    aqc.mDataFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;

    aqc.mDataFormat.mFramesPerPacket = 1;

    aqc.mDataFormat.mChannelsPerFrame = channels;

    aqc.mDataFormat.mBitsPerChannel = kBitsPerChannels;

    aqc.mDataFormat.mBytesPerPacket = kBytesPerFrame;

    aqc.mDataFormat.mBytesPerFrame = kBytesPerFrame;

    aqc.frameSize = kFrameSize;

    //创建一个录音音频队列对象

    AudioQueueNewInput(&aqc.mDataFormat, AQInputCallback, (__bridge void*)(self), NULL, kCFRunLoopCommonModes, 0, &aqc.queue);

    for (int i=0;i<kNumberBuffers;i++)

    {

        //请求音频队列对象来分配一个音频队列缓存。

        AudioQueueAllocateBuffer(aqc.queue, (UInt32)aqc.frameSize, &aqc.mBuffers[i]);

        //给录音或者回放音频队列的缓存中添加一个缓存数据

        AudioQueueEnqueueBuffer(aqc.queue, aqc.mBuffers[i], 0, NULL);

    }

    aqc.recPtr = 0;

    aqc.run = 1;

    int status = AudioQueueStart(aqc.queue, NULL);

    NSLog(@"AudioQueueStart = %d", status);

}

return self;

}
为什设置的采样率 是44100 但是回调函数里的打印数据的频率只有500次/s?哪位大神给个解决方法 我qq 1353482080

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 聚类分析或者python进行数据分析
    • ¥15 逻辑谓词和消解原理的运用
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号