Hello,

In an iOS app I am trying to capture audio from my graph in AVAudioEngine as it 
is sent to the output route. The purpose is a record-sum function.
There is a method AVAudioNode.installTap() which works great — if I invoke it 
on engine.mainMixerNode.
The tap is not called when I install it on engine.outputNode.
Has anyone successfully managed to install a tap on engine.outputNode?

I’d like to avoid the overhead of a mixer node just so I can install a tap on 
it when the output node should be able to handle it.

Note that the API documentation explicitly mentions that for an 
AVAudioOutputNode the format must be nil. This implies that AVAudioOutputNode 
is supported.

Here is some code from my test project. Each time the tap is called a text 
message should be seen in the console. It repeatedly appears when I use 
engine.mainMixerNode, but it never appears with engine.outputNode. Assume 
AVAudioEngine has already been started. An instance of AVAudioUnitSampler is 
connected to engine.outputNode.

func startRecording() -> Bool {
        guard let url = 
ViewController.documentsFolderURL()?.appendingPathComponent("Audio.aiff") else 
{ return false }

        do {
                // settings = Output file format
                // commonFormat = what comes from PCM buffer

                // Write 16-bit AIFF file
                let settings: [String: Any] = [
                        AVLinearPCMBitDepthKey: 16,
                        AVLinearPCMIsFloatKey: false,
                        AVLinearPCMIsNonInterleaved: false,
                        AVFormatIDKey: kAudioFormatLinearPCM,
                        AVNumberOfChannelsKey: stereoFormat.channelCount,
                        AVSampleRateKey: stereoFormat.sampleRate
                ]

                currentAudioFile = try AVAudioFile(forWriting: url, settings: 
settings, commonFormat: .pcmFormatFloat32, interleaved: false)

                engine.outputNode.installTap(onBus: 0, bufferSize: 8192, 
format: nil) { (pcmBuffer, when) in
                        // Use serial queue to prevent overlaps
                        self.audioFileQueue.addOperation {
                                guard let file = self.currentAudioFile else { 
return }
                                do {
                                        print("Writing 
length=\(pcmBuffer.frameLength), pos=\(file.framePosition), 
when=\(when.sampleTime)")
                                        try file.write(from: pcmBuffer)
                                } catch {
                                        print("Could not write to audio file")
                                }
                        }
                }

                print("Started new audio file")

        } catch {
                print("Could not create audio file")
        }

        return true
}

Thanks for any ideas.
Sven

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (Coreaudio-api@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to