gpt4 book ai didi

iPhone 声音和延迟

转载 作者:行者123 更新时间:2023-12-03 20:27:02 26 4
gpt4 key购买 nike

我正在开发一个应用程序,用户可以点击多个产生声音的点击区域。
但结果是有点滞后,当多个声音同时启动时,声音的播放有一个难看的延迟。

我正在为每个声音使用 AVAudioPlayer 实例。有没有更好的方法来播放声音并防止这种延迟?

代码如下:

#import "MBImageView.h"
#import <AVFoundation/AVFoundation.h>

@implementation MBImageView

-(void)awakeFromNib
{
NSURL* audioFile = [NSURL fileURLWithPath[[NSBundlemainBundle] pathForResource:@"shaker"
ofType:@"caf"]];
AudioServicesCreateSystemSoundID((CFURLRef)audioFile, &shortSound);

}

- (id)initWithImage:(UIImage *)image{
return self;
}

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
AudioServicesPlaySystemSound(shortSound);
}


@end

问候。

最佳答案

大多数声音(AVAudioPlayer 和 AudioServices)都会在运行循环结束后播放。也就是说,您说播放,他们就会排队播放,并且不会立即开始播放。

如果您想要无延迟的声音,请使用 Audio Unit :

To provide lowest latency audio, especially when doing simultaneous input and output (such as for a VoIP application), use the I/O unit or the Voice Processing I/O unit. See “Audio Unit Support in iPhone OS.”

您可能还想查看Audio Toolbox :

Use the Audio Toolbox framework to play audio with synchronization capabilities, access packets of incoming audio, parse audio streams, convert audio formats, and record audio with access to individual packets. For details, see Audio Toolbox Framework Reference and the SpeakHere sample code project.

关于iPhone 声音和延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1530030/

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