Re: Trouble with AudioDeviceGetCurrentTime....
Re: Trouble with AudioDeviceGetCurrentTime....
- Subject: Re: Trouble with AudioDeviceGetCurrentTime....
- From: Brian Kelly <email@hidden>
- Date: Mon, 29 Nov 2004 08:32:12 -0800
Hi All,
I need to get the number of bytes processed, and would like to use
the AudioDeviceGetCurrentTime() function to do it. I'm having
trouble with it though. If I comment out the call to
AudioDeviceGetCurrentTime() below, it works.
<snip>
long audio_device_processed_bytes(void)
{
struct timeval this;
static long multiplier = 176;
AudioTimeStamp* this_time;
OSStatus err;
UInt32 num_processes;
UInt32 count;
gettimeofday(&this, &tz);
/*if (multiplier == 0)
{
multiplier = audio_data.sfinfo.samplerate*FRAMESIZE;
}*/
printf("This time is: %ld\n", (long)(1000*this.tv_sec +
this.tv_usec/1000.));
playback_position =
multiplier*((this.tv_sec -
playback_start_time.tv_sec)*1000 + (this.tv_usec -
playback_start_time.
tv_usec) / 1000);//Have to scale it this way so the longs
don't overflow.
printf("play_back_position from gettimeofday is:
%ld\n",playback_position);
//usleep(1000);
count = sizeof(UInt32);
if ((err = AudioDeviceGetProperty (audio_data.device,
0, false, kAudioDevicePropertyDeviceIsRunning,
&count, &num_processes)) != noErr)
{ printf ("AudioDeviceGetProperty
(AudioDeviceGetProperty) failed. The device probably isn't
running.\n") ;
return -1;
}
else
{
printf("num_processes is: %ld\n",num_processes);
if((err =
AudioDeviceGetCurrentTime(audio_data.device, this_time)) != noErr)
{
printf("Could not get the current
time. The error number is: %ld \n",err);
//return playback_position;
}
else
{
printf("this_time - start_sample_time
= %ld\n",(long) (this_time->mSampleTime - start_sample_time));
}
//playback_position = (long)
(this_time->mSampleTime - start_sample_time);
}
return playback_position;
} // This is used to set the cursor. We need to make this return a
number controlled by a timer.
--
Your this_time variable is a pointer to an AudioTimeStamp, but you
never allocate the struct.
Does AudioDeviceGetCurrentTime allocate it for you?
Otherwise you're trampling memory, which is never good.
Cheers,
Brian
_______________________________________________
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