CoreMIDI:坚如磐石的MIDI同步 [英] CoreMIDI: rock solid midi sync

查看:149
本文介绍了CoreMIDI:坚如磐石的MIDI同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在与MIDI同步的烦恼。继在syntheticbits.com帖子,我使用了一个PGMidi类。
同步工作,而是不断变化的1-2 BPM。

I'm having troubles with midi synchronization. Following posts in the syntheticbits.com, I use a PGMidi class. Sync works, but is constantly shifting to 1-2 bpm.

下面是我用code:

- (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];
}

请告诉我如何得到一个明确的同步。

Please tell me how to get a clear synchronization.

推荐答案

第一:其中此消息正从叫什么名字?什么是你的计时器?你需要确保你使用一个非常精确的定时器。您将基本需要的东西是更严格的超过10ms(20ms的是MIDI时钟脉冲的周期,每季度注24脉冲,每分钟120四分音符)。

First: where is this message getting called from? What is your timer? You need to make sure you use a very accurate timer. You will essentially need something that is tighter than 10ms (20ms is the period of the MIDI clock pulse, at 24 pulses per quarter note, 120 quarter notes per minute).

这家伙做了$ P对同步原语$ ptty像样的写了在iOS / MacOS中获得。

This guy did a pretty decent write-up on synchronization primitives available on iOS / MacOS.

他这里最坏的情况下(即涉及自旋锁定)仍然是关闭的几乎50毫秒在最坏的情况下,并在平均情况下关闭的14毫秒。这是MIDI绝对可怕时机。最好的办法是利用现有的信息<一开始CoreAudio的线程(或一个实时线程href=\"https://developer.apple.com/library/mac/#documentation/Darwin/Conceptual/KernelProgramming/scheduler/scheduler.html\"相对=nofollow>这里)。

His worst case here (that involves spin-locking) is still off by almost 50ms in the worst case, and off by 14ms in the average case. This is absolutely terrible timing for MIDI. Your best bet is to start a CoreAudio thread (or a real-time thread using the info available here).

这篇关于CoreMIDI:坚如磐石的MIDI同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆