我想每秒调用 20 次 installTapOnBus:bufferSize:format:block: [英] I want to call 20 times per second the installTapOnBus:bufferSize:format:block:

查看:36
本文介绍了我想每秒调用 20 次 installTapOnBus:bufferSize:format:block:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实时显示麦克风输入的波形.我已经使用 installTapOnBus:bufferSize:format:block: 实现了,这个函数在一秒内被调用了 3 次.我想将此函数设置为每秒调用 20 次.在哪里可以设置?

I want to waveform display in real-time input from the microphone. I have been implemented using the installTapOnBus:bufferSize:format:block:, This function is called three times in one second. I want to set this function to be called 20 times per second. Where can I set?

AVAudioSession *audioSession = [AVAudioSession sharedInstance];

NSError* error = nil;
if (audioSession.isInputAvailable) [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
if(error){
    return;
}

[audioSession setActive:YES error:&error];
if(error){
    retur;
}

self.engine = [[[AVAudioEngine alloc] init] autorelease];

AVAudioMixerNode* mixer = [self.engine mainMixerNode];
AVAudioInputNode* input = [self.engine inputNode];
[self.engine connect:input to:mixer format:[input inputFormatForBus:0]];

// tap ... 1 call in 16537Frames
// It does not change even if you change the bufferSize
[input installTapOnBus:0 bufferSize:4096 format:[input inputFormatForBus:0] block:^(AVAudioPCMBuffer* buffer, AVAudioTime* when) {

    for (UInt32 i = 0; i < buffer.audioBufferList->mNumberBuffers; i++) {
        Float32 *data = buffer.audioBufferList->mBuffers[i].mData;
        UInt32 frames = buffer.audioBufferList->mBuffers[i].mDataByteSize / sizeof(Float32);

        // create waveform
        ...
    }
}];

[self.engine startAndReturnError:&error];
if (error) {
    return;
}

推荐答案

他们说,Apple 支持回复:(2014 年 9 月)

they say, Apple Support replied no: (on sep 2014)

是的,目前我们内部有一个固定的抽头缓冲区大小(0.375s),并且客户端为点击指定的缓冲区大小未生效.

Yes, currently internally we have a fixed tap buffer size (0.375s), and the client specified buffer size for the tap is not taking effect.

但有人调整缓冲区大小并获得 40 毫秒https://devforums.apple.com/thread/249510?tstart=0

but someone resizes buffer size and gets 40ms https://devforums.apple.com/thread/249510?tstart=0

无法检查它,在 ObjC 中没有 :(

Can not check it, neen in ObjC :(

UPD 它有效!单行:

    [input installTapOnBus:0 bufferSize:1024 format:[mixer outputFormatForBus:0] block:^(AVAudioPCMBuffer *buffer, AVAudioTime *when) {
    buffer.frameLength = 1024; //here

这篇关于我想每秒调用 20 次 installTapOnBus:bufferSize:format:block:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆