gpt4 book ai didi

iphone - iOS CocosDenshion 音频播放不均匀(滞后)

转载 作者:行者123 更新时间:2023-12-03 21:07:57 25 4
gpt4 key购买 nike

我正在尝试为需要快速连续播放样本的应用程序提供流畅的音频播放。我希望 Cocos2d 和 CocosDenshion 能够实现这一点,因为 AVAudioPlayer 由于延迟问题而无法工作,但我仍然遇到问题 - 这里模拟的“16 分音符”最终听起来摇摆不定。

我必须使用 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)];

用于测试播放的线程代码(基本上是 Metronome 示例应用程序,经过编辑以使用 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];

最佳答案

远程I0

这有一些关于原因的信息 http://atastypixel.com/blog/developing-loopy-part-2-implementation/

关于iphone - iOS CocosDenshion 音频播放不均匀(滞后),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5303456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com