Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS and decoding MP3/AAC data from memory buffer

Tags:

ios

iphone

Forgive me, I very new at iOS - and programming at this scale in general.

I have been digging through iOS documentation, I know there are some functions like ExtAudiofile... for decoding MP3/AAC files, but are there any that will operate on Mp3/aac data that's already in memory?

I will probably have to extract the media data (byte by byte; iOS does allow that right?) from inside another file, so I can't just give it the URL.

Edit: the mp3 data will be in a non-standard file format, Apple provided function should not be able to read them. I heard iOS has a hardware decoder that works on one audio stream and the OS will fallback to software decoding if there are multiple streams.

I would rather use what Apple provides then integrate a MP3 decoder into the app.

like image 897
WanderingInLimbo Avatar asked Jul 14 '11 10:07

WanderingInLimbo


1 Answers

You can use ExtAudioFileRead to read a file that is in memory, but you have to use AudioFileOpenWithCallbacks. I'm not by my work computer so I can't give you exact code, but here's the general process:

  • Use fopen/fread to read the given file into a memory buffer array. Use a simple C array and not an NSArray or NSData - you need speed and you need for it to be compatible with the next step.
  • Create some basic C function callbacks for read / get size.
  • Use AudioFileOpenWithCallbacks with the callbacks you wrote to open the audio file in memory.
  • Use ExtAudioFileWrapAudioFileID to start decoding the file in memory. This is in replacement of ExtAudioFileOpenURL.

If you Google +AudioFileOpenWithCallbacks +ExtAudioFileWrapAudioFileID, you'll find that some folks have already done this and published their code.

I'm not sure what you mean by non-standard mp3 data, so you should try to play the file using another app to see if it will be compatible.

like image 132
user503821 Avatar answered Oct 03 '22 07:10

user503821