我很是新手,当谈到AudioUnits,所以请原谅我,如果我的问题是非常基本的。
我现在用的是MusicDevice AudioUnit播放的一些注意事项。 我使用MusicDeviceMIDIEvent发送音符开和音符关消息。 它工作得很好。 有时不止一个音符应同时发声,所以我可以连续发送两个音符上的消息。 有时,这些笔记碰巧具有相同的间距。 然后,当我想关闭的音符之一,我送一个音符关事件此间距。 但是,此消息将关闭球场的所有音符。 当然,这种行为使得很多的感觉,但我想问人们通常如何处理这个问题。
我应该使用同步笔记不同的渠道? 或手动管理票据,说了数集,其持有的间距当前播放的,只有一个球场的最后一个实例后发送音符关事件应停止播放? 还是其他?
编辑:
由于这是在iOS,我必须使用kAudioUnitSubType_Sampler作为AudioUnit子类型。 虽然文件只提到,这种类型是单声道音色,我现在怀疑它也是单声道。 当然,这可以解释的行为。 不过我不知道我怎么会去这就是如果我真的有一个和弦仪器。
编辑2:
我做了一些测试,它现在在我看来,在任何通道发送一个音符关消息将停止所有的笔记在所有通道上相同的间距。 我拿着苹果示例代码在http://developer.apple.com/library/ios/#samplecode/LoadPresetDemo/Introduction/Intro.html和修改stopPlay [低/中/高]注意方法来发送音符关在某些随机信道消息(如果必须知道,在信道7,8,和9,分别地)。 它仍然停止笔记,尽管音符上的消息正在对通道0发送这是预期的行为?
只是,以确保我没有做一个愚蠢的错误,这些都是发送音符开和音符关消息的方法:
- (IBAction) startPlayLowNote:(id)sender {
UInt32 noteNum = kLowNote;
UInt32 onVelocity = 127;
UInt32 noteCommand = kMIDIMessage_NoteOn << 4 | 0;
OSStatus result = noErr;
require_noerr (result = MusicDeviceMIDIEvent (self.samplerUnit, noteCommand, noteNum, onVelocity, 0), logTheError);
logTheError:
if (result != noErr) NSLog (@"Unable to start playing the low note. Error code: %d '%.4s'\n", (int) result, (const char *)&result);
}
- (IBAction) stopPlayLowNote:(id)sender {
//note the channel!
UInt32 noteNum = kLowNote;
UInt32 noteCommand = kMIDIMessage_NoteOff << 4 | 7;
OSStatus result = noErr;
require_noerr (result = MusicDeviceMIDIEvent (self.samplerUnit, noteCommand, noteNum, 0, 0), logTheError);
logTheError:
if (result != noErr) NSLog (@"Unable to stop playing the low note. Error code: %d '%.4s'\n", (int) result, (const char *)&result);
}