• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Installing a tap on AVAudioOutputNode
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Installing a tap on AVAudioOutputNode


  • Subject: Installing a tap on AVAudioOutputNode
  • From: Sven Thoennissen <email@hidden>
  • Date: Mon, 30 Apr 2018 15:54:31 +0200

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      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Audio Output Sample Rate Discrepancy
  • Previous by thread: Audio Output Sample Rate Discrepancy
  • Index(es):
    • Date
    • Thread