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.