A Swift Package Manager wrapper for aubio - a powerful audio analysis library for tempo detection, pitch detection, beat tracking, and more.
The original aubio library is only available via CocoaPods. This fork adds Swift Package Manager (SPM) support, making it easy to integrate aubio into modern Swift and iOS projects without CocoaPods.
aubio is a library to label music and sounds. It listens to audio signals and attempts to detect events such as:
- When a drum is hit
- At which frequency a note is playing
- At what tempo a rhythmic melody is playing
- π΅ Tempo/BPM Detection - Accurate beat tracking and tempo estimation
- πΌ Pitch Detection - Fundamental frequency analysis
- πΉ Note Detection - Musical note tracking
- π Spectral Analysis - FFT, phase vocoder, MFCC
- π Onset Detection - Attack time detection
- ποΈ Digital Filters - Low pass, high pass, and more
- β‘ Accelerate Optimized - Uses Apple's Accelerate framework for performance
- π¦ SPM Ready - No CocoaPods required
- π Native Apple - Built-in CoreAudio integration
Add to your Package.swift:
dependencies: [
.package(url: "https://github.com/vitallica/aubio", from: "0.5.0")
]Or in Xcode: File β Add Package Dependencies and paste the repository URL.
import Aubio
// Detect tempo from audio samples
func detectTempo(audioSamples: [Float], sampleRate: UInt32 = 44100) -> Double? {
let hopSize: UInt32 = 512
let windowSize: UInt32 = 1024
guard let tempo = new_aubio_tempo("default", windowSize, hopSize, sampleRate) else {
return nil
}
defer { del_aubio_tempo(tempo) }
guard let inputBuffer = new_fvec(hopSize) else { return nil }
defer { del_fvec(inputBuffer) }
var bpmValues: [Float] = []
for chunkStart in stride(from: 0, to: audioSamples.count, by: Int(hopSize)) {
let chunkEnd = min(chunkStart + Int(hopSize), audioSamples.count)
let chunk = Array(audioSamples[chunkStart..<chunkEnd])
for (i, sample) in chunk.enumerated() {
inputBuffer.pointee.data[i] = sample
}
aubio_tempo_do(tempo, inputBuffer, nil)
let bpm = aubio_tempo_get_bpm(tempo)
if bpm > 0 {
bpmValues.append(bpm)
}
}
guard !bpmValues.isEmpty else { return nil }
let sortedBPMs = bpmValues.sorted()
return Double(sortedBPMs[sortedBPMs.count / 2])
}π Full Documentation - Complete API reference, examples, and integration guide
Quick Links:
- Aubio Manual - Official aubio documentation
- Developer Documentation - Doxygen-generated API docs
- Homepage - Official aubio website
- iOS 13.0+ or macOS 11.0+
- Xcode 14.0+
- Swift 5.9+
Check out examples/AubioUsageExample.swift for complete working examples:
- β Tempo detection with confidence scoring
- β Pitch detection with YIN algorithm
- β Musical key detection
- β AVFoundation audio file loading
- β Integration patterns for iOS apps
This fork adds:
- β
Package.swiftmanifest for SPM support - β
C module map for Swift interop (
src/include/module.modulemap) - β Swift usage examples
- β iOS/macOS optimizations with Accelerate framework
- β Comprehensive documentation for Swift developers
All original aubio functionality is preserved and unchanged.
This wrapper maintains aubio's original GPL v3 license. See COPYING for full details.
aubio is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- Open source your app under GPL v3
- Obtain a commercial license from the aubio developers
- Use an alternative library
- Aubio Library: Paul Brossier and contributors
- Original Repository: aubio/aubio
- SPM Wrapper: Community contribution for Swift/iOS support
When citing this work, please reference the original aubio project:
The home page of this project can be found at: https://aubio.org/
For more information, see the about page in the aubio manual.
Found a bug or want to improve the SPM wrapper? Contributions are welcome!
- For aubio library issues: Report to aubio/aubio
- For SPM wrapper issues: Open an issue in this repository
- aubio - Original C library
- aubio-iOS CocoaPod - CocoaPods version
Happy audio analysis! π΅
Made with β€οΈ for the Swift community