我在midi同步方面遇到了麻烦。在syntheticbits.com上的帖子之后,我使用了一个PGMidi类。 同步有效,但不断变为1-2 bpm。
以下是我使用的代码:
- (void)sendMidiClockInMidiThread {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[lock lock];
const int64_t kOneMillion = 1000 * 1000;
const UInt8 tick[] = { 0xF8 };
// Calculate tick time
// returns sample for sixteen note (5512 if current bpm is 120)
SInt32 sixteen = AGGetSamples_SixteensWithoutSwing(_grid, 1.0);
UInt64 tickTime = (sixteen / 6) * kOneMillion;
int tickLatency = 0;
// Send ticks messages
for (int i = 0; i < 6; ++i) {
int beginTime = clock();
hostTime = hostTime + (tickTime - tickLatency);
[self.midi sendBytes:tick size:sizeof(tick) atTime:hostTime];
int endTime = clock();
tickLatency = endTime - beginTime;
}
[lock unlock];
[pool drain];
}
请告诉我如何明确同步。