• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to find loop length of MP3
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to find loop length of MP3


  • Subject: Re: How to find loop length of MP3
  • From: "Stephen F. Booth" <email@hidden>
  • Date: Mon, 8 Nov 2010 20:04:40 -0800

Hi Kevin,

You may or not may be able to accurately determine how many audio frames are in an MP3.  If the encoder wrote a proper Xing/Info/LAME header you're in luck.  If it didn't, well, you would have to guesstimate.

The definition of the Info header is on http://gabriel.mp3-tech.org/mp3infotag.html

I've written code using MAD to decode MP3s, including parsing the Xing/Info header: https://github.com/sbooth/SFBAudioEngine/blob/master/Decoders/MPEGDecoder.cpp

I assume you could use AudioFile to read a single MPEG frame (packet) and pull the Info header from that, but I've never tried.

Stephen

On Mon, Nov 8, 2010 at 7:36 PM, Kevin Boyce <email@hidden> wrote:
I'm trying to stay in sync with looped playback, and having the devil of a time.  I'm using AudioFile (with a dash of ExtAudioFile), and have no problem scheduling a section of a file for playback and using the pre-render callback to update the current playback time in samples as inTimeStamp->mSampleTime - startTime, where I set startTime on the first pre-render callback.

So now I want to start the "current time" over at zero each time the playback loops back to the beginning of the scheduled region.  It should be simple, just increment startTime by loopSamples each time the playback time goes larger than loopSamples.  I calculate loopSamples from the file duration when I schedule the file. If I have scheduled a portion of the file, it all works fine.  However, if I try to use the total duration of the file, it often goes out of sync by something like 1000 samples each time around the loop (for an MP3 file).  Here's the code I use to find the length:

propsize = sizeof( fileFrames );
err = ExtAudioFileGetProperty( myExtAudioFile, kExtAudioFileProperty_FileLengthFrames, &propsize, &fileFrames );
fileDuration = fileFrames / fileFormat.mSampleRate;

where I got fileFormat earlier, from the underlying AudioFile.

This error sounds suspiciously like a number of priming samples, so I think I'm asking for a longer loop than the file really has.  And indeed, my length is longer than what Amadeus II reports.   So I thought I would try reading kExtAudioFileProperty_FileLengthFrames and just using mNumberValidFrames.  But no, that property is not defined for MP3s.

I tried using the kAudioFilePropertyEstimatedDuration property, but that gives wildly incorrect numbers, like a 1.3 second file is reported as 1.000 (I checked with afinfo and it also gives the incorrect answer).  Apparently the estimate is very approximate.

So, is there some way I can find out the real duration of an MP3 file (among others)?  Or alternatively a way to find out what the real loop length is after I schedule it?  (I tried reading back the kAudioUnitProperty_ScheduledFileRegion property, but it reports the same mFramesToPlay as I asked for.)

Thanks,
Kevin

 _______________________________________________
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

 _______________________________________________
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

  • Follow-Ups:
    • Re: How to find loop length of MP3
      • From: Kevin Boyce <email@hidden>
References: 
 >How to find loop length of MP3 (From: Kevin Boyce <email@hidden>)

  • Prev by Date: How to find loop length of MP3
  • Next by Date: Re: CoreAudio playback issue
  • Previous by thread: How to find loop length of MP3
  • Next by thread: Re: How to find loop length of MP3
  • Index(es):
    • Date
    • Thread