﻿<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFAudio",
  "identifier" : "/documentation/AVFAudio/AVAudioEngine",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AVFAudio"
    ],
    "preciseIdentifier" : "c:objc(cs)AVAudioEngine"
  },
  "title" : "AVAudioEngine"
}
-->

# AVAudioEngine

An object that manages a graph of audio nodes, controls playback, and configures real-time rendering constraints.

```
class AVAudioEngine
```

## Overview

An audio engine object contains a group of [`AVAudioNode`](/documentation/AVFAudio/AVAudioNode) instances that you attach to form an audio processing chain.

![A flow diagram that shows an app using an audio engine in a real time context. The audio flows from the source file in the app to a player node, a mixer node, and an output node before reaching the device’s speaker or connected headphones.](images/com.apple.avfaudio/media-3901205@2x.png)

You can connect, disconnect, and remove audio nodes during runtime with minor limitations. Removing an audio node that has differing channel counts, or that’s a mixer, can break the graph. Reconnect audio nodes only when they’re upstream of a mixer.

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. In that mode, the engine disconnects from audio devices and your app drives the rendering.

### Create an engine for audio file playback

To play an audio file, you create an [`AVAudioFile`](/documentation/AVFAudio/AVAudioFile) with a file that’s open for reading. Create an audio engine object and an [`AVAudioPlayerNode`](/documentation/AVFAudio/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()
```

## Topics

### Creating an audio engine

[`init()`](/documentation/AVFAudio/AVAudioEngine/init())

Creates an audio engine instance for rendering in real time.

### Attaching and detaching audio nodes

[`func attach(AVAudioNode)`](/documentation/AVFAudio/AVAudioEngine/attach(_:))

Attaches an audio node to the audio engine.

[`func detach(AVAudioNode)`](/documentation/AVFAudio/AVAudioEngine/detach(_:))

Detaches an audio node from the audio engine.

[`var attachedNodes: Set<AVAudioNode>`](/documentation/AVFAudio/AVAudioEngine/attachedNodes)

A read-only set that contains the nodes you attach to the audio engine.

### Accessing the built-in nodes

[`var inputNode: AVAudioInputNode`](/documentation/AVFAudio/AVAudioEngine/inputNode)

The audio engine’s singleton input audio node.

[`var outputNode: AVAudioOutputNode`](/documentation/AVFAudio/AVAudioEngine/outputNode)

The audio engine’s singleton output audio node.

[`var mainMixerNode: AVAudioMixerNode`](/documentation/AVFAudio/AVAudioEngine/mainMixerNode)

The audio engine’s optional singleton main mixer node.

### Connecting and disconnecting audio nodes

[`func connectNode(AVAudioNode, to: AVAudioNode, format: AVAudioFormat?) throws`](/documentation/AVFAudio/AVAudioEngine/connectNode(_:to:format:))

[`func connectNode(AVAudioNode, to: AVAudioNode, fromBus: AVAudioNodeBus, toBus: AVAudioNodeBus, format: AVAudioFormat?) throws`](/documentation/AVFAudio/AVAudioEngine/connectNode(_:to:fromBus:toBus:format:))

[`func connectNode(AVAudioNode, to: [AVAudioConnectionPoint], fromBus: AVAudioNodeBus, format: AVAudioFormat?) throws`](/documentation/AVFAudio/AVAudioEngine/connectNode(_:to:fromBus:format:))

[`func connect(AVAudioNode, to: AVAudioNode, format: AVAudioFormat?)`](/documentation/AVFAudio/AVAudioEngine/connect(_:to:format:))

Establishes a connection between two nodes.

[`func connect(AVAudioNode, to: AVAudioNode, fromBus: AVAudioNodeBus, toBus: AVAudioNodeBus, format: AVAudioFormat?)`](/documentation/AVFAudio/AVAudioEngine/connect(_:to:fromBus:toBus:format:))

Establishes a connection between two nodes, specifying the input and output busses.

[`func disconnectNodeInput(AVAudioNode)`](/documentation/AVFAudio/AVAudioEngine/disconnectNodeInput(_:))

Removes all input connections of the node.

[`func disconnectNodeInput(AVAudioNode, bus: AVAudioNodeBus)`](/documentation/AVFAudio/AVAudioEngine/disconnectNodeInput(_:bus:))

Removes the input connection of a node on the specified bus.

[`func disconnectNodeOutput(AVAudioNode)`](/documentation/AVFAudio/AVAudioEngine/disconnectNodeOutput(_:))

Removes all output connections of a node.

[`func disconnectNodeOutput(AVAudioNode, bus: AVAudioNodeBus)`](/documentation/AVFAudio/AVAudioEngine/disconnectNodeOutput(_:bus:))

Removes the output connection of a node on the specified bus.

### Managing MIDI nodes

[`func connectMIDI(AVAudioNode, to: AVAudioNode, format: AVAudioFormat?, eventListProvider: AVMIDIEventListBlock?)`](/documentation/AVFAudio/AVAudioEngine/connectMIDI(_:to:format:eventListProvider:)-8tmk8)

[`func connectMIDI(AVAudioNode, to: [AVAudioNode], format: AVAudioFormat?, eventListProvider: AVMIDIEventListBlock?)`](/documentation/AVFAudio/AVAudioEngine/connectMIDI(_:to:format:eventListProvider:)-35k1c)

[`func connectMIDI(AVAudioNode, to: AVAudioNode, format: AVAudioFormat?, eventListBlock: AUMIDIEventListBlock?)`](/documentation/AVFAudio/AVAudioEngine/connectMIDI(_:to:format:eventListBlock:)-73cd1)

Establishes a MIDI connection between two nodes.

[`func connectMIDI(AVAudioNode, to: [AVAudioNode], format: AVAudioFormat?, eventListBlock: AUMIDIEventListBlock?)`](/documentation/AVFAudio/AVAudioEngine/connectMIDI(_:to:format:eventListBlock:)-7qtd5)

Establishes a MIDI connection between a source node and multiple destination nodes.

[`func disconnectMIDI(AVAudioNode, from: AVAudioNode)`](/documentation/AVFAudio/AVAudioEngine/disconnectMIDI(_:from:)-1kssy)

Removes a MIDI connection between two nodes.

[`func disconnectMIDI(AVAudioNode, from: [AVAudioNode])`](/documentation/AVFAudio/AVAudioEngine/disconnectMIDI(_:from:)-7oaab)

Removes a MIDI connection between one source node and multiple destination nodes.

[`func disconnectMIDIInput(AVAudioNode)`](/documentation/AVFAudio/AVAudioEngine/disconnectMIDIInput(_:))

Disconnects all input MIDI connections from a node.

[`func disconnectMIDIOutput(AVAudioNode)`](/documentation/AVFAudio/AVAudioEngine/disconnectMIDIOutput(_:))

Disconnects all output MIDI connections from a node.

[`func connectMIDI(AVAudioNode, to: AVAudioNode, format: AVAudioFormat?, block: AUMIDIOutputEventBlock?)`](/documentation/AVFAudio/AVAudioEngine/connectMIDI(_:to:format:block:)-3bc13)

Establishes a MIDI-only connection between two nodes.

[`func connectMIDI(AVAudioNode, to: [AVAudioNode], format: AVAudioFormat?, block: AUMIDIOutputEventBlock?)`](/documentation/AVFAudio/AVAudioEngine/connectMIDI(_:to:format:block:)-666bc)

Establishes a MIDI-only connection between a source node and multiple destination nodes.

### Playing audio

[`func prepare()`](/documentation/AVFAudio/AVAudioEngine/prepare())

Prepares the audio engine for starting.

[`func start() throws`](/documentation/AVFAudio/AVAudioEngine/start())

Starts the audio engine.

[`var isRunning: Bool`](/documentation/AVFAudio/AVAudioEngine/isRunning)

A Boolean value that indicates whether the audio engine is running.

[`func pause()`](/documentation/AVFAudio/AVAudioEngine/pause())

Pauses the audio engine.

[`func stop()`](/documentation/AVFAudio/AVAudioEngine/stop())

Stops the audio engine and releases any previously prepared resources.

[`func reset()`](/documentation/AVFAudio/AVAudioEngine/reset())

Resets all audio nodes in the audio engine.

[`func withMusicSequence<R, E>((borrowing MusicSequence?) throws(E) -> R) throws(E) -> R`](/documentation/AVFAudio/AVAudioEngine/withMusicSequence(_:))

Provides scoped access to the AVAudioEngine’s MusicSequence

[`@property (nonatomic, nullable) MusicSequence musicSequence;`](/documentation/AVFAudio/AVAudioEngine/musicSequence-3u74x)

The music sequence instance that you attach to the audio engine, if any.

[`var musicSequence: MusicSequence?`](/documentation/AVFAudio/AVAudioEngine/musicSequence-1z47z)

### Rendering audio manually

[`func enableManualRenderingMode(AVAudioEngineManualRenderingMode, format: AVAudioFormat, maximumFrameCount: AVAudioFrameCount) throws`](/documentation/AVFAudio/AVAudioEngine/enableManualRenderingMode(_:format:maximumFrameCount:))

Sets the engine to operate in manual rendering mode with the render format and maximum frame count you specify.

[`enum AVAudioEngineManualRenderingMode`](/documentation/AVFAudio/AVAudioEngineManualRenderingMode)

The two modes for manual rendering.

[`func disableManualRenderingMode()`](/documentation/AVFAudio/AVAudioEngine/disableManualRenderingMode())

Sets the engine to render to or from an audio device.

[`func renderOffline(AVAudioFrameCount, to: AVAudioPCMBuffer) throws -> AVAudioEngineManualRenderingStatus`](/documentation/AVFAudio/AVAudioEngine/renderOffline(_:to:))

Makes a render call to the engine operating in the offline manual rendering mode.

[`enum AVAudioEngineManualRenderingStatus`](/documentation/AVFAudio/AVAudioEngineManualRenderingStatus)

Status codes that return from the render call to the engine operating in manual rendering mode.

[`enum AVAudioEngineManualRenderingError`](/documentation/AVFAudio/AVAudioEngineManualRenderingError)

Constants that describe error codes that the framework returns from manual rendering mode methods.

### Getting manual rendering properties

[`typealias AVAudioEngineManualRenderingBlock`](/documentation/AVFAudio/AVAudioEngineManualRenderingBlock)

The type that represents a block that renders the engine when operating in manual rendering mode.

[`var manualRenderingBlock: AVAudioEngineManualRenderingBlock`](/documentation/AVFAudio/AVAudioEngine/manualRenderingBlock)

The block that renders the engine when operating in manual rendering mode.

[`var manualRenderingFormat: AVAudioFormat`](/documentation/AVFAudio/AVAudioEngine/manualRenderingFormat)

The render format of the engine in manual rendering mode.

[`var manualRenderingMaximumFrameCount: AVAudioFrameCount`](/documentation/AVFAudio/AVAudioEngine/manualRenderingMaximumFrameCount)

The maximum number of PCM sample frames the engine produces in any single render call in manual rendering mode.

[`var manualRenderingMode: AVAudioEngineManualRenderingMode`](/documentation/AVFAudio/AVAudioEngine/manualRenderingMode)

The manual rendering mode configured on the engine.

[`var manualRenderingSampleTime: AVAudioFramePosition`](/documentation/AVFAudio/AVAudioEngine/manualRenderingSampleTime)

An indication of where the engine is on its render timeline in manual rendering mode.

[`var isAutoShutdownEnabled: Bool`](/documentation/AVFAudio/AVAudioEngine/isAutoShutdownEnabled)

A Boolean value that indicates whether autoshutdown is in an enabled state.

[`var isInManualRenderingMode: Bool`](/documentation/AVFAudio/AVAudioEngine/isInManualRenderingMode)

A Boolean value that indicates whether the engine is operating in manual rendering mode.

### Using connection points

[`class AVAudioConnectionPoint`](/documentation/AVFAudio/AVAudioConnectionPoint)

A representation of either a source or destination connection point in the audio engine.

[`func connect(AVAudioNode, to: [AVAudioConnectionPoint], fromBus: AVAudioNodeBus, format: AVAudioFormat?)`](/documentation/AVFAudio/AVAudioEngine/connect(_:to:fromBus:format:))

Establishes a connection between a source node and multiple destination nodes.

[`func inputConnectionPoint(for: AVAudioNode, inputBus: AVAudioNodeBus) -> AVAudioConnectionPoint?`](/documentation/AVFAudio/AVAudioEngine/inputConnectionPoint(for:inputBus:))

Returns connection information about a node’s input bus.

[`func outputConnectionPoints(for: AVAudioNode, outputBus: AVAudioNodeBus) -> [AVAudioConnectionPoint]`](/documentation/AVFAudio/AVAudioEngine/outputConnectionPoints(for:outputBus:))

Returns connection information about a node’s output bus.

### Responding to configuration changes

[`extern NSString * const AVAudioEngineConfigurationChangeNotification;`](/documentation/AVFAudio/AVAudioEngineConfigurationChangeNotification)

A notification the framework posts when the audio engine configuration changes.

## Relationships

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`Hashable`](/documentation/Swift/Hashable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Sendable`](/documentation/Swift/Sendable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-poli