2011-09-27 89 views
1

我有一个由程序生成的自我生成的DTMF声音(带有wav标头),我希望能够快速播放,实际上只要用户触摸按钮。这个DTMF​​声音必须无限地播放/循环播放,直到我停止播放。一些其他声音必须能够同时播放。在iOS中立即开始播放短的自制声音

我对音频编程非常陌生,我测试了很多方法,现在我迷了路。

我该如何做到这一点?

需求:

  • 很快开始播放(包括第一次)
  • 在同一时间较多声音(短声+ - 2-6秒)
  • 无限DTMF声音无间隙
  • 在被打/能够阻止不同的声音有控制权只是一个播放的声音

回答

1

AVAudioPlayer如果您确实需要延迟尽可能低,那么您可以忍受一些延迟OpenAL(例如Finch)。

+0

其实你可以通过提前排队轨道摆脱这种延迟。这样当你玩这个游戏时你会得到一个热门的开始。 –

+0

有多热?上次我测量的时间总是至少20毫秒左右,这对于很多目的来说太慢了。但是我尝试了很长一段时间,所以情况可能会好转。 – zoul

+0

/s/hotstart/lukewarmstart –

-1

我使用已经存在的.wav文件。我可以轻松地播放它。

用于运行以下代码。包括AudioToolbox框架。

写入到.h文件中#import <AudioToolbox/AudioToolbox.h>
写入.m文件

-(IBAction)startSound{ 

    //Get the filename of the sound file: 
    NSString *path = [NSString stringWithFormat:@"%@%@", [[NSBundle mainBundle] resourcePath], @"/sound1.wav"]; 

     //declare a system sound 
     SystemSoundID soundID; 

    //Get a URL for the sound file 
    NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO]; 

    //Use audio sevices to create the sound 
    AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID); 
    //Use audio services to play the sound 
    [self sound]; 
    timer =[ [NSTimer scheduledTimerWithTimeInterval:2.1 target:self selector:@selector(sound) userInfo:nil repeats:YES]retain]; 

} 
+0

我不认为系统声音服务很适合这个。延迟如何?你可以循环播放声音吗?你能阻止个人的声音吗? – zoul