### Create and Configure AVAudioEngine for Audio File Playback (Swift) Source: https://developer.apple.com/documentation/avfaudio/avaudioengine?language=objc/index_language=objc This snippet demonstrates how to create an AVAudioEngine, attach an AVAudioPlayerNode, connect it to the engine's output, and schedule an audio file for playback. It also includes starting the engine and handling playback completion. ```swift let audioFile = /* An AVAudioFile instance that points to file that's open for reading. */ let audioEngine = AVAudioEngine() let playerNode = AVAudioPlayerNode() // Attach the player node to the audio engine. audioEngine.attach(playerNode) // Connect the player node to the output node. audioEngine.connect(playerNode, to: audioEngine.outputNode, format: audioFile.processingFormat) playerNode.scheduleFile(audioFile, at: nil, completionCallbackType: .dataPlayedBack) { _ in /* Handle any work that's necessary after playback. */ } do { try audioEngine.start() playerNode.play() } catch { /* Handle the error. */ } // When you’re done, stop the player and the engine. playerNode.stop() audioEngine.stop() ``` -------------------------------- ### Creating an Engine for Audio File Playback Source: https://developer.apple.com/documentation/avfaudio/avaudioengine?language=objc/index_language=objc This section demonstrates how to create an AVAudioEngine for playing an audio file, including attaching a player node, connecting it to the output, scheduling the file, and starting the engine. ```APIDOC ## Create an Engine for Audio File Playback To play an audio file, you create an `AVAudioFile` with a file that’s open for reading. Create an audio engine object and an `AVAudioPlayerNode` instance, and then attach the player node to the engine. Next, connect the player node to the audio engine’s output node. The engine performs audio output through an output node, which is a singleton that the engine creates the first time you access it. ```swift let audioFile = /* An AVAudioFile instance that points to file that's open for reading. */ let audioEngine = AVAudioEngine() let playerNode = AVAudioPlayerNode() // Attach the player node to the audio engine. audioEngine.attach(playerNode) // Connect the player node to the output node. audioEngine.connect(playerNode, to: audioEngine.outputNode, format: audioFile.processingFormat) ``` Then schedule the audio file for full playback. The callback notifies your app when playback completes. ```swift playerNode.scheduleFile(audioFile, at: nil, completionCallbackType: .dataPlayedBack) { _ in /* Handle any work that's necessary after playback. */ } ``` Before you play the audio, start the engine. ```swift do { try audioEngine.start() playerNode.play() } catch { /* Handle the error. */ } ``` When you’re done, stop the player and the engine. ```swift playerNode.stop() audioEngine.stop() ``` ``` -------------------------------- ### AVAudioEngine Methods and Properties Source: https://developer.apple.com/documentation/avfaudio/avaudioengine?language=objc/index_language=objc This section details key methods and properties for managing audio nodes and connections within an AVAudioEngine. ```APIDOC ## Creating an Audio Engine `- init` Creates an audio engine instance for rendering in real time. ## Attaching and Detaching Audio Nodes `- attachNode:` Attaches an audio node to the audio engine. `- detachNode:` Detaches an audio node from the audio engine. `attachedNodes` A read-only set that contains the nodes you attach to the audio engine. ## Getting the Input, Output, and Main Mixer Nodes `inputNode` The audio engine’s singleton input audio node. `outputNode` The audio engine’s singleton output audio node. `mainMixerNode` The audio engine’s optional singleton main mixer node. ## Connecting and Disconnecting Audio Nodes `- connect:to:format:` Establishes a connection between two nodes. `- connect:to:fromBus:toBus:format:` Establishes a connection between two nodes, specifying the input and output busses. `- disconnectNodeInput:` Removes all input connections of the node. `- disconnectNodeInput:bus:` Removes the input connection of a node on the specified bus. `- disconnectNodeOutput:` Removes all output connections of a node. `- disconnectNodeOutput:bus:` Removes the output connection of a node on the specified bus. ## Managing MIDI Nodes `- connectMIDI:to:format:eventListBlock:` Establishes a MIDI connection between two nodes. `- connectMIDI:toNodes:format:eventListBlock:` Establishes a MIDI connection between a source node and multiple destination nodes. `- disconnectMIDI:from:` Removes a MIDI connection between two nodes. `- disconnectMIDI:fromNodes:` Removes a MIDI connection between one source node and multiple destination nodes. `- disconnectMIDIInput:` Disconnects all input MIDI connections from a node. `- disconnectMIDIOutput:` Disconnects all output MIDI connections from a node. `- connectMIDI:to:format:block:` Establishes a MIDI-only connection between two nodes. Deprecated `- connectMIDI:toNodes:format:block:` Establishes a MIDI-only connection between a source node and multiple destination nodes. Deprecated ``` -------------------------------- ### AVAudioEngine Overview Source: https://developer.apple.com/documentation/avfaudio/avaudioengine?language=objc/index_language=objc AVAudioEngine manages a graph of AVAudioNode instances for audio processing. It can render audio in real-time or manual mode. ```APIDOC ## AVAudioEngine An audio engine object contains a group of `AVAudioNode` instances that you attach to form an audio processing chain. You can connect, disconnect, and remove audio nodes during runtime with minor limitations. By default, Audio Engine renders to a connected audio device in real time. You can configure the engine to operate in manual rendering mode when you need to render at, or faster than, real time. ``` -------------------------------- ### AVAudioEngine Objective-C Interface Source: https://developer.apple.com/documentation/avfaudio/avaudioengine?language=objc/index_language=objc This is the Objective-C interface declaration for the AVAudioEngine class, outlining its basic structure and inheritance. ```objectivec @interface AVAudioEngine : NSObject ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.