Re: Getting and setting the play time on a DefaultOutputUnit
Re: Getting and setting the play time on a DefaultOutputUnit
- Subject: Re: Getting and setting the play time on a DefaultOutputUnit
- From: tahome izwah <email@hidden>
- Date: Fri, 06 May 2011 23:26:14 +0200
I'm not sure I understand the question. If you want to play from a
certain position in your file why don't you seek to that position and
play from there? ExtAudioFile has a seek call. This has nothing to do
with the AudioUnit's current play time, IMHO.
HTH
--th
2011/5/6 patrick machielse <email@hidden>:
> Hi,
>
> In my program I want to down-mix n files, adjusting the playback speed for each file. To this end I've set up an AUGraph with Varispeed units for each audio file, leading into an single AUMixer to join the audio streams, and ending in a DefaultOutputUnit to play the audio through the default device. Playing and mixing works.
>
> I have been using CoreAudio / AudioUnits for a number of years. However, now I want to get the current play time from the DefaultOutputUnit and set it too, so the user can jump around in the mix. Here I hit the (by now familiar) AU 'brick wall'; I cannot locate a property to get or set the play time on DefaultOutputUnit (there is no kAudioUnitProperty_CurrentPlayTime for DefaultOutputUnit?).
>
> The scant documentation and sample code on DefaultOutputUnit don't cover this either. I _think_ DefaultOutputUnit is the correct unit to use, as I'm not playing files directly (reading is handed off to ExtAudioFiles because it will have to work in offline mode too).
>
> In my audio processing class I tried things like this:
>
> ** To get the play time:
>
> - (NSTimeInterval)playbackTime;
> {
> AudioUnit outputUnit = ...;
>
> AudioDeviceID deviceID;
> UInt32 size;
> result = AudioUnitGetProperty(outputUnit,
> kAudioOutputUnitProperty_CurrentDevice,
> kAudioUnitScope_Global,
> 0,
> &deviceID,
> &size);
> if ( result ) {
> NSLog(@"could not get current device ID from default output unit (%ld)", (long)result);
> return 0.0;
> }
> NSLog(@"deviceID = %u", deviceID);
>
> AudioTimeStamp timestamp = (AudioTimeStamp) { 0, kAudioTimeStampSampleTimeValid };
> OSStatus error = AudioDeviceGetCurrentTime(deviceID, ×tamp);
> if ( error ) {
> NSLog(@"could not get audio device current time (%@)", NSFileTypeForHFSTypeCode(error));
> return 0.0;
> }
> return timestamp.mSampleTime / 44100;
> }
>
> Here I get a deviceID, but AudioDeviceGetCurrentTime() returns '!dev'.
>
>
> ** To set the play time:
>
> - (void)setPlaybackTime:(NSTimeInterval)time
> {
> AudioUnit outputUnit = ...;
>
> BOOL restart = self.isPlaying;
> if ( restart ) AudioOutputUnitStop(outputUnit);
>
> AudioTimeStamp timestamp = (AudioTimeStamp) { time * 44100, kAudioTimeStampSampleTimeValid };
> AudioOutputUnitStartAtTimeParams timeParams = (AudioOutputUnitStartAtTimeParams) { timestamp, 0 };
> result = AudioUnitSetProperty(outputUnit,
> kAudioOutputUnitProperty_StartTime,
> kAudioUnitScope_Global,
> 0,
> &timeParams,
> sizeof timeParams);
> if ( result ) {
> NSLog(@"could not set start time on default output (%ld)", (long)result);
> }
>
> if ( restart ) AudioOutputUnitStart(outputUnit);
> }
>
> There is no error in this case, but playback doesn't restart. (I first tried controlling playback through the containing AUGraph with identical results).
>
> Can someone please guide me towards the light? How do I manipulate DefaultOutputUnit?
>
> Thanks,
>
> patrick
> --
> Patrick Machielse
> Hieper Software
>
> http://www.hieper.nl
> 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
>
_______________________________________________
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