control speed of sound xcode

限于喜欢 提交于 2019-12-06 03:49:53
propstm

AVAudioPlayer has a rate property which should be able to help you accomplish your goal. http://developer.apple.com/library/IOS/#documentation/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html

The audio player’s playback rate. @property float rate

Discussion

This property’s default value of 1.0 provides normal playback rate. The available range is from 0.5 for half-speed playback through 2.0 for double-speed playback.

To set an audio player’s playback rate, you must first enable rate adjustment as described in the enableRate property description.

I also found a good SO post on the AVAudioPlayer's rate: AVAudioPlayer rate

Seems like as you'd mentioned you could set a slider with values from 0.5 to 2.0 and on valuechanged modify the audio players rate by using

- (IBAction)changeValue:(UISlider *)sender
{
    //made up assumed ivar names
    if ([_audioPlayer respondsToSelector:@selector(setEnableRate:)])
        _audioPlayer.enableRate = YES;
    if ([_audioPlayer respondsToSelector:@selector(setRate:)])
        _audioPlayer.rate = [NSNumber numberWithFloat:slideValue];
}

Playing PCM audio at a faster or slower rate than its sample rate changes its pitch and also introduces considerable artefacts. If you're OK with this, the approach you would use is to decode the MP3 into PCM audio and then use Direct Digital Synthesis Oscillator to control the playback rate.

If you want to maintain pitch but change speed, you need a audio time-stretching algorithm.

Dirac3 from DSP Dimension is a commercial product that can do it, and which is available for licensing for use in iOS application. Other commercial solutions exist.

DSP Dimension's blog provides a helpful tutorial on the basics of how to implement pitch-shifting using a FFT. Time stretching is essentially the same process. However, there's a fair bit of secret sauce in the DIRAC plug-in they don't tell you about.

Be warned that unless you're a Electronics engineering, physics or maths graduate, you'll probably it tough going to fill in the blanks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!