SFBAudioEngine is a framework for macOS and iOS audio playback using Swift or Objective-C. SFBAudioEngine supports the following formats:
- WAVE
- AIFF
- Apple Lossless
- AAC
- FLAC
- MP3
- WavPack
- Ogg Vorbis
- Ogg Speex
- Ogg Opus
- Musepack
- Monkey's Audio
- True Audio
- Shorten
- All formats supported by libsndfile
- All formats supported by Core Audio
- DSD to PCM conversion for DSD64
In addition to playback SFBAudioEngine supports reading and writing of metadata for most supported formats.
macOS 10.15+ or iOS 13.0+
- Clone the SFBAudioEngine repository.
- Download the dependencies and decompress in the project's root
- Open the project, build, and play something using SimplePlayer!
Playing an audio file is as simple as:
import SFBAudioEngine
let player = AudioPlayer()
let url = URL(fileURLWithPath: "example.flac")
try? player.play(url)
Reading audio properties and metadata is similarly trivial:
if let audioFile = try? AudioFile(readingPropertiesAndMetadataFrom: url) {
let sampleRate = audioFile.properties.sampleRate
let title = audioFile.metadata.title
}
Audio decoders in SFBAudioEngine are broadly divided into two categories, those producing PCM output and those producing DSD output. Audio decoders read data from an SFBInputSource which may refer to a file, buffer, or network source.
All audio decoders in SFBAudioEngine implement the SFBAudioDecoding protocol. PCM decoders additionally implement SFBPCMDecoding while DSD decoders implement SFBDSDDecoding.
Three special decoder subclasses that wrap an underlying audio decoder instance are also provided: SFBLoopableRegionDecoder, SFBDoPDecoder, and SFBDSDPCMDecoder. For seekable inputs, SFBLoopableRegionDecoder allows arbitrary looping and repeating of a specified PCM decoder segment. SFBDoPDecoder and SFBDSDPCMDecoder wrap a DSD decoder providing DSD over PCM (DoP) and PCM output respectively.
SFBAudioPlayerNode is a subclass of AVAudioSourceNode that provides rich playback functionality within an AVAudioEngine processing graph. SFBAudioPlayerNode supports gapless playback and comprehensive status notifications through delegate callbacks.
SFBAudioPlayer wraps an AVAudioEngine processing graph driven by SFBAudioPlayerNode. SFBAudioPlayer provides complete player functionality with no required configuration but also allows customization of the underlying processing graph as well as rich status notifications through delegate callbacks.
Audio properties and metadata are accessed from instances of SFBAudioFile. Audio properties are read-only while metadata is writable for most formats.
Two versions of SimplePlayer, one for macOS and one for iOS, are provided illustrate the usage of SFBAudioEngine.
SimplePlayer for macOS is written in Swift using AppKit and supports gapless sequential playback of items from a playlist. The essential functionality is contained in one file, PlayerWindowController.swift.
SimplePlayer for iOS is written in Swift using SwiftUI and supports playback of a single item selected from a list.
SFBAudioEngine is released under the MIT License.