iphone - MP3 streaming on iOS -


I want to use the openale to play music in the iOS game. Music files are stored in MP3 format and I want to stream them using buffer queue. I load audio data in buffers using AudioFileReadPacketData () . However, the buffers game only gives me noise. It works perfectly for CAF files, but not for MP3. Do I miss some important steps in decoding the file?

I use the code to open the sound file:

  - (zero) openfile: (NSString *) fileName {NSBundle * bundle = [NSBindle main bundle]; Seafrrr url = (cfrrrf) [[NSUr file URLTHath Path: [Bundle PathFor Resource: Filename Type: @ "MP3"]] was retained; Audio file open URL (url, kAudioFileReadPermission, 0, and audiofile); Audiostream Basic Description Format; UInt32 format size = size form (format); AudioFileGuideProperty (audiofile, QDoFilepropertydataformat, and format size, and format); Freq = (ALsizei) theformat.mSampleRate; CFRelease (url); }  

The code I use to fill the buffers:

  - (zero) loadOneChunkIntoBuffer: (algorithm) buffer {char data [STREAM_BUFFER_SIZE]; UInt32 loadSize = STREAM_BUFFER_SIZE; AudioStream Packet Device Packet Disk [STREAM_PACKETS]; UInt32 numpackets = STREAM_PACKETS; AudioFileReadPacketData (audio file, no, and load size, packetdesk, packet loaded, and numpackets, data); Alfredadata (buffer, AL_FORMAT_STEREO16, data, load system, freak); Packet loaded = numpackets; }   

Because you are reading bytes of MP3 data and form them in the form of PCM data Are treated in.

You almost certainly AudioFileReadPacketData () . wants to edit: except that still gives you MP3 data; It just gives in packets and (possibly) purse packet header.

If you do not need OpenGL, AVAudioPlayer is probably the best way to go (according to this, audio queue services are also if you want more control).

If you really need to use OpenAL, you will need to convert it to PCM in the original byte sequence. For an example of using an extended audio file service to do this, see. Note that the TN2199 format should not use "hardware decontr ... ..." - According to the multimedia programming guide, software decoding is supported for everything except the O-AAC after OS 3.0. Also keep in mind that the software can use MP3 encoding a significant amount of CPU time.

Alternatively, use audio converter or audio (probably) using audio aunet to explicitly convert the audio with QDOINITSUBTep_Aquoconwer. If you do this, then it is advisable to break it once and keep it in memory to reduce the overhead.


Comments