dmann200
dmann200

Reputation: 579

Synchronizing Playback of Multiple Audio Files in Audio Kit

I am developing a small audio sequencer application using AudioKit. I only need to play back 4 channels of audio. However I need to play them back perfectly synchronized down to the sample level. When I run a test using just two audio files, I can hear that they are not synchronized. The difference is only a few samples, but even a one sample discrepancy would be a problem. I am currently using multiple AKClipPlayer objects routed to an AKMixer object. I called him with the basics for loop like this:

   private var clipPlayers : [AKClipPlayer] = []

   func play(){
        for player in clipPlayers{
            player.play()
        }
    }

Is sample accurate playback timing of multiple audio files possible using AudioKit?

Upvotes: 2

Views: 826

Answers (1)

dave234
dave234

Reputation: 4955

Yes, you need to schedule playback to start in the future with play(at:).

// This can take longer than expected, so do this before choosing a future time
clipPlayers.forEach { $0.prepare(withFrameCount: 10_000) }

let nearFuture = AVAudioTime.now() + 0.2
clipPlayers.forEach { $0.play(at: nearFuture) }

Upvotes: 5

Related Questions