Bug 29709

Summary: last sound driver MFC introduced problems with various applications
Product: Base System Reporter: Andre Albsmeier <Andre.Albsmeier>
Component: kernAssignee: sound
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.4-PRERELEASE   
Hardware: Any   
OS: Any   

Description Andre Albsmeier 2001-08-14 13:00:16 UTC
Since the pcm MFC on August 1st various applications have problems.
Here is a summary of the observations taken from -multimedia:

pcm0: <SB16 DSP 4.16> at io 0x220 irq 5 drq 1:5 (1p/1r/0v channels duplex)
  - mtv (linux) audio doesn't work, the console says:
    pcm0: play interrupt timeout, channel dead
  - in mxaudio the progress slider runs like hell; a 4 minute
    song is processed in 4 seconds. No audio appears..
  - sox produces a short blip as though the sample is playing too fast
  - mpg123 works!

pcm0: <Aureal Vortex 8820> at memory 0xf4000000 irq 10 (4p/1r/0v channels duplex)
  - same with mtv

I assume the list isn't complete; it just lists the problems seen
until now.

Fix: 

I replaced /sys/dev/sound completely with the version before august 1st
and created empty pci/ich.c, pcm/vchan.c, pcm/sndstat.c and pcm/feeder_rate.c
files so I didn't have to mess around with sys/conf/files :-)
How-To-Repeat: 
Update to a recent 4.4-PRERELEASE and try some of the above combinations.
Comment 1 greid freebsd_committer freebsd_triage 2001-08-14 16:07:35 UTC
Responsible Changed
From-To: freebsd-bugs->sound

Sound issue
Comment 2 gandalf 2001-08-14 17:29:22 UTC
>pcm0: <SB16 DSP 4.16> at io 0x220 irq 5 drq 1:5 (1p/1r/0v channels duplex)
>  - mtv (linux) audio doesn't work, the console says:
>    pcm0: play interrupt timeout, channel dead
>  - in mxaudio the progress slider runs like hell; a 4 minute
>    song is processed in 4 seconds. No audio appears..

these are both consistent with the channel not starting.  does 'systat -vm'
indicate interrupts happening on irq5 while playing?

>  - sox produces a short blip as though the sample is playing too fast

is the length of the blip proportional to the length of the sample?

        -cg
Comment 3 Ted Faber 2001-08-14 18:29:56 UTC
>> - sox produces a short blip as though the sample is playing too fast
> 
>is the length of the blip proportional to the length of the sample?

Yes, roughly.

FYI, xmcd works fine, too.
Comment 4 Andre Albsmeier 2001-08-14 18:57:29 UTC
On Tue, 14-Aug-2001 at 17:29:22 +0100, Cameron Grant wrote:
> >pcm0: <SB16 DSP 4.16> at io 0x220 irq 5 drq 1:5 (1p/1r/0v channels duplex)
> >  - mtv (linux) audio doesn't work, the console says:
> >    pcm0: play interrupt timeout, channel dead
> >  - in mxaudio the progress slider runs like hell; a 4 minute
> >    song is processed in 4 seconds. No audio appears..
> 
> these are both consistent with the channel not starting.  does 'systat -vm'
> indicate interrupts happening on irq5 while playing?

No. The 'sbc0 irq5' output of 'systat -vm' didn't even appear when
I first started mtv. Then I launched mpg123 and sound could be
heard and I got about 86 irqs. Then I started mtv and fired
systat -vm  again. Now the 'sbc0 irq5' output was available
but no irqs were shown:

    8 users    Load  0.16  0.20  0.15                  Tue Aug 14 19:47

Mem:KB    REAL            VIRTUAL                     VN PAGER  SWAP PAGER
        Tot   Share      Tot    Share    Free         in  out     in  out
Act   25072    3548    49048     5308   75172 count
All  450324   13444  2937476    26224         pages
                                                          zfod   Interrupts
Proc:r  p  d  s  w    Csw  Trp  Sys  Int  Sof  Flt        cow     269 total
     3     1 21       522  200 1785  269  216    1  80204 wire        intpm0 irq
                                                    62944 act         ahc0 irq14
 1.7%Sys   0.0%Intr 21.8%User  0.0%Nice 76.4%Idl   294316 inact     8 mux irq15
|    |    |    |    |    |    |    |    |    |      12860 cache       ahc1 irq10
=>>>>>>>>>>>                                        62312 free      7 atkbd0 irq
                                                          daefr    26 psm0 irq12
Namei         Name-cache    Dir-cache                     prcfr       fdc0 irq6
    Calls     hits    %     hits    %                     react       ppc0 irq7
                                                          pdwak       sbc0 irq5
                                                          pdpgs   100 clk irq0
Disks  ccd0   da0   da1   da2   da3   da4  da10           intrn   128 rtc irq8
KB/t   0.00  0.00  8.00  0.00  0.00  0.00  0.00     62048 buf
tps       0     0     0     0     0     0     0         4 dirtybuf
MB/s   0.00  0.00  0.00  0.00  0.00  0.00  0.00     32315 desiredvnodes
% busy    0     0     0     0     0     0     0     13095 numvnodes
                                                       26 freevnodes


Here is the contents of the pop up windows that appears shortly
after starting mtv:

Warning!
Cannot play audio: Invalid argument (muting)
With GNOME, use "esddsp mtv". Use option -aw to debug.


I tried the -aw option. Here the the part that seems interesting:
(I can send the whole log file which is about 36 KB...)

[4442,1026] mtvp: audio: audiolib.c:2657: t=997811378.6596: looking for next audio syncword
[4442,1026] mtvp: audio: audiolib.c:2664: t=997811378.6596: found audio syncword
[4442,1026] mtvp: audio: audioioctl.c:1106: t=997811378.6597: writing 4608 bytes to device
[4442,1026] mtvp: audio: audioioctl.c:1138: t=997811378.6597: 4608 bytes written
[4442,1026] mtvp: audio: audiolib.c:2657: t=997811378.6602: looking for next audio syncword
[4442,1026] mtvp: audio: audiolib.c:2664: t=997811378.6604: found audio syncword
[4442,1026] mtvp: audio: audioioctl.c:1106: t=997811378.6604: writing 4608 bytes to device
[4442,1026] mtvp: audio: audioioctl.c:1138: t=997811378.6604: 4608 bytes written
[4442,1026] mtvp: audio: audiolib.c:2657: t=997811378.6610: looking for next audio syncword
[4442,1026] mtvp: audio: audiolib.c:2664: t=997811378.6610: found audio syncword
[4442,1026] mtvp: audio: audioioctl.c:1106: t=997811378.6610: writing 4608 bytes to device
[4442,1026] mtvp: audio: audioioctl.c:1138: t=997811378.6610: 4608 bytes written
[4442,1026] mtvp: audio: audiolib.c:2657: t=997811378.6615: looking for next audio syncword
[4442,1026] mtvp: audio: audiolib.c:2664: t=997811378.6616: found audio syncword
[4442,1026] mtvp: audio: audioioctl.c:1106: t=997811378.6616: writing 4608 bytes to device
[4442,1026] mtvp: audio: audioioctl.c:1138: t=997811378.6616: 4608 bytes written
[4442,1026] mtvp: audio: audiolib.c:2657: t=997811378.6621: looking for next audio syncword
[4442,1026] mtvp: audio: audiolib.c:2664: t=997811378.6621: found audio syncword
[4442,1026] mtvp: audio: audioioctl.c:1106: t=997811378.6622: writing 4608 bytes to device
[4442,1026] mtvp: audio: audioioctl.c:1138: t=997811378.6622: 4608 bytes written
[4442,1026] mtvp: audio: audiolib.c:2657: t=997811378.6627: looking for next audio syncword
[4442,1026] mtvp: audio: audiolib.c:2664: t=997811378.6627: found audio syncword
[4442,1026] mtvp: audio: audioioctl.c:1106: t=997811378.6627: writing 4608 bytes to device
[4442,1026] mtvp: audio: audioioctl.c:1138: t=997811379.6529: 1536 bytes written
[4442,1026] mtvp: audio: audioioctl.c:1106: t=997811379.6530: writing 3072 bytes to device
[4442,1026] mtvp: audio: audioioctl.c:1134: t=997811379.6530: error: write to device failed: Invalid
 argument (status=22)
[4442,1026] mtvp: audio: audiolib.c:6077: t=997811379.6531: error: couldn't write 4608 bytes to devi
ce: Invalid argument (status=22)
[4442,1026] mtvp: audio: audiolib.c:6532: t=997811379.6531: error: in mal_decode_something(): mal_de
code_frame() returned -1: Invalid argument (status=22)
[4442,1026] mtvp: audio: audio_fork.c:971: t=997811379.6532: error: cannot play audio: Invalid argum
ent (status=22)
[4442,1026] mtvp: audio: audio_fork.c:105: t=997811379.6532: sending msg: type: 84, sz: 4, val: 22  
[4442,1026] mtvp: audio: audio_fork.c:254: t=997811379.6532: flushing all pending commands until A2S
_COM_RESTART
[4442,1026] mtvp: audio: audiolib.c:7039: t=997811379.6532: flushing buffer data
[4442,1026] mtvp: audio: audiolib.c:2317: t=997811379.6533: flushing pts fifo   
[4442,1026] mtvp: audio: audiolib.c:2718: t=997811379.6533: closing audio device
[4442,1026] mtvp: audio: audioioctl.c:267: t=997811379.6533: closing audio device...
[4442,1026] mtvp: audio: audioioctl.c:253: t=997811379.6533: ioctl(24, SNDCTL_DSP_RESET, ...) = 0
[4442,1026] mtvp: audio: audioioctl.c:342: t=997811380.6555: audio device closed
[4442,1026] mtvp: audio: audiolib.c:2722: t=997811380.6555: audio device closed


> 
> >  - sox produces a short blip as though the sample is playing too fast
> 
> is the length of the blip proportional to the length of the sample?

Yes, I tried an mp3 file with a duration of 30 minutes and 45 seconds
with mxaudio. The progess indicator went from start to end in about
30 seconds. Seems to be factor 60 ?!?

	-Andre
Comment 5 gandalf 2001-08-14 20:49:22 UTC
please test this patch.

    -cg

Index: channel.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/sound/pcm/channel.c,v
retrieving revision 1.19.2.13
diff -u -b -r1.19.2.13 channel.c
--- channel.c   2001/08/01 03:41:03     1.19.2.13
+++ channel.c   2001/08/14 17:55:32
@@ -24,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/sound/pcm/channel.c,v 1.19.2.13 2001/08/01
03:41:03 cg Exp $
+ * $FreeBSD: src/sys/dev//sound/pcm/channel.c,v 1.19.2.13 2001/08/01
03:41:03 cg Exp $
  */

 #include <dev/sound/pcm/sound.h>
@@ -422,7 +422,7 @@

        CHN_LOCKASSERT(c);
        /* if we're running, or if we're prevented from triggering, bail */
-       if ((c->flags & CHN_F_TRIGGERED) || (c->flags & CHN_F_NOTRIGGER))
+       if ((c->flags & CHN_F_TRIGGERED) || ((c->flags & CHN_F_NOTRIGGER) &&
!force))
                return EINVAL;

        i = (c->direction == PCMDIR_PLAY)? sndbuf_getready(bs) :
sndbuf_getfree(bs);
Index: dsp.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/sound/pcm/dsp.c,v
retrieving revision 1.15.2.8
diff -u -b -r1.15.2.8 dsp.c
--- dsp.c       2001/08/01 03:41:03     1.15.2.8
+++ dsp.c       2001/08/14 18:35:56
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/sound/pcm/dsp.c,v 1.15.2.8 2001/08/01 03:41:03 cg
Exp $
+ * $FreeBSD: src/sys/dev//sound/pcm/dsp.c,v 1.15.2.8 2001/08/01 03:41:03 cg
Exp $
  */

 #include <sys/param.h>
@@ -854,20 +854,18 @@
                if (rdch) {
                        CHN_LOCK(rdch);
                        rdch->flags &= ~(CHN_F_TRIGGERED | CHN_F_NOTRIGGER);
-                       if (*arg_i & PCM_ENABLE_INPUT) {
-                               rdch->flags |= CHN_F_TRIGGERED;
+                       if (*arg_i & PCM_ENABLE_INPUT)
                                chn_start(rdch, 1);
-                       } else
+                       else
                                rdch->flags |= CHN_F_NOTRIGGER;
                        CHN_UNLOCK(rdch);
                }
                if (wrch) {
                        CHN_LOCK(wrch);
                        wrch->flags &= ~(CHN_F_TRIGGERED | CHN_F_NOTRIGGER);
-                       if (*arg_i & PCM_ENABLE_OUTPUT) {
-                               wrch->flags |= CHN_F_TRIGGERED;
+                       if (*arg_i & PCM_ENABLE_OUTPUT)
                                chn_start(wrch, 1);
-                       } else
+                       else
                                wrch->flags |= CHN_F_NOTRIGGER;
                        CHN_UNLOCK(wrch);
                }
Comment 6 Andre Albsmeier 2001-08-14 21:32:08 UTC
On Tue, 14-Aug-2001 at 20:49:22 +0100, Cameron Grant wrote:
> please test this patch.
> 
>     -cg
> 

I had to apply it by hand due to some line wrap problems
but it seems I did it right since it fixes the problem :-)

At least it works here on the <SB16 DSP 4.16> with mtv
and mxaudio. Maybe others can try theur stuff as well..

Thanks for the quick help,

	-Andre
Comment 7 Ted Faber 2001-08-15 01:37:49 UTC
On Tue, Aug 14, 2001 at 10:36:09PM +0200, Andre Albsmeier wrote:
> The PR (29709) contains a patch from Cameron which fixes the problem
> here (SB16 with mxaudio and mtv)!
> 
> Maybe you want to try it out as well...

I can't get to the original machine until later, but I build the
PRERELEASE on my laptop and it exhibits the same problems.

arvon:~$ cat /dev/sndstat
FreeBSD Audio Driver (newpcm) Aug 14 2001 15:55:37
Installed devices:
pcm0: <Yamaha DS-1E (YMF744)> at memory 0xfedf8000 irq 9 (4p/2r/0v channels duplex)


I applied the patch, and mtv works.  Once.  A second invocation can't
open /dev/dsp.  aviplay has similar problems, although it may run more
than once, eventually the sound device gets jammed up.  (mtv may run
more than once, too, but the time I tried it failed on the second
attempt).

play from the sox package still fails, as does catting the file,
although the failure mode is a little different: a pop then the sound
played too fast and then a pop.

I'll try this all again on my soundblaster at home, but I don't think
this should close yet.

Comment 8 Andre Albsmeier 2002-01-05 14:59:33 UTC
This PR can be closed.

At least regarding my problem :-)

Thanks,

	-Andre
Comment 9 Maxim Konovalov freebsd_committer freebsd_triage 2002-09-16 09:12:02 UTC
State Changed
From-To: open->closed

Closed at originator's request.