Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - convert mp3 to wav?

Is there a way I can convert an mp3 file into a wav/aiff in my iPhone app? I have an mp3 but I want to combine it with other files and the only way I know this can be done is when using PCM formats.

Can anyone help me out here?

Thanks.

Some things I tried

I tried using the AudioConverterFillComplexBuffer() method and its callback to convert the mp3 to caf but the bytes per packet and per frame are read as 0. Any ideas how I can or whether I can use this function?

Thanks again.

like image 967
lostInTransit Avatar asked Dec 14 '22 02:12

lostInTransit


1 Answers

WAV and AIFF often (usually?) contain PCM, so what's the objection there? Or are you saying that you have to get your MP3 data to PCM in order to mix it (perhaps in a multichannel mixer audio unit). If you seriously want to do this, look at Core Audio, specifically:

  • Audio File Services (to read the MP3 format and write AIFF or WAV)
  • Audio File Conversion Services (to convert the MP3 data to PCM, and/or to encode from PCM to some other codec if you were to write a file). Note that a given converter cannot convert between two encoded formats; you can do MP3-to-PCM or PCM-to-AAC, but to do MP3-to-AAC, you'd need two converters.
  • Extended Audio File Services, which combine both of the above.

Check out the ConvertFile example in the Core Audio SDK. This opens a source file for reading, describes the desired format of the target file, reads buffers from one and writes them to the other. The code exhibits both the separate use of file services + conversion services, and the convenient use of ExtAudioFiles.

Also, be sure to understand the difference between codecs and file formats, and what codec/format combinations are legal. I was surprised the first time I found out that PCM must be little-endian in a WAV, big-endian in an AIFF.

like image 112
invalidname Avatar answered Dec 28 '22 12:12

invalidname