Re: Loop Audio on iPhone
Re: Loop Audio on iPhone
- Subject: Re: Loop Audio on iPhone
- From: Marco Papa <email@hidden>
- Date: Sat, 21 Feb 2009 20:14:47 -0800
On Thu, Feb 19, 2009 at 11:50 AM, Marco Papa
<email@hidden> wrote:
Date: Tue, 17 Feb 2009 14:46:07 -0800
From: William Stewart <email@hidden>
Subject: Re: Loop Audio on iPhone
To: Marco Papa <email@hidden>
Cc: email@hidden
Message-ID: <email@hidden" target="_blank">email@hidden>
Content-Type: text/plain; charset="us-ascii"
On Feb 17, 2009, at 2:31 PM, Marco Papa wrote:
> Bill,
>
> I did some more research. You say in your post below:
>
> "AudioQueue's buffer routines provide a trimming function for just
> this purpose. AVAudioPlayer uses these."
>
> I did the same exercise you mentioned below. I obtained a fairly
> long "uncompressed" WAV file. I played it using the "loop" function
> of AVAudioPlayer: the loop worked flawlessly.
>
> Then I encoded it with AAC and stored in a CAF file using afconvert,
> as suggested in your post below.
>
> I verified using afiinfo that the "priming frames" (2112) at the
> beginning and the "remainder frames" at the end are also stored in
> the CAF file.
>
> Then I tried to loop the CAF file using AudioQueuebuffer routines
> (using AudioFileGetProperty((audio_file,
> kAudioFilePropertyPacketTableInfo,... to get the priming and
> remainder frames totals ). This seems to also loop fine.
>
> Then I tried to loop the CAF file using AVAudioPlayer routines using
> the same code that loops fine with the uncompressed WAV file. This
> one did NOT loop fine and there is a very audible glitch.
>
> I tried both of the above using the iPhone Simulator - 2.2.1 (latest
> release). I haven't tried it an actual iPhone yet, but I would not
> expect it to be any different.
>
> Should I submit a bug report?
For sure (and if you can include your code that will be great) - I
would have expected this to work. Thanks
Bill
I did some more experimenting and I'm happy to report that the "looping glitch" bug present with AAC/CAF compressed files using AVAudioPlayer is NOT present when using IMA4/CAF compressed files.
The only difference that I could see is the fact that AAC/CAF files have 2112 priming frames, while IMA4/CAF files have 0 priming frames. as produced by afconvert. Both formats have remainder frames.
You can use afconvert as in:
afconvert -f caff -d ima4 audiofiile.wav
to do the conversion.
IMA4 files are not as "compressed" as AAC files (on the average they are 3 times bigger), but you still get a compressed file that is 1/4 of the size of the original WAV uncompressed file.
Well, I did some more experimenting, and I'm now able to compress and generate MP3 loops and play them using AVAudioPlayer, despite the bug in its handling of priming and remainder frames.
The solution was recommended to me by Canis, Lead Developer at Wooji Juice, the publisher of Stage Hands for the iPhone. The details are available in the article "Gapless looping MP3 tracks" available at this site:
http://www.compuphase.com/mp3/mp3loops.htm
Quoting from the article:
"To make the MP3 clip loopable, you need an additional utility, mp3loop, that prepares the WAV file prior to encoding and postprocesses the file afterwards. This second utility "folds around" the encoder: it does something to the input file before the encoder transforms it to an MP3 file and it does something to the result after the encoder has completed running."
Unfortunately this tool is available only as a MS-DOS program, so I fired up VMWare and there I went. The tool needs an MP3 encoder, and has presets for LAME, so I downloaded the LAME 3.98.2 encoder from free-codecs.com:
The resulting MP3 file does not need to be embedded in an CAF envelope. It just loops with no additional info needed by AVAudioPlayer.
The difference in size is HUGE in an environment like the iPhone. In my case, this is the comparison:
Original looping WAV: 2.4MB
looping IMA4-CAF: 658KB
looping MP3: 384KB
--
Marco Papa, Ph.D.
Computer Science Department
University of Southern California
Henry Salvatori Computer Center
Los Angeles, California 90089-0781
Voice: +1-213-974-2137
Cell: +1-310-944-5468
E-mail:
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden