[alsa-devel] hardware not asking for more data using asyn call back

stan stanl at cox.net
Tue May 29 22:20:32 CEST 2007


On Tue, 29 May 2007 15:19:12 -0400
"Ashlesha Shintre" <ashlesha.shintre at gmail.com> wrote:

> Hi,
> 
> Thanks Stan, for your response - Instead of copying pcm data from a
> wav file, i decided to copy all the data to a master buffer first and
> then see if the circular buffer implementation works -
> 
Not really necessary to use an intermediate buffer, but won't hurt.
I'm not sure why you are using a circular buffer, though it shouldn't
hurt either.

> so now instead of copying from the wave file, i m copying data from
> the master buffer to the circular buffer.. however, as per your
> suggestion, if i copy the data in the while loop in main, then, it
> might not always be copied between 2 consecutive callbacks, but maybe
> more, as the callbacks are asynchronous.

Well, your computer is creating the data that the callback function is
going to send to alsa.  If the callback function can fill the buffer
and send it to alsa and keep up with the play rate, then if you fill
the buffer in your main routine it will work even better.  Your program
is sleeping instead of doing anything.  You can put in place some kind
of interprocess communication so that they don't tread on each other in
the buffer.  With any modern processor that isn't heavily loaded, I
don't think this will matter anyway.

> 
> however, the hardware still does not ask for more data after
> executing the callback function about twice -- is there a way to
> flush the hardware buffer before beginning playback? I have pasted my
> code below
> 

The program output would still be helpful.  I implemented this a few
years ago.  I'll go look at the code and see how it differs from
yours.  I seem to recall that there was a sample of exactly this on the
alsa website, www.alsa-project.org.  You could look at that and it
might trigger an Aha! moment.

> Regards,
> Ashlesha.



More information about the Alsa-devel mailing list