2
我试图为需要快速连续播放样本的应用程序获得流畅的音频播放。我希望Cocos2d和CocosDenshion能够做到这一点,因为AVAudioPlayer由于滞后问题而无法工作,但我仍然遇到问题 - 这里模拟的“第16个音符”最终听起来会摇摆不定。iOS CocosDenshion音频播放参差不齐(延迟)
我将不得不去与RemoteIO或类似的东西?在iOS中播放声音的精确时机最简单的方法是什么?
或者,正在使用CDAudioEngine playSound:函数不是我可以用CocosDenshion做的最有效的方法吗?
要加载引擎:
[CDAudioManager sharedManager];
while ([CDAudioManager sharedManagerState] != kAMStateInitialised) {
[NSThread sleepForTimeInterval:0.1];
NSLog(@"Not init yet...");
}
CDSoundEngine *sse = [CDAudioManager sharedManager].soundEngine;
NSArray *defs = [NSArray arrayWithObjects:
[NSNumber numberWithInt:16],nil];
[sse defineSourceGroups:defs];
[[CDAudioManager sharedManager].soundEngine setSourceGroupNonInterruptible:0 isNonInterruptible:TRUE];
NSLog(@"Loading sound: %i",[sse loadBuffer:1 filePath:@"bass drum.wav"]);
[[CDAudioManager sharedManager] setResignBehavior:kAMRBStopPlay autoHandle:YES];
[[CDAudioManager sharedManager] setMode:(kAMM_MediaPlayback)];
线程代码以测试播放(基本上节拍器示例应用程序,editted使用CocosDenshion播放):
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Give the sound thread high priority to keep the timing steady.
[NSThread setThreadPriority:1.0];
BOOL continuePlaying = YES;
CDSoundEngine *sse = [CDAudioManager sharedManager].soundEngine;
while (continuePlaying) { // Loop until cancelled.
// An autorelease pool to prevent the build-up of temporary objects.
NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];
[sse playSound:1 sourceGroupId:0 pitch:1.0f pan:0.0f gain:1.0f loop:NO];
withObject:nil waitUntilDone:NO];
NSDate *curtainTime = [[NSDate alloc] initWithTimeIntervalSinceNow:0.125f];
NSDate *currentTime = [[NSDate alloc] init];
// Wake up periodically to see if we've been cancelled.
while (continuePlaying && ([currentTime compare:curtainTime] != NSOrderedDescending)) {
if ([soundPlayerThread isCancelled] == YES) {
continuePlaying = NO;
}
[NSThread sleepForTimeInterval:0.005];
[currentTime release];
currentTime = [[NSDate alloc] init];
}
[curtainTime release];
[currentTime release];
[loopPool drain];
}
[pool drain];
呃 - 我希望在那篇文章中他不需要介入“Doom的伟大音频接口”。 – 2011-03-14 20:13:45
我已经使用了RemoteIO。这有点复杂,但并不像我认为的那样糟糕。 – madmik3 2011-03-14 20:22:20
任何好的指针(链接?)只是开始 - 只是用它播放WAV文件? – 2011-03-14 20:30:04