开发者

Record, modify pitch and play back audio in real time on iOS

开发者 https://www.devze.com 2023-01-30 03:54 出处:网络
I just wondering if anyone can explain to me how I would go about recording audio, modifying it (pitch?) and playing it back to the user on iPhone.

I just wondering if anyone can explain to me how I would go about recording audio, modifying it (pitch?) and playing it back to the user on iPhone.

I'm not asking for someone to do this for me, just a few hints on how I should go about it. looking through the docs it seems like I should be using AVAudioSession, AVAudioRecorder and AVAudioPlayer (AVFoundation.Framework) for the recording p开发者_StackOverflow中文版laying parts. Or should I be using the CoreAudio.Framework? and then there is the question regarding modifying the audio.


AVAudioUnitTimePitch should do the trick.

Sample code from udacity.com Intro to iOS App Development with Swift:

func playAudioWithVariablePitch(pitch: Float) {
    audioEngine.stop()
    audioEngine.reset()

    let audioPlayerNode = AVAudioPlayerNode()
    audioEngine.attachNode(audioPlayerNode)

    let changePitchEffect = AVAudioUnitTimePitch()
    changePitchEffect.pitch = pitch
    audioEngine.attachNode(changePitchEffect)

    audioEngine.connect(audioPlayerNode, to:changePitchEffect, format:nil)
    audioEngine.connect(changePitchEffect, to:audioEngine.outputNode, format:nil)

    audioPlayerNode.scheduleFile(audioFile, atTime:nil, completionHandler: nil)
    try! audioEngine.start()

    audioPlayerNode.play()
}


OpenAL is a library, that supports what you're searching for. And its very popular on the iPhone, so maybe you should take a look on this. i.e. The pitch of an sample is easily changeable with only one command:

alSourcef(source, AL_PITCH, pitch);

But I'm not sure, if pitch change is also with the AVFoundation or CoreAudio classes possible - never used them.


This might help. DIRAC-mobile, a library for real-time tempo and pitch manipulation of polyphonic audio signals. They also have sample codes that you can take a look once you download the library.

0

精彩评论

暂无评论...
验证码 换一张
取 消