views:

52

answers:

1

Hey everyone, I was wondering if someone could point me in the right direction to creating a function in my openAL singleton class that returns the current time of the sound.

Any Ideas? Thanks!

(Current time 'while the sound is playing')

+1  A: 

Hi can you elaborate in what you mean by the current time of the sound?

do you mean what the actually time is when the sound is played or how long the actual length of time is of the audio clip? please specify.

  1. If you mean when the actual time the sound was played then you can use

    CFAbsoluteTimeGetCurrent()

    to get the current time expressed as the number of seconds (as a double value, so fractional seconds will be there) since January 1, 2001 00:00:00 GMT. so basically what you will get is the current time the moment the function is called.

  2. if you would like to know when an event occurred within your application then you can use the

    -[UIEvent timestamp]

    property which will be the most accurate representation of when the sound played.

To put either of those functions which ever you decide to choose (if its actually what you are talking about) then you return it like so:

(double)returnTime{
    double *timeValue = CFAbsoluteTimeGetCurrent();
    return timeValue;
}

And then you can call this function and store the time like so

double *storeValue = [self returnTime];

in one go. You can then use this variable to print it to the console or what ever you like.

Hope this helps. Again please specify what you meant by the current time of the sound.

Pk

Pavan
Those are both really useful! I actually am shooting at a 'current time while the sound is playing' type thing. I want to be able to compare which sound is closest to complete.
XenElement
I'm glad that this will be of use to you. If you need any more help do let me know.
Pavan
please mark this post as answered. thank you
Pavan