Juergen Keil wrote:
> For audio_out using "Sun style audio ioctls", you can find out how much
> data is waiting in the sound device's internal buffers by comparing the
> number of audio "samples" sent to the device with the number of
> "samples" played by the device. The later is return in the
> "info.play.samples" field, returned for the AUDIO_GETINFO ioctl and is
> a counter maintained by the sound card driver. There is no guarantee
> that the hardware's sample counter returned in the AUDIO_GETINFO
> ioctl is able to count "individual" samples; it may count samples in
> bigger "chunks", whenever the hardware interrupts and signals that it has
> finished playing a chunk of data.
There's something else you can do to, namely, periodically write "marks"
to the audio stream, at which point the play.eof count will be updated as
these marks are passed in the stream. Just do a zero length write to the
audio file descriptor where you wish to set a mark, then wait for eof to
increment and you know it's been passed. Note, though, that you need to be
careful not to do a zero length write to the audio buffer when it's empty
or it will hang (or at least that's my recollection; This is all collected
research from when I was implementing the Linux sparcaudio driver) but you
can avoid this by doing e.g.
fcntl(fd, F_SETFL, O_NONBLOCK);
write(fd, buf, 0);
fcntl(fd, F_SETFL, 0);
As I haven't been carefully following the changes (and have only been
doing so silently anyway) I don't know if this is helpful but I figured I
should share in case it is.