Iphone iOS CocosDenshion音频播放不均匀(滞后)
我正在尝试为一个需要快速连续播放样本的应用程序实现平滑的音频播放。我希望Cocos2d和CocosDenshion能够实现这一点,因为AVAudioPlayer由于滞后问题而无法工作,但我仍然遇到问题——这里模拟的“16音符”最终听起来摇摆不定 我要用RemoteIO之类的东西吗?要获得在iOS中播放项目所需声音的精确计时,最简单的方法是什么 或者,使用CDAudioEngine playSound:功能不是我用CocosDenshion做事情的最有效方式吗 要加载发动机:Iphone iOS CocosDenshion音频播放不均匀(滞后),iphone,objective-c,cocos2d-iphone,Iphone,Objective C,Cocos2d Iphone,我正在尝试为一个需要快速连续播放样本的应用程序实现平滑的音频播放。我希望Cocos2d和CocosDenshion能够实现这一点,因为AVAudioPlayer由于滞后问题而无法工作,但我仍然遇到问题——这里模拟的“16音符”最终听起来摇摆不定 我要用RemoteIO之类的东西吗?要获得在iOS中播放项目所需声音的精确计时,最简单的方法是什么 或者,使用CDAudioEngine playSound:功能不是我用CocosDenshion做事情的最有效方式吗 要加载发动机: [CDAudioMa
[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)];
测试回放的线程代码(基本上是Metronome示例应用程序,编辑为使用CocosDenshion回放):
RemoteI0
这有一些关于原因的信息
Ugh——我希望不必像他在那篇文章中所说的那样参与到“毁灭的伟大音频界面”中。我使用了RemoteIO。它有点复杂,但实际上并没有我想象的那么糟糕。有什么好的指针(链接?)可以让我开始玩WAV文件吗?好吧,我已经具备了同时玩多个样本的基本能力。现在,所有的数学计算,何时发挥他们。。。对于其他想要开始的人,我也发现这是一个有用的资源:
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];