On Oct 3, 2008, at 11:02 PM, Xu Ting wrote: Hi, bill, Thank you for your kindness reply, but I still not quite understand Audio Queue. Hi, Craig,
I think with your help, I had figured out how to perform fast forward and rewind, but I still have some questions about some details. Q1. When I specify a packet index to be read, should I clean the buffer?
Don't have to - audio file is going to write into that buffer If I don't clear the buffer, after I set the next packet index to be read, the original buffer data will be played, am I right?
I think what you want to do is something like this:
read data and schedule AudioQueueFlush skip to the next bit of the file - read the tiny bit that you want to play as a part of your skipping and schedule it to the queue, AudioQueueFlush
You can reset, but that will discard everything that hasn't been played when you call it, whereas Flush will playout everything you have scheduled. You might want to experiment with these both to see what gives you the best behaviour I have watched the iPod app on iPhone, and it does not have any latency when I push the fast forward button or rewind button. So, if I do not clear the buffer, how could I guarantee I can play the next audio data as soon as possible?
If so, how should I do? I had tried free buffer and refill the buffer from the packet index, but it did not work correctly.
there must be a bug in your code - the audio file is reading the file based on the information you are providing it - whether you are reading "sequentially" or from some arbitrary spot in the file should not mean anything to the file object.
Yes, I had finally figured it out. Now, no matter what packet index I set to the audio file, it will read the correct data. Thank you. Q2. After I clicked the fast forward button or rewind button, I found out that the AudioQueueGetCurrentTime doesn't work as I expected. How should I get the correct time? Should I calculate the time by current packet index? If so, I can not get the correct packet index which is currently playing. How should I get the correct packet index?
the queue has no notion of where in a file you are providing data. it is providing you with a time since you started playing - but has no idea about what that means from your point of view as the data provider.
so the way you need to do this is to associate the buffers you enqueue with a time in the aq timeline (so you know when that buffer is going to be played). then, based on what "time in the file" a given buffer represents, you can then find out where in your timeline, the "current time" of the queue corresponds too.
I am not quite understand you here. Did you mean, I need to create an AudioTimeStamp object(For example aTimeStamp) by using AudioQueueCreateTimeline, and then using the AudioQueueEnqueueBufferWithParameters, and pass the aTimeStamp object to it?
Yes, you can schedule a buffer that you are providing to the audio queue to play at some time in the queue's time - that is what you would use that for. But this has no relationship to the file - it is just saying:
This buffer should be played at sample 50.
If the queue is already at sample 60 it will discard (not play) the first 10 samples of that buffer) If the queue is at sample 40, it will schedule your buffer to start playing when it gets to sample 50.
I've copied Murray who wrote the reference doc for CoreAudio, so he can jump in and help to explain this
Bill Actually, here is most hard to understand part for me, as I reading the Aduio Queue Service Reference. I had checked these functions one by one, I don't think what I said above is correct. So, bill, could you give me a right way? If it is possible, I want to know the exact function name. Maybe there is some misunderstanding when I read the reference. But I really stucked in this problem for too many days... Thank you, Best Regards,
-Tonny
-- Life is like a box of chocolates, u never know what u'r gonna get.
|