Skip to content

A Swift 4 framework for streaming remote audio with real-time effects using AVAudioEngine

License

Notifications You must be signed in to change notification settings

carson-katri/AudioStreamer

 
 

Repository files navigation

streaming-audio-avaudioengine-banner-w-phone-image

AudioStreamer

Apache License

A Swift 4 framework for streaming remote audio with real-time effects using AVAudioEngine. Read the full article here!

Examples

This repo contains two example projects, one for iOS and one for macOS, in the TimePitchStreamer.xcodeproj found in the Examples folder.

device-examples

Blog Post Preview

Building our AVAudioEngine streamer

Because the AVAudioEngine works like a hybrid between the Audio Queue Services and Audio Unit Processing Graph Services we can combine what we know about each to create a streamer that schedules audio like a queue, but supports real-time effects like an audio graph.

At a high-level here's what we'd like to achieve:

Streamer overview diagram

Here's a breakdown of the streamer's components:

  1. Download the audio data from the internet. We know we need to pull raw audio data from somewhere. How we implement the downloader doesn't matter as long as we're receiving audio data in its binary format (i.e. Data in Swift 4).
  2. Parse the binary audio data into audio packets. To do this we will use the often confusing, but very awesome Audio File Stream Services API.
  3. Read the parsed audio packets into LPCM audio packets. To handle any format conversion required (specifically compressed to uncompressed) we'll be using the Audio Converter Services API.
  4. Stream (i.e. playback) the LPCM audio packets using an AVAudioEngine by scheduling them onto the AVAudioPlayerNode at the head of the engine.

In the following sections we're going to dive into the implementation of each of these components. We're going to use a protocol-based approach to define the functionality we'd expect from each component and then do a concrete implementation. For instance, for the Download component we're going to define a Downloadable protocol and perform a concrete implementation of the protocol using the URLSession in the Downloader class...read more

About

A Swift 4 framework for streaming remote audio with real-time effects using AVAudioEngine

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 100.0%