installTap(onBus:bufferSize:format:block:)
Installs an audio tap on a bus you specify to record, monitor, and observe the output of the node.
Declaration
func installTap(onBus bus: AVAudioNodeBus, bufferSize: AVAudioFrameCount, format: AVAudioFormat?, block tapBlock: @escaping AVAudioNodeTapBlock)Parameters
- bus:
The output bus to attach the tap to.
- bufferSize:
The size of the incoming buffers. The implementation may choose another size.
- format:
If non-
nil, the framework applies this format to the output bus you specify. An error occurs when attaching to an output bus that’s already in a connected state. The tap and connection formats (if non-nil) on the bus need to be identical. Otherwise, the latter operation overrides the previous format.For
AVAudioOutputNode, you must specify the tap format asnil. - tapBlock:
A block the framework calls with audio buffers.
Discussion
You can install and remove taps while the engine is in a running state. You can install only one tap on any bus.
AVAudioEngine *engine = [[AVAudioEngine alloc] init];
AVAudioInputNode *input = [engine inputNode];
AVAudioFormat *format = [input outputFormatForBus: 0];
[input installTapOnBus: 0 bufferSize: 8192 format: format block: ^(AVAudioPCMBuffer *buf, AVAudioTime *when) {
// __'__buf' contains captured audio from the node at time 'when'
}];
....
// start engine