<!--
{
  "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

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

Attaches an audio node to the audio engine.

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

Detaches an audio node from the audio engine.

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

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

### Getting the Input, Output, and Main Mixer Nodes

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

The audio engine’s singleton input audio node.

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

The audio engine’s singleton output audio node.

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

The audio engine’s optional singleton main mixer node.

### Connecting and Disconnecting Audio Nodes

[`connectNode(_:to:format:)`](/documentation/AVFAudio/AVAudioEngine/connectNode(_:to:format:))

[`connectNode(_:to:fromBus:toBus:format:)`](/documentation/AVFAudio/AVAudioEngine/connectNode(_:to:fromBus:toBus:format:))

[`connectNode(_:to:fromBus:format:)`](/documentation/AVFAudio/AVAudioEngine/connectNode(_:to:fromBus:format:))

[`connect(_:to:format:)`](/documentation/AVFAudio/AVAudioEngine/connect(_:to:format:))

Establishes a connection between two nodes.

[`connect(_:to:fromBus:toBus:format:)`](/documentation/AVFAudio/AVAudioEngine/connect(_:to:fromBus:toBus:format:))

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

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

Removes all input connections of the node.

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

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

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

Removes all output connections of a node.

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

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

### Managing MIDI Nodes

[`connectMIDI(_:to:format:eventListProvider:)`](/documentation/AVFAudio/AVAudioEngine/connectMIDI(_:to:format:eventListProvider:)-8tmk8)

[`connectMIDI(_:to:format:eventListProvider:)`](/documentation/AVFAudio/AVAudioEngine/connectMIDI(_:to:format:eventListProvider:)-35k1c)

[`connectMIDI(_:to:format:eventListBlock:)`](/documentation/AVFAudio/AVAudioEngine/connectMIDI(_:to:format:eventListBlock:)-73cd1)

Establishes a MIDI connection between two nodes.

[`connectMIDI(_:to:format:eventListBlock:)`](/documentation/AVFAudio/AVAudioEngine/connectMIDI(_:to:format:eventListBlock:)-7qtd5)

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

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

Removes a MIDI connection between two nodes.

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

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

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

Disconnects all input MIDI connections from a node.

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

Disconnects all output MIDI connections from a node.

[`connectMIDI(_:to:format:block:)`](/documentation/AVFAudio/AVAudioEngine/connectMIDI(_:to:format:block:)-3bc13)

Establishes a MIDI-only connection between two nodes.

[`connectMIDI(_:to:format:block:)`](/documentation/AVFAudio/AVAudioEngine/connectMIDI(_:to:format:block:)-666bc)

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

### Playing Audio

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

Prepares the audio engine for starting.

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

Starts the audio engine.

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

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

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

Pauses the audio engine.

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

Stops the audio engine and releases any previously prepared resources.

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

Resets all audio nodes in the audio engine.

[`withMusicSequence(_:)`](/documentation/AVFAudio/AVAudioEngine/withMusicSequence(_:))

Provides scoped access to the AVAudioEngine’s MusicSequence

### Manually Rendering an Audio Engine

[`enableManualRenderingMode(_:format:maximumFrameCount:)`](/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.

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

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

[`renderOffline(_:to:)`](/documentation/AVFAudio/AVAudioEngine/renderOffline(_:to:))

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

### Getting Manual Rendering Properties

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

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

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

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

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

The render format of the engine in manual rendering mode.

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

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

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

The manual rendering mode configured on the engine.

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

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

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

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

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

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

### Using Connection Points

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

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

[`connect(_:to:fromBus:format:)`](/documentation/AVFAudio/AVAudioEngine/connect(_:to:fromBus:format:))

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

[`inputConnectionPoint(for:inputBus:)`](/documentation/AVFAudio/AVAudioEngine/inputConnectionPoint(for:inputBus:))

Returns connection information about a node’s input bus.

[`outputConnectionPoints(for:outputBus:)`](/documentation/AVFAudio/AVAudioEngine/outputConnectionPoints(for:outputBus:))

Returns connection information about a node’s output bus.

### Notifications

[`AVAudioEngineConfigurationChangeNotification`](/documentation/AVFAudio/AVAudioEngineConfigurationChangeNotification)

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

### Constants

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

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

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

The two modes for manual rendering.

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

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



---

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-policy)