1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
diff -ru pwlib-orig/plugins/sound_alsa/sound_alsa.cxx pwlib/plugins/sound_alsa/sound_alsa.cxx
--- pwlib-orig/plugins/sound_alsa/sound_alsa.cxx 2004-03-13 13:36:14.000000000 +0100
+++ pwlib/plugins/sound_alsa/sound_alsa.cxx 2004-10-21 18:33:38.562610536 +0200
@@ -28,6 +28,21 @@
* Contributor(s): /
*
* $Log: sound_alsa.cxx,v $
+ * Revision 1.21 2004/10/18 11:43:39 dsandras
+ * Use Capture instead of Mic when changing the volume. Use the correct mixer when using the Default device.
+ *
+ * Revision 1.20 2004/10/14 19:30:16 dsandras
+ * Removed DMIX and DSNOOP plugins and added support for DEFAULT as it is the correcti way to do things.
+ *
+ * Revision 1.19 2004/08/30 21:09:41 dsandras
+ * Added DSNOOP plugin support.
+ *
+ * Revision 1.18 2004/05/14 10:15:26 dominance
+ * Fixes direct opening of sound output devices. The list of devices does no longer return NULL in that case. Patch provided by Julien Puydt <julien.puydt@laposte.net>.
+ *
+ * Revision 1.17 2004/04/03 10:33:45 dsandras
+ * Use PStringToOrdinal to store the detected devices, that fixes problems if there is a discontinuity in the succession of soundcard ID's. For example the user has card ID 1 and 3, but not 2.
+ *
* Revision 1.16 2004/03/13 12:36:14 dsandras
* Added support for DMIX plugin output.
*
@@ -81,8 +96,8 @@
PCREATE_SOUND_PLUGIN(ALSA, PSoundChannelALSA)
-static PStringArray playback_devices;
-static PStringArray capture_devices;
+static PStringToOrdinal playback_devices;
+static PStringToOrdinal capture_devices;
///////////////////////////////////////////////////////////////////////////////
@@ -119,8 +134,9 @@
}
-PStringArray PSoundChannelALSA::GetDeviceNames (Directions dir)
+void PSoundChannelALSA::UpdateDictionary (Directions dir)
{
+
int card = -1, dev = -1;
snd_ctl_t *handle = NULL;
@@ -134,12 +150,12 @@
if (dir == Recorder) {
stream = SND_PCM_STREAM_CAPTURE;
- capture_devices = PStringArray ();
+ capture_devices = PStringToOrdinal ();
}
else {
stream = SND_PCM_STREAM_PLAYBACK;
- playback_devices = PStringArray ();
+ playback_devices = PStringToOrdinal ();
}
snd_ctl_card_info_alloca (&info);
@@ -148,7 +164,7 @@
/* No sound card found */
if (snd_card_next (&card) < 0 || card < 0) {
- return PStringArray ();
+ return;
}
@@ -176,13 +192,11 @@
snd_card_get_name (card, &name);
if (dir == Recorder) {
- if (capture_devices.GetStringsIndex (name) == P_MAX_INDEX)
- capture_devices.AppendString (name);
+ capture_devices.SetAt (name, card);
}
else {
- if (playback_devices.GetStringsIndex (name) == P_MAX_INDEX)
- playback_devices.AppendString (name);
+ playback_devices.SetAt (name, card);
}
free (name);
@@ -193,17 +207,27 @@
snd_ctl_close(handle);
snd_card_next (&card);
}
+}
-
- if (dir == Recorder)
- return capture_devices;
- else {
+PStringArray PSoundChannelALSA::GetDeviceNames (Directions dir)
+{
+ PStringArray devices;
+ PStringToOrdinal devices_dict;
- if (playback_devices.GetSize () > 0)
- playback_devices += "DMIX Plugin";
+ if (dir == Recorder)
+ devices_dict = capture_devices;
+ else
+ devices_dict = playback_devices;
+
+ UpdateDictionary (dir);
+
+ if (devices_dict.GetSize () > 0)
+ devices += "Default";
+
+ for (PINDEX j = 0 ; j < devices_dict.GetSize () ; j++)
+ devices += devices_dict.GetKeyAt (j);
- return playback_devices;
- }
+ return devices;
}
@@ -223,7 +247,7 @@
unsigned _bitsPerSample)
{
PString real_device_name;
- PINDEX i = 0;
+ POrdinalKey *i = NULL;
snd_pcm_stream_t stream;
Close();
@@ -236,21 +260,31 @@
stream = SND_PCM_STREAM_PLAYBACK;
/* Open in NONBLOCK mode */
- if (_dir != Recorder && _device == "DMIX Plugin") {
+ if (_device == "Default") {
- real_device_name = "plug:dmix";
+ real_device_name = "default";
+ card_nr = -2;
}
- else if ((i = (_dir == Recorder) ? capture_devices.GetStringsIndex (_device) : playback_devices.GetStringsIndex (_device)) != P_MAX_INDEX) {
+ else {
+
+ if ((_dir == Recorder && capture_devices.IsEmpty ())
+ || (_dir == Player && playback_devices.IsEmpty ()))
+ UpdateDictionary (_dir);
+
+ i = (_dir == Recorder) ? capture_devices.GetAt (_device) : playback_devices.GetAt (_device);
- real_device_name = "plughw:" + PString (i);
- card_nr = i;
+ if (i) {
+
+ real_device_name = "plughw:" + PString (*i);
+ card_nr = *i;
+ }
+ else {
+
+ PTRACE (1, "ALSA\tDevice not found");
+ return FALSE;
+ }
}
- else {
- PTRACE (1, "ALSA\tDevice unavailable");
- return FALSE;
- }
-
if (snd_pcm_open (&os_handle, real_device_name, stream, SND_PCM_NONBLOCK) < 0) {
PTRACE (1, "ALSA\tOpen Failed");
@@ -735,7 +769,7 @@
snd_mixer_elem_t *elem;
snd_mixer_selem_id_t *sid;
- const char *play_mix_name = (direction == Player) ? "PCM": "Mic";
+ const char *play_mix_name = (direction == Player) ? "PCM": "Capture";
PString card_name;
long pmin = 0, pmax = 0;
@@ -744,7 +778,10 @@
if (!os_handle)
return FALSE;
- card_name = "hw:" + PString (card_nr);
+ if (card_nr == -2)
+ card_name = "default";
+ else
+ card_name = "hw:" + PString (card_nr);
//allocate simple id
snd_mixer_selem_id_alloca (&sid);
@@ -796,23 +833,39 @@
return FALSE;
}
- snd_mixer_selem_get_playback_volume_range (elem, &pmin, &pmax);
if (set) {
-
- vol = (set_vol * (pmax?pmax:31)) / 100;
- snd_mixer_selem_set_playback_volume (elem,
- SND_MIXER_SCHN_FRONT_LEFT, vol);
- snd_mixer_selem_set_playback_volume (elem,
- SND_MIXER_SCHN_FRONT_RIGHT, vol);
+ if (direction == Player) {
+
+ snd_mixer_selem_get_playback_volume_range (elem, &pmin, &pmax);
+ vol = (set_vol * (pmax?pmax:31)) / 100;
+ snd_mixer_selem_set_playback_volume_all (elem, vol);
+ }
+ else {
+
+ snd_mixer_selem_get_capture_volume_range (elem, &pmin, &pmax);
+ vol = (set_vol * (pmax?pmax:31)) / 100;
+ snd_mixer_selem_set_capture_volume_all (elem, vol);
+ }
PTRACE (4, "Set volume to " << vol);
}
else {
- snd_mixer_selem_get_playback_volume (elem,
- SND_MIXER_SCHN_FRONT_LEFT, &vol);
+ if (direction == Player) {
+
+ snd_mixer_selem_get_playback_volume_range (elem, &pmin, &pmax);
+ snd_mixer_selem_get_playback_volume (elem, SND_MIXER_SCHN_FRONT_LEFT,
+ &vol);
+ }
+ else {
+
+ snd_mixer_selem_get_capture_volume_range (elem, &pmin, &pmax);
+ snd_mixer_selem_get_capture_volume (elem, SND_MIXER_SCHN_FRONT_LEFT,
+ &vol);
+ }
get_vol = (vol * 100) / (pmax?pmax:31);
+
PTRACE (4, "Got volume " << vol);
}
Only in pwlib/plugins/sound_alsa: .sound_alsa.cxx-patch.swp
diff -ru pwlib-orig/plugins/sound_alsa/sound_alsa.h pwlib/plugins/sound_alsa/sound_alsa.h
--- pwlib-orig/plugins/sound_alsa/sound_alsa.h 2003-12-28 16:10:35.000000000 +0100
+++ pwlib/plugins/sound_alsa/sound_alsa.h 2004-10-21 18:35:51.559391952 +0200
@@ -89,7 +89,8 @@
BOOL IsOpen() const;
private:
-
+
+ static void UpdateDictionary(PSoundChannel::Directions);
BOOL Volume (BOOL, unsigned, unsigned &);
PSoundChannel::Directions direction;
PString device;
|