On Tue, 20 Jan 2004, Michel Dänzer wrote:

> On Tue, 2004-01-20 at 17:06, Michel Dänzer wrote:
> > On Tue, 2004-01-20 at 16:29, Jaroslav Kysela wrote:
> > > On Tue, 20 Jan 2004, Michel Dänzer wrote:
> > > 
> > > Could you try the attached patch? If you add a line 'slowptr yes' to your 
> > > dmix pcm definition, the snd_pcm_delay() function should be more precise.
> > 
> > It seems to work perfectly, thank you very much!
> 
> I have to take that back. :(
> 
> I had put the slowptr in the wrong place (in the dmixer slave pcm
> block), and xine silently fell back to using /dev/dsp (alsa-oss doesn't
> seem to work with it). With the slowptr in the right place, I have now
> verified that xine uses ALSA with it enabled, but it doesn't seem to
> enhance sound quality much if at all.
> 
> Sorry for the false confirmation. Any other ideas?

Yes, I've tested xine with dmix today and I figured after several hours of 
looking for totaly another problem, that it was 'snd_pcm_wait()' function 
which causes trouble in conjunction with the xine ALSA code algorithm.

The result patch (attached to this mail and available also in CVS) is that
xine works with dmix even without the slowptr option! So there is no 
reason to make this option as default.

I'm happy that the next direct plugin related bug is solved.

                                                Jaroslav

-----
Jaroslav Kysela <[EMAIL PROTECTED]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
? a
? out.txt
? pcm.c.engine
Index: pcm_direct.c
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/src/pcm/pcm_direct.c,v
retrieving revision 1.11
diff -u -r1.11 pcm_direct.c
--- pcm_direct.c        9 Jan 2004 18:32:05 -0000       1.11
+++ pcm_direct.c        21 Jan 2004 19:18:06 -0000
@@ -410,15 +410,23 @@
 {
        snd_pcm_direct_t *dmix = pcm->private_data;
        unsigned short events;
-       static snd_timer_read_t rbuf[5];        /* can be overwriten by multiple 
plugins, we don't need the value */
+       /* rbuf might be overwriten by multiple plugins */
+       /* we don't need the value */
+       static snd_timer_read_t rbuf[5];
 
        assert(pfds && nfds == 1 && revents);
        events = pfds[0].revents;
        if (events & POLLIN) {
-               events |= POLLOUT;
-               events &= ~POLLIN;
+               int empty = 0;
+               if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
+                       events |= POLLOUT;
+                       events &= ~POLLIN;
+                       empty = snd_pcm_mmap_playback_avail(pcm) < pcm->avail_min;
+               } else {
+                       empty = snd_pcm_mmap_capture_avail(pcm) < pcm->avail_min;
+               }
                /* empty the timer read queue */
-               while (snd_timer_read(dmix->timer, &rbuf, sizeof(rbuf)) == 
sizeof(rbuf)) ;
+               while (empty && snd_timer_read(dmix->timer, &rbuf, sizeof(rbuf)) == 
sizeof(rbuf)) ;
        }
        *revents = events;
        return 0;
Index: pcm_dmix.c
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/src/pcm/pcm_dmix.c,v
retrieving revision 1.47
diff -u -r1.47 pcm_dmix.c
--- pcm_dmix.c  20 Jan 2004 15:29:39 -0000      1.47
+++ pcm_dmix.c  21 Jan 2004 19:18:07 -0000
@@ -407,7 +407,6 @@
        }
        dmix->hw_ptr += diff;
        dmix->hw_ptr %= pcm->boundary;
-       // printf("sync ptr diff = %li\n", diff);
        if (pcm->stop_threshold >= pcm->boundary)       /* don't care */
                return 0;
        if ((avail = snd_pcm_mmap_playback_avail(pcm)) >= pcm->stop_threshold) {
@@ -545,6 +544,7 @@
        if (err < 0)
                return err;
        dmix->state = SND_PCM_STATE_RUNNING;
+       snd_pcm_hwsync(dmix->spcm);
        dmix->slave_appl_ptr = dmix->slave_hw_ptr = *dmix->spcm->hw.ptr;
        avail = snd_pcm_mmap_playback_hw_avail(pcm);
        if (avail < 0)
Index: pcm_dshare.c
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/src/pcm/pcm_dshare.c,v
retrieving revision 1.13
diff -u -r1.13 pcm_dshare.c
--- pcm_dshare.c        20 Jan 2004 15:29:39 -0000      1.13
+++ pcm_dshare.c        21 Jan 2004 19:18:07 -0000
@@ -292,6 +292,7 @@
        if (err < 0)
                return err;
        dshare->state = SND_PCM_STATE_RUNNING;
+       snd_pcm_hwsync(dshare->spcm);
        dshare->slave_appl_ptr = dshare->slave_hw_ptr = *dshare->spcm->hw.ptr;
        avail = snd_pcm_mmap_playback_hw_avail(pcm);
        if (avail < 0)
Index: pcm_dsnoop.c
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/src/pcm/pcm_dsnoop.c,v
retrieving revision 1.13
diff -u -r1.13 pcm_dsnoop.c
--- pcm_dsnoop.c        20 Jan 2004 15:29:39 -0000      1.13
+++ pcm_dsnoop.c        21 Jan 2004 19:18:07 -0000
@@ -274,6 +274,7 @@
        if (err < 0)
                return err;
        dsnoop->state = SND_PCM_STATE_RUNNING;
+       snd_pcm_hwsync(dsnoop->spcm);
        dsnoop->slave_appl_ptr = dsnoop->slave_hw_ptr = *dsnoop->spcm->hw.ptr;
        gettimeofday(&tv, 0);
        dsnoop->trigger_tstamp.tv_sec = tv.tv_sec;

Reply via email to