2 qq 32013343 qq_32013343 于 2016.03.11 17:01 提问

iOS 关于audio数据的提取 12C

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

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!