[patch] stereo input is mixed to monaural via SoundBlaster16 recording mixer

Watanabe Kazuhiro CQG00620 at nifty.ne.jp
Wed Nov 9 13:47:05 GMT 2005


At Tue, 08 Nov 2005 16:59:55 +0100,
Alexander Leidinger wrote:
> Watanabe Kazuhiro <CQG00620 at nifty.ne.jp> wrote:
> 
> > 	if (src & SOUND_MASK_MIC)
> > -		recdev |= 0x01; /* mono mic */
> > +		recdev_l |= 0x01; /* mono mic */
> > +		recdev_r |= 0x01;
> 
> If I understand this correctly, this feeds the monaural signal to the left
> and the right channel. When we have a mono input, do we really want to have
> the same input doubled? I don't do any recording, so I don't know how most
> programs handle this, but IMHO it's a waste of resources and if the source
> is only able to deliver a mono-signal, the recording should only be possible
> in mono.

The function sb16mix_setrecsrc() only manipulates the analog recording
mixer.  So if we assign a mono input to the left and right channel, it
doesn't force for us to record a two-channel digitized output.

To decide a sampling format(stereo/mono, sample rate, bit length, and
so on) is not the mixer's role but DSP.

At Wed, 9 Nov 2005 00:20:13 +0800,
Ariff Abdullah wrote:
> Watanabe-san, I would suggest you to put braces along with the
> conditional statement so the code become much easier tu understand.
> Without it, it seems that recdev_r will always be set even if the
> condition is false.

Oops... your indication is right and I'm wrong. The correct patch is
below.

However, this patch is not perfect.  After applied the patch, if I try
to record an monaural output (e.g. "wavrec -M mono.wav"), only record
the left channel sound.

From the "Hardware Programming Reference" pp74:
	"When recording in mono, note that samples will only be taken
	from the left input mixer.

	So, if a mono recording of a stereo source is desired, the
	switchs controlled by registers 0x3D and 0x3E must be
	manipulated to enable both channels of a stereo source to be
	mixed together first into the left input mixer before being
	sampled."

I'm just going to consider the problem.  Perhaps it's difficult for
me to solve the problem...

--- sys/dev/sound/isa/sb16.c.orig	Tue Nov  8 22:01:22 2005
+++ sys/dev/sound/isa/sb16.c	Wed Nov  9 12:22:29 2005
@@ -370,23 +370,32 @@ static int
 sb16mix_setrecsrc(struct snd_mixer *m, u_int32_t src)
 {
     	struct sb_info *sb = mix_getdevinfo(m);
-    	u_char recdev;
+	u_char recdev_l, recdev_r;
 
-	recdev = 0;
-	if (src & SOUND_MASK_MIC)
-		recdev |= 0x01; /* mono mic */
+	recdev_l = 0;
+	recdev_r = 0;
+	if (src & SOUND_MASK_MIC) {
+		recdev_l |= 0x01; /* mono mic */
+		recdev_r |= 0x01;
+	}
 
-	if (src & SOUND_MASK_CD)
-		recdev |= 0x06; /* l+r cd */
+	if (src & SOUND_MASK_CD) {
+		recdev_l |= 0x04; /* l cd */
+		recdev_r |= 0x02; /* r cd */
+	}
 
-	if (src & SOUND_MASK_LINE)
-		recdev |= 0x18; /* l+r line */
+	if (src & SOUND_MASK_LINE) {
+		recdev_l |= 0x10; /* l line */
+		recdev_r |= 0x08; /* r line */
+	}
 
-	if (src & SOUND_MASK_SYNTH)
-		recdev |= 0x60; /* l+r midi */
+	if (src & SOUND_MASK_SYNTH) {
+		recdev_l |= 0x40; /* l midi */
+		recdev_r |= 0x20; /* r midi */
+	}
 
-	sb_setmixer(sb, SB16_IMASK_L, recdev);
-	sb_setmixer(sb, SB16_IMASK_R, recdev);
+	sb_setmixer(sb, SB16_IMASK_L, recdev_l);
+	sb_setmixer(sb, SB16_IMASK_R, recdev_r);
 
 	/* Switch on/off FM tuner source */
 	if (src & SOUND_MASK_LINE1)
@@ -849,7 +858,7 @@ sb16_attach(device_t dev)
 	else
 		status2[0] = '\0';
 
-    	snprintf(status, SND_STATUSLEN, "at io 0x%lx irq %ld drq %ld%s bufsz %ud %s",
+    	snprintf(status, SND_STATUSLEN, "at io 0x%lx irq %ld drq %ld%s bufsz %u %s",
     	     	rman_get_start(sb->io_base), rman_get_start(sb->irq),
 		rman_get_start(sb->drq1), status2, sb->bufsize,
 		PCM_KLDSTRING(snd_sb16));

---
Watanabe Kazuhiro (CQG00620 at nifty.ne.jp)


More information about the freebsd-multimedia mailing list