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#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算