swiftaudiosignal-processingavaudioenginebass

Installing the BASS audio library into a Swift Xcode Project (Mac & iOS)


There is a BASS audio library (written in C) from un4seen.com that, in my experience, has much better performance and efficiency than AVAudioEngine. However, I have experienced great difficulty in installing it into my Swift Xcode project. How do you install this library into Xcode?

The BASS audio library is free for non-commercial use. It has very powerful commands for performing digital signal processing (DSP) on audio signals. For example, the following two lines

Timer.scheduledTimer(withTimeInterval: 1.0/60.0, repeats: true) { time in
    BASS_ChannelGetData(stream, &spectrum, BASS_DATA_FFT16384) }

extracts 16,384 samples from the playing audio stream, converts it to mono, applies a Hann window function, calculates it's Fourier transform, generates it's power spectrum, and does this repeatedly every 60th of a second.


Solution

  • There is now a much simpler method of incorporating BASS into an Xcode Swift project than the answer I provided earlier. A programmer named Treata Norouzi packaged the BASS files into a Swift Package which he called CBass. He made this package open-source and posted it on GitHub. Simply importing the CBass package seamlessly integrates the BASS audio library and its extensive collection of extensions into your Swift projects.

    To import BASS into your Xcode project, click on "File | Add Package Dependencies...". In the resultant pop-up window, type "github.com/Teatra11/CBass" as the repository url, and click on "Add Package". Then type "import Bass" at the top of any class in the project using BASS library commands.

    To be clear, the CBass Swift Package wrapper is open source and free for general usage, but the wrapper's contents (mainly the files bass.xcframework, libbass.xcframework, bass.h, bridge.c, and bridge.h) are proprietary to Un4seen Developments. Usage of these files is free for non-commercial use.

    I posted a simple Swift project named SwiftCBassDemo (here) as a sample illustrating proper usage.