2

I'm making an app where I gotta record sound through microphone, change its pitch, save it in Documents Directory and play it.

I have accomplished the recording and playing part successfully via AVRecorder and AVAudioPlayer. But I'm unable to change the pitch of the recorder sound :(

Searched a lot all over StackOverlow and Google, but all methods aren't working. DIRAC is not available now I guess, SoundTouch integration is going over my head, other solutions are in Objectice-C++ which I don't understand.

Also tried OpenAL, but it only allows to play the changed pitch sound, not save it.

Please tell me if it's possible using Objective-C, or any other example/tutorial.

Thank you.

Hyder
  • 1,163
  • 2
  • 13
  • 37
  • I'm pretty sure you will probably have to implement your own code to pitch shift the code because I am pretty sure AVAudioPlayer only changes the pitch when it is playing it. There's some pitch shifting code out there on github and I know it's hard to hear this but try to understand and implement some classes that use Objective-C++. That said, you can definitely implement pitch shifting solely in Objective-C but you'd have to learn some DSP/know how to convert C++ to Objective-C from the code available online. Good luck! – yun Aug 12 '16 at 19:46
  • @yun.cloud sigh. Thanks for the info man. I'm dead – Hyder Aug 12 '16 at 19:53
  • 1
    If it helps I did this pitch shifter in college... You'll have to convert it to Objective-C but basically you'd have to pull all your data into a buffer and run it through this algorithm and write the new samples. Then you can save it that data into a new file. https://github.com/ryanfoo/pitch-shifter/blob/master/fooHarmonizer/Source/Shifter.cpp – yun Aug 12 '16 at 19:57
  • 2
    @yun.cloud actually I found this solution ( https://github.com/VladimirKravchenko/AVAudioEngineOfflineRender ) perfect. It takes audio from bundle, applies effect, and saves new file in document directory. Sad part is, when trying to load audio by recording through mic, the output file it saves is empty :( if this works, it will be magic for me – Hyder Aug 12 '16 at 20:02
  • Do you have an audio file from the recording without the pitch shifting? Or the file is empty no matter what? – yun Aug 12 '16 at 20:04
  • I didn't get you? I record audio, load it in audioengine, play it through audioEngine, it plays with pirch shifted, but when i render it, an empty audiofile is saved. I don't know why :( whereas if i load an audio from main bundle ( as in the example ) it works perfect – Hyder Aug 12 '16 at 20:25
  • I was confused by your wording I guess.. it still is a little unclear though, can you try saving an audio file without pitch shifting it and seeing if that audio file is empty? I only ask because even if you had the pitch shifting figured out your recorded file will still be empty... – yun Aug 12 '16 at 20:27
  • Already tried that. It saves empty 0 second long audiofile. Like i mentioned earlier, the pitch effect gets applied correctly and it is confirmed by playing the sound like '[_playerNode play]. But when i render it (save it) it saves empty file. Did i take a look at the github repo? – Hyder Aug 12 '16 at 20:30
  • Well sounds like you gotta resolve saving the recorded file first before you even get into pitch shifting. – yun Aug 12 '16 at 20:31
  • @yun.cloud did you check the link? – Hyder Aug 12 '16 at 20:34

0 Answers0