4

I would like to use the lame mp3 encoder for encoding audio data on the iPhone and save it to a file. I'm able to use lame for encoding and I'm able to use the Extended Audio File Services for writing audio files. I would like to combine the two so that my code is consistent and does not use two kinds of glue code when writing audio files of different formats.

A possible solution I can imagine is to wrap an own AudioConverter (like the ones created by AudioConverterNew) around lame so that I can use this converter together with the Extended Audio File Services functions, most prominently with ExtAudioFileWrite. Can you help me to implement this solution or another one which makes it possible to write mp3 files consistently with the API provided by iOS?

UPDATE:

After lots of trial'n'error, I'm convinced that the AudioConverter structure provided by Apple is not extensible for app developers. Therefor, I'm using the following work around:

I've created my own abstract AudioEncoder class, which declares methods for encoding audio data and writing it to a file. I then subclassed this AudioEncoder class, one for wrapping around the ExtAudioFileRef functions and one as a wrapper for LAME. I can now use these subclasses wherever I want to encode audio, but I do not have to care there if I encode to a natively supported format or to a format which I added with an external library, because my encoder classes hide all the API-details of the underlying encoder. If I later want to add OGG or FLAC, this will be easy, because I will only need to write additional subclasses of AudioEncoder for wrapping the respective OGG or FLAC library.

Daniel S.
  • 6,458
  • 4
  • 35
  • 78
  • I think the main reason that Apple does not implement APIs for writing mp3 files is more to do with legal issues around mp3 rather than technical issues. ExtAudioFileWrite is set up in a way that it allows you to give it an audio buffer - which is completely pre-encoding so I really don't think you could use ExtAudioFileWrite with your own encoder. However, if you are using LAME to encode - you are already at the point where audio samples -> data. Why not simply write that data to a file with the extension '.mp3' – e7mac Mar 24 '14 at 18:07
  • @e7mac, I've rephrased one sentence. I hope it's clearer now: I would like to combine the two so that my code is consistent and does not use two kinds of glue code when writing audio files of different formats. – Daniel S. Mar 24 '14 at 18:14
  • @e7mac, this question is not about making an end result possible (mp3 encoding). Instead, it's about writing good, elegant code which can be easily refactored later if need should be. – Daniel S. Mar 24 '14 at 18:15

0 Answers0