From mkb@altair.mukappabeta.net  Fri Oct  1 01:02:13 2004
Return-Path: <mkb@altair.mukappabeta.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id E474C16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  1 Oct 2004 01:02:13 +0000 (GMT)
Received: from moghedien.mukappabeta.net (moghedien.mukappabeta.net [194.145.150.66])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 83A5D43D31
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  1 Oct 2004 01:02:13 +0000 (GMT)
	(envelope-from mkb@altair.mukappabeta.net)
Received: from altair.mukappabeta.net (pD9E696F9.dip.t-dialin.net [217.230.150.249])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by moghedien.mukappabeta.net (Postfix) with ESMTP id 9E05E2D73
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  1 Oct 2004 02:58:13 +0200 (CEST)
Received: by altair.mukappabeta.net (Postfix, from userid 1001)
	id DD5095C54; Fri,  1 Oct 2004 03:02:06 +0200 (CEST)
Message-Id: <20041001010206.DD5095C54@altair.mukappabeta.net>
Date: Fri,  1 Oct 2004 03:02:06 +0200 (CEST)
From: Matthias Buelow <mkb@mukappabeta.de>
Reply-To: Matthias Buelow <mkb@mukappabeta.de>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: emu10k1 stereo channels are reversed (5.3-beta6)
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         72221
>Category:       kern
>Synopsis:       [sound] emu10k1 stereo channels are reversed (5.3-beta6)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-multimedia
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Oct 01 01:10:24 GMT 2004
>Closed-Date:    Wed Dec 28 17:58:41 GMT 2005
>Last-Modified:  Wed Dec 28 17:58:41 GMT 2005
>Originator:     Matthias Buelow
>Release:        FreeBSD 5.3-BETA6 i386
>Organization:
>Environment:
System: FreeBSD xxx 5.3-BETA6 FreeBSD 5.3-BETA6 #1: Tue Sep 28 18:32:48 CEST 2004 root@xxx:/usr/obj/usr/src/sys/xxx i386


>Description:

	The stereo channels on emu10k1 (sblive! hardware) seem to be
	reversed, that is, left is right, and vice versa.
	This is most definitely a driver bug.  On Linux, it works
	properly on the same hardware.

>How-To-Repeat:
>Fix:

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->sound 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Oct 8 06:12:13 GMT 2004 
Responsible-Changed-Why:  
Reassign to appropriate mailing list. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=72221 

From: Tig <tigger.on@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org, mkb@mukappabeta.de
Cc:  
Subject: Re: kern/72221: [sound] emu10k1 stereo channels are reversed (5.3-beta6)
Date: Fri, 5 Nov 2004 23:51:36 +1100

 I'm no programmer, but this is what I did to fix this problem. I
 edited /usr/src/sys/dev/sound/pci/emu10k1.c
 and changed :
 
 556         if (v->stereo) {
 557                 l = v->ismaster ? l : 0;
 558                 r = v->ismaster ? 0 : r;
 559         }
 
 to this
 
 556         if (v->stereo) {
 557                 l = v->ismaster ? 0 : l;
 558                 r = v->ismaster ? r : 0;
 559         }
 
 My sound card is:
 pcm0: <Creative Audigy 2 (EMU10K2)> port 0xc400-0xc43f irq 23 at
 device 2.0 on pci2
 
 uname -a
 FreeBSD cage.goo 5.3-STABLE FreeBSD 5.3-STABLE #0: Tue Nov  2 16:26:03
 EST 2004     tigger@cage.goo:/usr/obj/usr/src/sys/GENERIC  i386
 
 I have no idea if this breaks any other cards, but it works fine here.

From: Gil Kloepfer <gkloepfer@sbcglobal.net>
To: freebsd-gnats-submit@FreeBSD.org, mkb@mukappabeta.de
Cc:  
Subject: Re: kern/72221: [sound] emu10k1 stereo channels are reversed (5.3-beta6)
Date: Tue, 23 Nov 2004 14:22:17 -0600

 This problem also exists on 5.3-RELEASE (verified) on SoundBlaster Live; CPU: 
 Athlon Thunderbird 800 MHz using GENERIC kernel:
 
 pcm0: <Creative EMU10K1> port 0xe000-0xe01f irq 5 at device 13.0 on pci0
 pcm0: <TriTech TR28023 AC97 Codec>
 
 FreeBSD cerebrum.kloepfer.org 5.3-RELEASE FreeBSD 5.3-RELEASE #0: Fri Nov  5 
 04:19:18 UTC 2004     root@harlow.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386
 
 Audio application: xmms 1.2.10 (from ports)
 
 The fix included in the bug report also works for me as well.  I, too, don't
 understand why it works.  It seems that the snippet of code has been
 "reversed" since at least 4.8-RELEASE, and I can't remember if the problem
 happened at that release of FreeBSD too...

From: Eric Anholt <eta@lclark.edu>
To: gnats <freebsd-gnats-submit@FreeBSD.ORG>
Cc:  
Subject: Re: kern/72221
Date: Mon, 27 Jun 2005 01:32:46 -0700

 I tested this on a:
 pcm0: <Creative EMU10K1> port 0xa800-0xa81f irq 17 at device 13.0 on pci0
 pcm0: <TriTech TR28023 AC97 Codec>
 and the channels were the right way around already.  I suspect the
 proper fix is going to be more complicated.
 
 -- 
 Eric Anholt                                     eta@lclark.edu
 http://people.freebsd.org/~anholt/              anholt@FreeBSD.org

From: Juha-Matti Tilli <juhis@nallukka.net>
To: bug-followup@FreeBSD.org, mkb@mukappabeta.de
Cc:  
Subject: Re: kern/72221: [sound] emu10k1 stereo channels are reversed (5.3-beta6)
Date: Sat, 26 Nov 2005 02:13:03 +0200

 I have also the problem on 6.0-RELEASE. I think I have found the change
 which reversed the channels. Revision 1.44 of emu10k1.c, which added
 Audigy support, has the line
 
 emu_wrptr(sc, v->vnum, FXRT, 0xd01c0000);
 
 replaced with the following lines:
 
 if (sc->audigy) {
         emu_wrptr(sc, v->vnum, A_FXRT1, v->fxrt1);
         emu_wrptr(sc, v->vnum, A_FXRT2, v->fxrt2);
         emu_wrptr(sc, v->vnum, A_SENDAMOUNTS, 0);
 }
 else
         emu_wrptr(sc, v->vnum, FXRT, v->fxrt1 << 16);
 
 where v->fxrt1 << 16 == 0xd10c0000
 
 Here's a patch to correct the order of the channels:
 
 --- emu10k1.c.orig      Tue Mar  1 10:58:05 2005
 +++ emu10k1.c   Sat Nov 26 02:00:56 2005
 @@ -494,12 +494,12 @@
         m->buf = tmp_addr;
         m->slave = s;
         if (sc->audigy) {
 -               m->fxrt1 = FXBUS_MIDI_CHORUS | FXBUS_PCM_LEFT << 8 |
 -                   FXBUS_PCM_RIGHT << 16 | FXBUS_MIDI_REVERB << 24;
 +               m->fxrt1 = FXBUS_MIDI_CHORUS | FXBUS_PCM_RIGHT << 8 |
 +                   FXBUS_PCM_LEFT << 16 | FXBUS_MIDI_REVERB << 24;
                 m->fxrt2 = 0x3f3f3f3f;  /* No effects on second route */
         } else {
 -               m->fxrt1 = FXBUS_MIDI_CHORUS | FXBUS_PCM_LEFT << 4 |
 -                   FXBUS_PCM_RIGHT << 8 | FXBUS_MIDI_REVERB << 12;
 +               m->fxrt1 = FXBUS_MIDI_CHORUS | FXBUS_PCM_RIGHT << 4 |
 +                   FXBUS_PCM_LEFT << 8 | FXBUS_MIDI_REVERB << 12;
                 m->fxrt2 = 0;
         }
 
 
 I don't have Audigy, so I'm not sure if the problem affects Audigy cards
 too. The order of the channels can't be tested by just altering mixer
 settings. Here's a small program to test if the channels are reversed on
 your sound card:
 
 
 #include <sys/soundcard.h>
 #include <fcntl.h>
 #include <unistd.h>
 
 int main(int argc, char **argv)
 {
 	int fd = open("/dev/dsp", O_WRONLY), format = AFMT_S16_LE;
   int channels = 2, rate = 22050, i;
 
   /* 450 Hz sine wave on left channel, right channel silent */
   unsigned char samples[] = {0, 0, 0, 0, 94, 16, 0, 0, 120, 32, 0, 0,
     9, 48, 0, 0, 208, 62, 0, 0, 143, 76, 0, 0, 12, 89, 0, 0, 19, 100,
     0, 0, 117, 109, 0, 0, 11, 117, 0, 0, 182, 122, 0, 0, 92, 126, 0,
     0, 239, 127, 0, 0, 105, 127, 0, 0, 202, 124, 0, 0, 32, 120, 0, 0,
     124, 113, 0, 0, 251, 104, 0, 0, 193, 94, 0, 0, 249, 82, 0, 0,
     212, 69, 0, 0, 138, 55, 0, 0, 85, 40, 0, 0, 120, 24, 0, 0, 51, 8,
     0, 0, 205, 247, 0, 0, 136, 231, 0, 0, 171, 215, 0, 0, 118, 200,
     0, 0, 44, 186, 0, 0, 7, 173, 0, 0, 63, 161, 0, 0, 5, 151, 0, 0,
     132, 142, 0, 0, 224, 135, 0, 0, 54, 131, 0, 0, 151, 128, 0, 0,
     17, 128, 0, 0, 164, 129, 0, 0, 74, 133, 0, 0, 245, 138, 0, 0,
     139, 146, 0, 0, 237, 155, 0, 0, 244, 166, 0, 0, 113, 179, 0, 0,
     48, 193, 0, 0, 247, 207, 0, 0, 136, 223, 0, 0, 162, 239, 0, 0};
 
   ioctl(fd, SNDCTL_DSP_SETFMT,&format);
   ioctl(fd, SNDCTL_DSP_CHANNELS,&channels);
   ioctl(fd, SNDCTL_DSP_SPEED,&rate);
 
   for(i=0;i<500;i++)
     write(fd, &samples, sizeof(samples));
   write(fd, &samples, 2); /* swap channels */
   for(i=0;i<500;i++)
     write(fd, &samples, sizeof(samples));
 
   return 0;
 }
 
 You should hear a sound on the left channel followed by a sound on the
 right channel. If you hear a sound on the right channel first, the
 channels are reversed.
 
 -- 
 Juha-Matti Tilli, email: juhis@nallukka.net
State-Changed-From-To: open->closed 
State-Changed-By: netchild 
State-Changed-When: Wed Dec 28 17:58:33 UTC 2005 
State-Changed-Why:  
Committed. Thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=72221 
>Unformatted:
