相关疑难解决方法(0)

在iOS中准确计时

我正在查看iOS SDK中的"Metronome"示例代码(http://developer.apple.com/library/ios/#samplecode/Metronome/Introduction/Intro.html).我正在以60 BPM的速度运行节拍器,这意味着每秒都会打勾.当我看一下外部手表(PC的手表)时,我看到节拍器运行速度太慢 - 它错过了每分钟一次,这就是app.15毫秒的一致错误.相关代码是:

- (void)startDriverTimer:(id)info {    
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];       

    // Give the sound thread high priority to keep the timing steady.    
    [NSThread setThreadPriority:1.0];    
    BOOL continuePlaying = YES;   

    while (continuePlaying) {  // Loop until cancelled.   
        // An autorelease pool to prevent the build-up of temporary objects.    
        NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];     
        [self playSound];

        [self performSelectorOnMainThread:@selector(animateArmToOppositeExtreme) withObject:nil waitUntilDone:NO];    
        NSDate *curtainTime = [[NSDate alloc] initWithTimeIntervalSinceNow:self.duration];    
        NSDate *currentTime = [[NSDate alloc] init];  
        // Wake up periodically …
Run Code Online (Sandbox Code Playgroud)

time cocoa-touch ios4 ios

16
推荐指数
2
解决办法
1万
查看次数

音频播放的准确(音乐级)时间

我正在尝试编写一个应用程序,可以安排一些(大多数是微小的)音频文件的定时播放.问题:它需要定时准确的音乐.这些声音将不会播放频繁(它不是,例如采样器或鼓包),但他们需要绝对精确地放置.这个问题分为两部分:

  1. 我该如何组织时间安排?我听说NSTimer不准确,或者至少不可靠?我应该以某种方式使用MIDI吗?还是一个紧凑的循环和一些具有高分辨率的时间获取功能?

  2. 一旦我完成了计时,我知道何时播放我的声音......我该怎么玩它们?是否NSSound快速可靠,足以保持所需的准确度?

audio macos cocoa objective-c

4
推荐指数
2
解决办法
2151
查看次数

标签 统计

audio ×1

cocoa ×1

cocoa-touch ×1

ios ×1

ios4 ×1

macos ×1

objective-c ×1

time ×1