At Wed, 27 Sep 2006 09:58:53 -0400, Lee Revell wrote: > > On Tue, 2006-09-19 at 17:15 +0200, Takashi Iwai wrote: > > The workq task is a pseudo-DMA engine that runs in background. > > When it's woken up, it feeds data from intermediate buffer to hardware > > as much as possible. The available data can be found in > > > > If all data are fed, it sleeps again (or exit > > the task). The timer wakes up or schedule the new workq task. > > I think something is missing - the available data can be found where? We track the following two pointers (assume the playback direction): - hw_ptr points the current transferring position in the ring buffer - appl_ptr points the current position the data is filled The available data size is calculated as (appl_ptr - hw_ptr). The appl_ptr is the data size given by the application, i.e. it's incremented at each time the app writes data chunk. So, the interest for the driver is basically only hw_ptr. The only access point that the driver provides hw_ptr is the pointer callback. It returns a value between 0 and buffer_size-1, and the PCM core layer expands to a linear position in 0 - pcm->boundary_size. In case the hardware doesn't provide the exact DMA position... it's a bit hard. If the hardware generates an irq at each period boundary, the driver simply updates the hw_ptr at each interrupt (before calling snd_pcm_period_elapsed()) such as hw_ptr += frames_per_period; hw_ptr %= buffer_size; then pass this value in pointer callback. If the hardware doesn't generate irq, we have to rely on the system timer just like your code. In that case, the driver must keep tracking the pointer by itself, such as frames_per_period = rate / HZ; frac_per_period = rate % HZ; hw_ptr += frames_per_period; frac += frac_per_period; if (frac >= HZ) { hw_ptr++; frac -= HZ; } hw_ptr %= buffer_size; Takashi ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Alsa-devel mailing list Alsa-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.sourceforge.net/lists/listinfo/alsa-devel