AudioKit / AudioKit

Audio synthesis, processing, & analysis platform for iOS, macOS and tvOS

Home Page:http://audiokit.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AudioPlayer schedule not working as expected

jasonayre opened this issue · comments

macOS Version(s) Used to Build

macOS 12 Monterey

Xcode Version(s)

Xcode 14

Description

So I'm just trying to schedule a buffered AudioPlayer, at multiple, specific times. I am running entirely in offline mode. For context, my code currently looks like this, which I've had to do the following to avoid weird pops when playback starts: (sampleTimeDelay function just calculates the delay correctly based on the buffers sample rate)

          avNodeAsType().prepare(withFrameCount: buffer.frameLength)
          akNodeAsType().load(buffer: buffer)
          akNodeAsType().schedule(at: sampleTimeDelay(Float(delay)))
          akNodeAsType().play()

^ (I mention this in case any of it looks weird. Because I was also expecting to not have to call play on the node after scheduling, but if I remove play nothing plays back.)

Anyways, rather than calling the schedule function as above, I'm essentially just trying to do this:

      for time in trigger_at_times {
        akNodeAsType().schedule(at: sampleTimeDelay(Float(time)))
      }

But if I do that, then the last call to schedule overrides all the previous calls, and it only plays at the the time for the last value in the array.

So I thought I could work around it by using the completion handler to reschedule/ play the buffer after it stops (although that's not really what I want either because then if the sample is > length than the pause it won't trigger), but the completion handler isn't called at all when engine is in offline mode it looks like.

Any idea how I can achieve this, or whether I'm missing something obvious?

Crash Logs, Screenshots or Other Attachments (if applicable)

No response