以下代码将iOS音频引擎配置为创建采用一种声音字体(为简化讨论)设置的采样器。然后我使用这些示例播放MIDI音符,并且一切正常,直到我尝试引入一系列标准效果(失真 - >延迟 - >混响)。如何正确配置AVAudioUnitEffects的链条
如果采样器的输出简单地连接直接到音频引擎MainMixerNode它的工作原理。如果我将采样器连接到失真效果(链中的第一个效果),那么只要我尝试播放第一个MIDI音符,就会收到错误“AVAudioUnitMIDIInstrument.mm:103: - [AVAudioUnitMIDIInstrument startNote:withVelocity:onChannel:]:错误-10867"
注:我使用Xamarin在Mac上,所以下面可能看起来陌生,但我希望的代码是你的协助足够可读的代码。
的问题仅仅是我要去哪里错在初始化我的影响/或链上?
由于提前, 克里斯
private void InitAudioEngine(NSUrl sampleFileUrl)
{
AVAudioSession.SharedInstance().Init();
NSError sessionErrorCode;
sessionErrorCode = AVAudioSession.SharedInstance().SetCategory (AVAudioSessionCategory.Playback);
if(sessionErrorCode != null)
Logger.Write ("Failed to set AudioSession category");
sessionErrorCode = AVAudioSession.SharedInstance().SetActive (true);
if(sessionErrorCode != null)
Logger.Write ("Failed to activate AudioSession");
Logger.Write ("Instantiate Audio Engine");
_audioEngine = new AVAudioEngine();
_samplers = new List<AVAudioUnitSampler>();
var distortion = new AVAudioUnitDistortion();
var delay = new AVAudioUnitDelay();
var reverb = new AVAudioUnitReverb();
distortion.Init();
delay.Init();
reverb.Init();
distortion.LoadFactoryPreset (AVAudioUnitDistortionPreset.SpeechGoldenPi);
reverb.LoadFactoryPreset (AVAudioUnitReverbPreset.LargeHall2);
delay.DelayTime = 300;
delay.WetDryMix = 30;
delay.Feedback = 30;
_audioEngine.AttachNode (distortion);
_audioEngine.AttachNode (delay);
_audioEngine.AttachNode (reverb);
_audioEngine.Connect (distortion, delay, delay.GetBusOutputFormat (0));
_audioEngine.Connect (delay, reverb, reverb.GetBusOutputFormat (0));
_audioEngine.Connect (reverb, _audioEngine.MainMixerNode, _audioEngine.MainMixerNode.GetBusOutputFormat (0));
for (int index = 0; index < 15; index++)
{
var sampler = new AVAudioUnitSampler();
sampler.Init();
_samplers.Add (sampler);
_audioEngine.AttachNode (sampler);
_audioEngine.Connect (sampler, distortion, distortion.GetBusOutputFormat(0));
}
// Connect all the samplers to a defined SoundFont
ConnectSoundbank (sampleFileUrl);
NSError engineErrorCode;
_audioEngine.StartAndReturnError (out engineErrorCode);
if(engineErrorCode != null)
Logger.Write ("Failed to start AudioEngine after samplers attached");
}
// ...
// Later code
// Play a MIDI note on one of the samplers configured above
//
_samplers[0].StartNote(58,127,0); // Crashes with error -10867 (uninitialised)
//...etc...
只要我有我的git回购对齐,我会发布代码。 –