AudioKit 5 - Mixer一次只播放1个ampludeenvelope



我使用AudioKit 5(开发)与Xcode 12和iOS 14。

我首先创建一个由28个振荡器和28个振幅信封组成的数组。

我用相应的振荡器初始化28个amplitudeenvelope,并启动所有振荡器,但不启动amplitudeenvelope。

我将每个AmplitudeEnvelope连接到Mixer,然后将AudioEngine的输出分配给该Mixer。

当用户触摸与amplitudeenvelope相对应的28个按钮中的1个时,我启动该信封并从扬声器中获得正确的声音(攻击和释放是正确的)。

然而,当用户从按钮上抬起他/她/他们的手指时,我访问了amplitudeenvelope数组并停止了相应的信封。

然而,如果我按住一个按钮,然后我开始按另一个按钮,第一个振幅信封自动切断。

为什么?

在触摸手势识别器中,我打印了"START"one_answers";STOP"当手势开始和结束时,分别

我发现从一个信封开始我不知道问题出在哪里。

@objc func handletouch(gesture: UILongPressGestureRecognizer) {
if gesture.state == .began {
print("START")
self.soft.impactOccurred()
let theindex = (gesture.view as! BUTTON).theindex
let thefrequency = (gesture.view as! BUTTON).midinumber.midiNoteToFrequency()
let theoscillator = self.oscillators[theindex]
theoscillator.frequency = thefrequency
let theenvelope = self.envelopes[theindex]
theenvelope.start()
}
if gesture.state == .ended {
print("STOP")
let theindex = (gesture.view as! BUTTON).theindex
let theenvelope = self.envelopes[theindex]
theenvelope.stop()
}
}

结果是我能够解决这个问题。

我用Array<Oscillator> = Array(repeating, count)创建了一个振荡器数组,并且发现所有的振荡器都将被赋予与我分配给它们中的任何一个相同的频率。

因此,在现实中,不止一个ampludeenvelope同时被播放,但它们播放的频率相同。

我刚刚初始化了一个空的振荡器数组,并在一个简单的for循环中手动创建了它们。这就解决了问题。

最新更新