Skip to contentSkip to conversation

Alsa-OSS so-called 'Duplex-bug'

PATCH Alan H 3 participants 7 messages Jun 19, 2006 – Jul 1, 2006

lore
Share & tools
lore

Alan H

author
#0 lore raw

There is considered by some to be a duplex bug in alsa-OSS, which affects for example audacity, which uses portaudio. As this affects myself very much I have investigated.

The cause is that the OSS ioctl SNDCTL_DSP_CHANNELS cannot set separately the playback and capture channels. With the original OSS this was not a problem AFAICT because separate playback and capture devices are created. However, with the alsa-emulation, only a single device is created. Thus it is not possible to record 4 chs while playing 2.

It seems to me that some method of separately setting playback and capture channels should be included in the emulation. This could be through new ioctls eg SNDCTL_DSP_PCHANNELS and SNDCTL_DSP_CCHANNELS; I have devised an alternative using the existing SNDCTL_DSP_CHANNELS, by passing 'channels' calculated as (playback_channels + 256 * capture_channels) so that in effect the first 8 bits are playback, the 2nd 8 bits are capture. The result is compatible with the existing, as numbers < 255 are treated in the existing way, setting playback and capture the same if the sub-streams are active. Thus it has simply added an enhanced mode.

Diff is attached; I wonder what your thoughts are on this?? I have been able to very simply patch portaudio to use this facility and the system now works great.

Regards Alan

core/oss/pcm_oss.c renamed from core/oss/pcm_oss-orig.c +54 -12
@@ -1156,25 +1156,67 @@
 	return substream->runtime->oss.rate;
 }
 
+static int snd_pcm_oss_get_substream_channels(struct snd_pcm_oss_file *pcm_oss_file, int substrindx)
+{
+	struct snd_pcm_substream *substream;
+	int err = -1;
+
+	if (substrindx < 0 || substrindx > 1)
+		return err;
+	substream = pcm_oss_file->streams[substrindx];
+	if (substream == NULL)
+		return 0; /* Don't complain, consider as zero active channels */
+	return substream->runtime->oss.channels;
+}
+
 static int snd_pcm_oss_set_channels(struct snd_pcm_oss_file *pcm_oss_file, unsigned int channels)
 {
-	int idx;
+	struct snd_pcm_substream *substream;
+	int playback_channels, capture_channels, channels_set = -1;
+
 	if (channels < 1)
 		channels = 1;
-	if (channels > 128)
+	if (channels > 65025)
 		return -EINVAL;
-	for (idx = 1; idx >= 0; --idx) {
-		struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];
-		struct snd_pcm_runtime *runtime;
-		if (substream == NULL)
-			continue;
-		runtime = substream->runtime;
-		if (runtime->oss.channels != channels) {
-			runtime->oss.params = 1;
-			runtime->oss.channels = channels;
+
+	playback_channels = channels & 255;
+			/* lower 8 bits always set playback channels */
+	if (playback_channels > 128)
+		return -EINVAL;
+	substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK];
+	printk("SND OSS: p/b chs %i\n", playback_channels);
+	if (substream != NULL)
+		if (substream->runtime->oss.channels != playback_channels) {
+			substream->runtime->oss.params = 1;
+			substream->runtime->oss.channels = playback_channels;
 		}
+
+	substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE];
+	if (channels >255) { /* Enhanced channel set mode */
+		capture_channels = channels / 256 & 255;
+			 /* 2nd 8 bits set capture channels */
+		if (capture_channels > 128)
+			return -EINVAL;
+		if (substream != NULL)
+			if (substream->runtime->oss.channels != capture_channels) {
+				substream->runtime->oss.params = 1;
+				substream->runtime->oss.channels = capture_channels;
+			}
+		channels_set = snd_pcm_oss_get_substream_channels(
+				   pcm_oss_file, SNDRV_PCM_STREAM_PLAYBACK)
+				   + 256 * snd_pcm_oss_get_substream_channels(
+				   pcm_oss_file, SNDRV_PCM_STREAM_CAPTURE);
+	} else {  /* Standard mode, same num channels play and capture */
+		if (substream != NULL)
+			if (substream->runtime->oss.channels != channels) {
+				 /* Capture channels same as playback */
+				substream->runtime->oss.params = 1;
+				substream->runtime->oss.channels = channels;
+			}
+		channels_set = snd_pcm_oss_get_channels(pcm_oss_file);
 	}
-	return snd_pcm_oss_get_channels(pcm_oss_file);
+	printk("SND OSS: chs set %i\n", channels_set);
+	return channels_set;
 }
 
 static int snd_pcm_oss_get_channels(struct snd_pcm_oss_file *pcm_oss_file)

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#1 lore raw

At Mon, 19 Jun 2006 15:15:28 +0100,

Quoted 8 lines · Alan H

There is considered by some to be a duplex bug in alsa-OSS, which affects for example audacity, which uses portaudio. As this affects myself very much I have investigated.

The cause is that the OSS ioctl SNDCTL_DSP_CHANNELS cannot set separately the playback and capture channels. With the original OSS this was not a problem AFAICT because separate playback and capture devices are created.

Really? How? /dev/dsp0 and /dev/dsp1 for playback and capture?

Quoted 7 lines

However,
with the alsa-emulation, only a single device is created. Thus it is not possible to record 4 chs while playing 2.

It seems to me that some method of separately setting playback and capture channels should be included in the emulation. This could be through new ioctls eg SNDCTL_DSP_PCHANNELS and SNDCTL_DSP_CCHANNELS;

Introducing new ioctls doesn't make sense because the purpose of aoss is to emulate the OSS, not creating a new one.

Quoted 11 lines

I have devised an
alternative using the existing SNDCTL_DSP_CHANNELS, by passing 'channels' calculated as (playback_channels + 256 * capture_channels) so that in effect the first 8 bits are playback, the 2nd 8 bits are capture. The result is compatible with the existing, as numbers < 255 are treated in the existing way, setting playback and capture the same if the sub-streams are active. Thus it has simply added an enhanced mode.

Diff is attached; I wonder what your thoughts are on this?? I have been able to very simply patch portaudio to use this facility and the system now works great.

I don't think it's a right solution. This simply introduces an incompatibility with the existing OSS ioctl...

Takashi

#2 lore raw
Quoted 7 lines · Takashi Iwai

At Mon, 19 Jun 2006 15:15:28 +0100,

Quoted 4 lines · Alan H

There is considered by some to be a duplex bug in alsa-OSS, which affects for example audacity, which uses portaudio. As this affects myself very much I have investigated.

Quoted 5 lines
Quoted 3 lines

The cause is that the OSS ioctl SNDCTL_DSP_CHANNELS cannot set separately the playback and capture channels. With the original OSS this was not a problem AFAICT because separate playback and capture devices are created.

Really? How? /dev/dsp0 and /dev/dsp1 for playback and capture?

For the ice1712 (my main 2 cards), apparently, a whole series of stereo devices are created; /dev/dsp0 to dsp4 cover the 10 playback channels, and dsp5 to 10 are capture; dsp11 & 12 are 'raw devices', 11 is playback, 12 capture. I have attached the OSS release notes I downloaded ages ago.

Quoted 10 lines
Quoted 7 lines

However,
with the alsa-emulation, only a single device is created. Thus it is not possible to record 4 chs while playing 2.

It seems to me that some method of separately setting playback and capture channels should be included in the emulation. This could be through new ioctls eg SNDCTL_DSP_PCHANNELS and SNDCTL_DSP_CCHANNELS;

Introducing new ioctls doesn't make sense because the purpose of aoss is to emulate the OSS, not creating a new one.

That is what I thought.

Quoted 8 lines
Quoted 8 lines

I have devised an
alternative using the existing SNDCTL_DSP_CHANNELS, by passing 'channels' calculated as (playback_channels + 256 * capture_channels) so that in effect the first 8 bits are playback, the 2nd 8 bits are capture. The result is compatible with the existing, as numbers < 255 are treated in the existing way, setting playback and capture the same if the sub-streams are active. Thus it has simply added an enhanced mode.

Quoted 6 lines
Quoted 3 lines

Diff is attached; I wonder what your thoughts are on this?? I have been able to very simply patch portaudio to use this facility and the system now works great.

I don't think it's a right solution. This simply introduces an incompatibility with the existing OSS ioctl...

The 'enhanced' alsa-emulation I created is backwards compatible; it enables aware apps to work-around the limitation of the emulation. But if sent commands as-if standard, does exactly what it would have done. However, where the app needs to set separate record and playback channels for a duplex mode, there is extra capability. It would be used only for duplex when (capture_channels != playback_channels) This would not be necessary with original OSS, although also it would not work. None-the-less I can understand your reluctance, it is just that a solution seems necessary.

Another alternative would be for ALSA to create at least two devices, one for all playback channels, the other for all capture, eg /dsp0 and /adsp0 or something else. It would then be more like the raws OSS in its behaviour. That would also solve the problems here. Obviously a full implementation as per attached description would also be fine!

Alan

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#3 lore raw

At Mon, 19 Jun 2006 22:12:57 +0100,

Quoted 25 lines · Alan Horstmann
Quoted 9 lines
Quoted 9 lines

I have devised an
alternative using the existing SNDCTL_DSP_CHANNELS, by passing 'channels' calculated as (playback_channels + 256 * capture_channels) so that in effect the first 8 bits are playback, the 2nd 8 bits are capture. The result is compatible with the existing, as numbers < 255 are treated in the existing way, setting playback and capture the same if the sub-streams are active. Thus it has simply added an enhanced mode.

Quoted 6 lines
Quoted 3 lines

Diff is attached; I wonder what your thoughts are on this?? I have been able to very simply patch portaudio to use this facility and the system now works great.

I don't think it's a right solution. This simply introduces an incompatibility with the existing OSS ioctl...

The 'enhanced' alsa-emulation I created is backwards compatible; it enables aware apps to work-around the limitation of the emulation. But if sent commands as-if standard, does exactly what it would have done. However, where the app needs to set separate record and playback channels for a duplex mode, there is extra capability. It would be used only for duplex when (capture_channels != playback_channels) This would not be necessary with original OSS, although also it would not work. None-the-less I can understand your reluctance, it is just that a solution seems necessary.

Quoted 5 lines

Another alternative would be for ALSA to create at least two devices, one for all playback channels, the other for all capture, eg /dsp0 and /adsp0 or something else. It would then be more like the raws OSS in its behaviour. That would also solve the problems here. Obviously a full implementation as per attached description would also be fine!

It's easy over aoss. Having the following

	pcm.dsp0 {
		type asym
		playback.pcm "plughw"
	}

	pcm.dsp1 {
		type asym
		capture.pcm "plughw"
	}

would give you /dev/dsp0 for playback and /dev/dsp1 for capture. You can replace "plughw" whatever you like, of course.

Takashi

#4 lore raw
Quoted 21 lines · you

At Mon, 19 Jun 2006 22:12:57 +0100,

Quoted 5 lines · Alan Horstmann

Another alternative would be for ALSA to create at least two devices, one for all playback channels, the other for all capture, eg /dsp0 and /adsp0 or something else. It would then be more like the raws OSS in its behaviour. That would also solve the problems here. Obviously a full implementation as per attached description would also be fine!

It's easy over aoss. Having the following

	pcm.dsp0 {
		type asym
		playback.pcm "plughw"
	}

	pcm.dsp1 {
		type asym
		capture.pcm "plughw"
	}
Quoted 2 lines

would give you /dev/dsp0 for playback and /dev/dsp1 for capture. You can replace "plughw" whatever you like, of course.

I'm not very familiar with these conf files, and have tried for hours to get this to work. However, at best
aoss audacity
results in
ALSA lib pcm_asym.c:106:(_snd_pcm_asym_open) playback slave is not defined ALSA lib pcm_asym.c:106:(_snd_pcm_asym_open) capture slave is not defined

Have I missed other bits?

Also, won't using aoss introduce a performance hit?

Regards Alan

Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

#5 lore raw

At Thu, 29 Jun 2006 23:11:05 +0100,

Quoted 33 lines · Alan Horstmann
Quoted 21 lines · you

At Mon, 19 Jun 2006 22:12:57 +0100,

Quoted 5 lines · Alan Horstmann

Another alternative would be for ALSA to create at least two devices, one for all playback channels, the other for all capture, eg /dsp0 and /adsp0 or something else. It would then be more like the raws OSS in its behaviour. That would also solve the problems here. Obviously a full implementation as per attached description would also be fine!

It's easy over aoss. Having the following

	pcm.dsp0 {
		type asym
		playback.pcm "plughw"
	}

	pcm.dsp1 {
		type asym
		capture.pcm "plughw"
	}
Quoted 2 lines

would give you /dev/dsp0 for playback and /dev/dsp1 for capture. You can replace "plughw" whatever you like, of course.

I'm not very familiar with these conf files, and have tried for hours to get this to work. However, at best
aoss audacity
results in
ALSA lib pcm_asym.c:106:(_snd_pcm_asym_open) playback slave is not defined ALSA lib pcm_asym.c:106:(_snd_pcm_asym_open) capture slave is not defined

Quoted 3 lines

Have I missed other bits?

Also, won't using aoss introduce a performance hit?

Err, I should have tested before posting. How about below?

pcm.dsp0 {
type asym
playback.pcm "plughw"
capture.pcm "null"
}
pcm.dsp1 {
type asym
playback.pcm "null"
capture.pcm "plughw"
}

Takashi

Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

#6 lore raw
Quoted 51 lines · you

At Thu, 29 Jun 2006 23:11:05 +0100,

Quoted 34 lines · Alan Horstmann
Quoted 22 lines · you

At Mon, 19 Jun 2006 22:12:57 +0100,

Quoted 6 lines · Alan Horstmann

Another alternative would be for ALSA to create at least two devices, one for all playback channels, the other for all capture, eg /dsp0 and /adsp0 or something else. It would then be more like the raws OSS in its behaviour. That would also solve the problems here. Obviously a full implementation as per attached description would also be fine!

It's easy over aoss. Having the following

	pcm.dsp0 {
		type asym
		playback.pcm "plughw"
	}

	pcm.dsp1 {
		type asym
		capture.pcm "plughw"
	}
Quoted 2 lines

would give you /dev/dsp0 for playback and /dev/dsp1 for capture. You can replace "plughw" whatever you like, of course.

I'm not very familiar with these conf files, and have tried for hours to get this to work. However, at best
aoss audacity
results in
ALSA lib pcm_asym.c:106:(_snd_pcm_asym_open) playback slave is not
defined ALSA lib pcm_asym.c:106:(_snd_pcm_asym_open) capture slave is not defined

Quoted 3 lines

Have I missed other bits?

Also, won't using aoss introduce a performance hit?

Err, I should have tested before posting. How about below?

(quoted diff) +0 -0
 	pcm.dsp0 {
 		type asym
 		playback.pcm "plughw"

capture.pcm "null"

(quoted diff) +0 -0
 	}
 	pcm.dsp1 {
 		type asym

playback.pcm "null"

Review

Quoted 2 lines
(quoted diff) +0 -0
 		capture.pcm "plughw"
 	}

Now a different set of errors, interspersed with portaudio errors/warnings....

ALSA lib pcm.c:2146:(snd_pcm_open_noupdate) Unknown PCM dsp2
ALSA lib pcm_null.c:347:(snd_pcm_null_open) Cannot open /dev/full: Permission denied

ALSA lib pcm_null.c:347:(snd_pcm_null_open) Cannot open /dev/full: Permission denied

ALSA lib control.c:816:(snd_ctl_open_noupdate) Invalid CTL mixer0 ALSA lib control.c:816:(snd_ctl_open_noupdate) Invalid CTL mixer0 ALSA lib control.c:816:(snd_ctl_open_noupdate) Invalid CTL mixer1 ALSA lib control.c:816:(snd_ctl_open_noupdate) Invalid CTL mixer2 ALSA lib control.c:816:(snd_ctl_open_noupdate) Invalid CTL mixer3 ALSA lib control.c:816:(snd_ctl_open_noupdate) Invalid CTL mixer0 ALSA lib control.c:816:(snd_ctl_open_noupdate) Invalid CTL mixer0 ALSA lib control.c:816:(snd_ctl_open_noupdate) Invalid CTL mixer1 ALSA lib control.c:816:(snd_ctl_open_noupdate) Invalid CTL mixer2 ALSA lib control.c:816:(snd_ctl_open_noupdate) Invalid CTL mixer3

Alan

Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642