Synchronizing with the PCM subchannel

QSA provides some basic synchronization capabilities.

Your application can find out where in the stream the hardware play position is. The resolution of this position is entirely a function of the hardware driver; consult the specific device driver documentation for details if this is important to your application.

The API calls to get this information are:

Both of these functions fill in a snd_pcm_channel_status_t structure. You'll need to check the following members of this structure:

scount
The hardware play position, in bytes relative to the start of the stream since the last time the channel was prepared. The act of preparing a channel resets this count.
count
The play position, in bytes relative to the total number of bytes written to the device.
Note: The count member isn't used if the mmap plugin is used. The mmap plugin is disabled by default, but if you have it enabled, you can call snd_pcm_plugin_set_disable() to disable the mmap plugin.

For example, consider a stream where 1,000,000 bytes have been written to the device. If the status call sets scount to 999,000 and count to 1000, there are 1000 bytes of data in the buffer remaining to be played, and 999,000 bytes of the stream have already been played.