• 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
AUAudioFilePlayer cheat sheet
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AUAudioFilePlayer cheat sheet


  • Subject: AUAudioFilePlayer cheat sheet
  • From: Doug Wyatt <email@hidden>
  • Date: Thu, 1 Dec 2005 15:36:54 -0800

It's come to my attention that some folks are having difficulty getting started with AUAudioFilePlayer ...
Here are some bits of code from a program that uses the AU.


To provide one file to play (you can/must give it all of the files from which you will schedule events):

AudioFileID mAudioFile;

UInt32 size;
require_noerr(err = AudioFileOpen(&fsref, fsRdPerm, 0, &mAudioFile), Bail);

size = sizeof(mFileDataFormat);
require_noerr(err = AudioFileGetProperty(mAudioFile, kAudioFilePropertyDataFormat, &size, &mFileDataFormat), Bail);

err = [self _buildGraph]; // here it's simplest to set the file player's output format to be
// canonical float 32, with the file's sample rate and channel count
if (err) goto Bail;

// give the file to the player
require_noerr(err = AudioUnitSetProperty(mFilePlayerAU, kAudioUnitProperty_ScheduledFileIDs, kAudioUnitScope_Global, 0, &mAudioFile, sizeof(mAudioFile)), Bail);



To start playback:

ScheduledAudioFileRegion playRegion;
playRegion.mTimeStamp.mFlags = kAudioTimeStampSampleTimeValid;
playRegion.mTimeStamp.mSampleTime = 0;
playRegion.mCompletionProc = NULL;
playRegion.mCompletionProcUserData = NULL;
playRegion.mAudioFile = mAudioFile;
playRegion.mLoopCount = 0;
playRegion.mStartFrame = mStartSampleFrame;
playRegion.mFramesToPlay = UInt32(-1);
require_noerr(err = AudioUnitSetProperty(mFilePlayerAU, kAudioUnitProperty_ScheduledFileRegion, kAudioUnitScope_Global, 0, &playRegion, sizeof(playRegion)), Bail);


// prime
UInt32 primeFrames = 0; // default
require_noerr(err = AudioUnitSetProperty(mFilePlayerAU, kAudioUnitProperty_ScheduledFilePrime, kAudioUnitScope_Global, 0, &primeFrames, sizeof(primeFrames)), Bail);

// set start time (on next render cycle)
AudioTimeStamp startTime;
startTime.mFlags = kAudioTimeStampSampleTimeValid;
startTime.mSampleTime = -1;
require_noerr(err = AudioUnitSetProperty(mFilePlayerAU, kAudioUnitProperty_ScheduleStartTimeStamp, kAudioUnitScope_Global, 0, &startTime, sizeof(startTime)), Bail);



To obtain the play position relative to the start point, in samples:

AudioTimeStamp ts;
UInt32 size = sizeof(ts);
AudioUnitGetProperty(mFilePlayerAU, kAudioUnitProperty_CurrentPlayTime, kAudioUnitScope_Global, 0, &ts, &size);
Float64 sampleFrame = ts.mSampleTime;


To stop:

	AudioUnitReset(mFilePlayerAU, kAudioUnitScope_Global, 0);

This is all described in AudioUnitProperties.h, although I admit that it is made a little harder to follow because some of these properties come from AUScheduledSoundPlayer, of which AUAudioFilePlayer is a specialization.

Doug

--
Doug Wyatt
Core Audio, Apple

_______________________________________________
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: 
 >Re: Endian stuff was: Re: SPDIF encoded output on G5 (From: Urs Heckmann <email@hidden>)
 >QT and CM versions (From: Lubor Prikryl <email@hidden>)
 >Re: QT and CM versions (From: William Stewart <email@hidden>)
 >Re: QT and CM versions (From: Lubor Prikryl <email@hidden>)
 >Re: QT and CM versions (From: William Stewart <email@hidden>)

  • Prev by Date: Re: AudioDriver to User Application
  • Next by Date: About USB Audio Device's Volume
  • Previous by thread: Re: QT and CM versions
  • Next by thread: Re: Endian stuff was: Re: SPDIF encoded output on G5
  • Index(es):
    • Date
    • Thread