简体   繁体   中英

AudioKit 4.1 - How to properly stop AKSampler from playing audio?

I have 2 AKSamplers that are connected to an AKMixer but when I call the stop function for each AKSampler, the audio does not stop playing it only stops when I call the stop of the AKMixer. How do I stop playing an AKSampler which is connected to an AXMixer?

Sample Code:

func stop() {
   let sampler1 = AKSampler()
   let sampler2 = AKSampler()
   let mixer = AKMixer(sampler1, sampler2)

   AudioKit.output = mixer

   do {
        try sampler1.loadWav("Support Objects/audio")
        try sampler2.loadWav("Support Objects/audio")
    } catch {
        return
   }

    do {
        try AudioKit.start()
    } catch let error as NSError{
        print(error.debugDescription)
    }

   sampler1.play(noteNumber: //some midi number)
   sampler2.play(noteNumber: //some midi number)
   sampler1.stop() // does not stop sampler1 from playing
}

A preferred method to stop notes with AKSampler is to stop the specific AKSampler note that was previously started.

For example:

 sampler1.play(noteNumber: yourMIDINoteNumber)
...
 sampler1.stop(noteNumber: yourMIDINoteNumber)

Should successfully stop the AKSampler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM