简体   繁体   English

AudioKit 4.1 - 如何正确阻止AKSampler播放音频?

[英]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. 我有2个AKSamplers连接到AKMixer但是当我为每个AKSampler调用stop函数时,音频不会停止播放它只在我调用AKMixer的停止时停止。 How do I stop playing an AKSampler which is connected to an AXMixer? 如何停止播放连接到AXMixer的AKSampler?

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. 使用AKSampler停止音符的首选方法是停止先前启动的特定 AKSampler音符。

For example: 例如:

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

Should successfully stop the AKSampler. 应该成功停止AKSampler。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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