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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
    • ¥15 再不同版本的系统上,TCP传输速度不一致
    • ¥15 高德地图点聚合中Marker的位置无法实时更新
    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程