Subject: port-i386/2587: src/sys/dev/isa/sbdsp.c
To: None <gnats-bugs@NetBSD.ORG>
From: None <rvb@cs.cmu.edu>
List: netbsd-bugs
Date: 07/01/1996 14:57:54
>Number:         2587
>Category:       port-i386
>Synopsis:       audio does not sound right
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul  1 15:20:02 1996
>Last-Modified:
>Originator:     Robert V. Baron
>Organization:
	
>Release:        1.1
>Environment:
	
System: NetBSD strauss.coda.cs.cmu.edu 1.1 NetBSD 1.1 (CCODA) #14: Wed Jun 19 14:56:34 EDT 1996 bnoble@telemann.coda.cs.cmu.edu:/usr1/bnoble/kernel_tree/src/sys/arch/i386/compile/CCODA i386


>Description:
	sbdsp_round_blocksize(addr, blk) has a couple of problems: The
check below (see code) seems pretty braindead.  For 8k sample blk =
160 and is left alone.  For 16k which has blk = 320 the code kicks in
and yields blk = 2048.  This causes a rather poor audio sound.  I
think the code should be removed.  I have done so for the function
provided in the code listing below.  The change is under #ifdef	new

Note:  The code being commented out itself is wrong for another reason.
For the SB16 it tests the straight rates as follows:
                        if (sc->sc_orate > 8000 || sc->sc_irate > 8000)
                                blk = NBPG/2;
But for the time constant rate is checks
                        if (sc->sc_otc > SB_8K || sc->sc_itc < SB_8K)
                                blk = NBPG/2;
The < would appear to be a typo.


>How-To-Repeat:
	
	To get the problem to appear, you either have to use /dev/sound
with a sampling rate higher than 8k.  Or use /dev/audio and set both
the sampling rate and also the precision or number of channels.  (The
value of the precision/channels can be the default -- it just must be set.)
>Fix:
	

sbdsp_round_blocksize(addr, blk)
        void *addr;
        int blk;
{
        register struct sbdsp_softc *sc = addr;

        sc->sc_last_hs_size = 0;

        /* Higher speeds need bigger blocks to avoid popping and silence gaps. */
        if (blk < NBPG/4 || blk > NBPG/2) {
#define new
#ifdef  new
        /*
         * The check below seems pretty braindead.  For 8k sample blk = 160
         * and is left alone.  For 16k which has blk = 320 [or for 8k+epsilon]
         * the code kicks in and yields blk = 2048 !!!!!!!!!!!
         */
#else
                if (ISSB16CLASS(sc)) {
                        if (sc->sc_orate > 8000 || sc->sc_irate > 8000)
                                blk = NBPG/2;
                } else {
                        if (sc->sc_otc > SB_8K || sc->sc_itc < SB_8K)
                                blk = NBPG/2;
                }
#endif
#undef  new
        }
        /* don't try to DMA too much at once, though. */
        if (blk > NBPG)
                blk = NBPG;
        if (sc->sc_channels == 2)
                return (blk & ~1); /* must be even to preserve stereo separation */
        else
                return (blk);   /* Anything goes :-) */
}
>Audit-Trail:
>Unformatted: