• 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: Getting Audio Stream/File info
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting Audio Stream/File info


  • Subject: Re: Getting Audio Stream/File info
  • From: Jens Alfke <email@hidden>
  • Date: Fri, 13 Feb 2009 14:22:08 -0800


On Feb 13, 2009, at 7:33 AM, Jarek M wrote:

1) time in seconds since audio playing began

This is hard to get, if you need precision. I struggled with this for a while last year, as you can infer from my tone of voice in the comments below. (Check the list archives from last April/May.) Here's the code I ended up with, which still isn't perfect. If anyone has a better approach, please please tell me.


AudioTimeStamp AudioPlayerState::getCurrentTime()
{
AudioTimeStamp t;
Boolean discontinuity;
OSStatus err = AudioQueueGetCurrentTime(mQueue,mTimeline,&t,&discontinuity);
if( err==noErr ) {
// t.mSampleTime is totally fucking useless. Contrary to docs, it's in _device_ samples,
// not queue samples, and resets to an arbitrary negative number when the audio hardware
// configuration changes (like when plugging in headphones on a MacBook.)
// Therefore, after wasting entire days trying to figure it out, I've decided to ignore
// it entirely and synthesize my own accurate value based on host time.
Float64 seconds = secondsFromTimeStamp(&t);
if( seconds > 0 ) {
if( mStartTime==0 ) {
//FIX: This still doesn't work right because t.mSampleTime is often way off even on the
// first callback (if this is not the first track being played.)--jpa 5/2008
mStartTime = seconds - t.mSampleTime/this- >getDeviceSampleRate();
} else {
// Recompute the sample time based on the start time:
Float64 sampleTime = round((seconds-mStartTime) * mDataFormat.mSampleRate);
t.mSampleTime = sampleTime;
}
}
} else {
t.mSampleTime = 0;
t.mHostTime = 0;
}
return t;
}



3) Duration of the stream being played (if exists, it may be a continuous stream)
2) sampling rate of the stream being played
3) bitrate of the stream being played ( this may vary in VBR, I understand)

You can get all of these from the properties of the ExtAudioFile that you're reading the data from. One warning: determining the duration (packet count) of an MP3 file may require scanning through the entire file, so it can potentially take on the order of seconds.


—Jens _______________________________________________
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


References: 
 >Getting Audio Stream/File info (From: Jarek M <email@hidden>)

  • Prev by Date: Re: Trimming audio
  • Next by Date: Re: high-performance iphone and 8.24: convert to float and back or fixed-point math?
  • Previous by thread: Getting Audio Stream/File info
  • Next by thread: Re: Getting Audio Stream/File info
  • Index(es):
    • Date
    • Thread