我想从麦克风实时输入波形显示.
我已经使用installTapOnBus:bufferSize:format:block:来实现,这个函数在一秒钟内被调用三次.
我想将此函数设置为每秒调用20次.
我在哪里可以设置?
我已经使用installTapOnBus:bufferSize:format:block:来实现,这个函数在一秒钟内被调用三次.
我想将此函数设置为每秒调用20次.
我在哪里可以设置?
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月)
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
在ObjC中无法检查它:(
UPD它有效!只是单行:
[input installTapOnBus:0 bufferSize:1024 format:[mixer outputFormatForBus:0] block:^(AVAudioPCMBuffer *buffer,AVAudioTime *when) { buffer.frameLength = 1024; //here