Hi again!

Ludovico Cavedon wrote:
> mstute wrote:
>> On Friday 27 July 2007 00:42, Ludovico Cavedon wrote:
>>> I noticed that opening plughw devices instead of hw is working for me
>>> (no
>>> mono/stereo issue). I tried both the internal soundcard and a USB
>>> headset.
>>> In this case, it is ALSA taking care of the necessary conversions.
>>
>> For me it does solve the mono/stereo issue but unfortunately it breaks
>> audio mixing i.e no more dtfm feedback during a call... So I've added
>> to your patch the default ALSA device that fit most of the use cases
>> (see the attached patch) What do you think?
> 
> Mhm, I think it is a good compromise.
> Unfortunately I can not test it now, and I won't be reading the mail for
> the next 20 days...


I tried to understand why mixing gets broken: since alsa version 1.0.9,
the "default" pcm is set up to use the "dmix" plugin to enable audio
mixing for audio cards which do not support it in hardware. When using
"plughw" we do get "dmix" working.

We could enumerate the sound cards and use "default:0", "default:1",
"default:2", etc. This would enable audio mixing via dmix if necessary,
but it would be wrong to associate each "default:X" with a precise
hardware devices, because mapping of "default" can be overridden by the
.asoundrc file.

Rather, I would use the "plug:dmix:X" (X=card number) device for output,
instead of "plughw".
See the patch attached (edit of mstute's patch)

It has two little drawbacks:
-it enables dmix even if not necessary
-I could not manage to specify the device number on the card, but just
the card number (like just "hw:0" instead of "hw:0,0"). This mean that
the default device is used on that card. However I think it is not too
bad, as the user should be asked to choose just the sound card. More
fine tuning should be done using alsa configuration (asoundrc)

The patch is working, but still needs a modification in one of these
three directions:
-manage to specify the device with dmix
-remove duplicate output entries if a card has more than one output
device (with the current patch the same output card would apply more
than once)
-remove device selection for both input and output (for sake of consistency)

Actually, the best thing would be to use the new ALSA API of version
1.0.14, with would be allow to enumerate virtual pcm devices and gather
information like the following:
-------------
$ aplay -L
default:CARD=rev50
    VIA 82C686A/B rev50, VIA 82C686A/B rev50
    Default Audio Device
front:CARD=rev50,DEV=0
    VIA 82C686A/B rev50, VIA 82C686A/B rev50
    Front speakers
iec958:CARD=rev50,DEV=0
    VIA 82C686A/B rev50, VIA 82C686A/B rev50
    IEC958 (S/PDIF) Digital Audio Output
null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=Headset
    BT Headset, BT SCO PCM
    Default Audio Device
-------------
However using the new API would break compatibility with etch and
feisty, and I think it should be avoided.

What do you think?

Regards,
Ludovico
Index: wengophone-2.1.1.dfsg0/libs/sound/src/linux/AudioDeviceManager.cpp
===================================================================
--- wengophone-2.1.1.dfsg0.orig/libs/sound/src/linux/AudioDeviceManager.cpp	2007-04-20 14:06:36.000000000 +0000
+++ wengophone-2.1.1.dfsg0/libs/sound/src/linux/AudioDeviceManager.cpp	2007-08-25 20:13:42.000000000 +0000
@@ -28,39 +28,19 @@
 std::list<AudioDevice> AudioDeviceManager::getInputDeviceList() {
 	RecursiveMutex::ScopedLock scopedLock(_mutex);
 
-	//HACK: always return the default one + plughw
-	std::list<AudioDevice> deviceList;
-	deviceList.push_back(getDefaultInputDevice());
-
-	StringList data;
-	data += String("ALSA: plughw");
-	data += String("plughw");
-	data += EnumDeviceType::toString(EnumDeviceType::DeviceTypeWaveIn);
-	deviceList.push_back(AudioDevice(data));
+	std::list<AudioDevice> deviceList = find_alsa_devices(1);
+	deviceList.push_front(getDefaultInputDevice());
 
 	return deviceList;
-	////
-
-	//return find_alsa_devices(1);
 }
 
 std::list<AudioDevice> AudioDeviceManager::getOutputDeviceList() {
 	RecursiveMutex::ScopedLock scopedLock(_mutex);
 
-	//HACK: always return the default one + plughw
-	std::list<AudioDevice> deviceList;
-	deviceList.push_back(getDefaultOutputDevice());
-
-	StringList data;
-	data += String("ALSA: plughw");
-	data += String("plughw");
-	data += EnumDeviceType::toString(EnumDeviceType::DeviceTypeWaveOut);
-	deviceList.push_back(AudioDevice(data));
+	std::list<AudioDevice> deviceList = find_alsa_devices(0);
+	deviceList.push_front(getDefaultOutputDevice());
 
 	return deviceList;
-	////
-
-	//return find_alsa_devices(0);
 }
 
 AudioDevice AudioDeviceManager::getDefaultOutputDevice() {
@@ -131,7 +111,7 @@
 		////
 
 		// open the sound card
-		if( snd_ctl_open(&snd_ctl, alsa_card_name, 0 ) < 0 )
+		if ( snd_ctl_open(&snd_ctl, alsa_card_name, 0 ) < 0 )
 		{
 			LOG_WARN("unable to open card: " + String(alsa_card_name));
 			break;
@@ -165,8 +145,16 @@
 			int has_playback = 0;
 
 			// compute internal device name
-			snprintf(alsa_device_name, sizeof(alsa_device_name), "%s:%d,%d", "hw",
-			card_index, device_index);
+			if (input)
+			{
+				snprintf(alsa_device_name, sizeof(alsa_device_name), "%s:%d,%d",
+					"plughw", card_index, device_index);
+			}
+			else
+			{
+				snprintf(alsa_device_name, sizeof(alsa_device_name), "%s:%d",
+					"plug:dmix", card_index);
+			}
 			LOG_DEBUG("alsa_device_name: " + String(alsa_device_name));
 			////
 

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Wengophone-devel mailing list
[email protected]
http://dev.openwengo.com/mailman/listinfo/wengophone-devel

Reply via email to