Skip to content

Commit 6272e2b

Browse files
committed
try all sound cards in reverse order in case of open failure
1 parent c2dcdf2 commit 6272e2b

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

pcm.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,25 @@ void initPcmDevice() {
8484

8585
gtk_combo_box_set_active(GTK_COMBO_BOX(cardcombo), 0);
8686

87-
if (cardnum == 0) {
88-
sprintf(pcm_name,"default");
89-
} else {
90-
sprintf(pcm_name,"hw:%d",cardnum-1);
91-
}
92-
9387
snd_pcm_hw_params_alloca(&hwparams);
9488

95-
if (snd_pcm_open(&pcm_handle, pcm_name, PcmInStream, 0) < 0) {
96-
fprintf(stderr, "ALSA: Error opening PCM device %s\n", pcm_name);
97-
exit(EXIT_FAILURE);
89+
while (true) {
90+
if (cardnum == 0) {
91+
sprintf(pcm_name,"default");
92+
} else {
93+
sprintf(pcm_name,"hw:%d",cardnum-1);
94+
}
95+
96+
if (snd_pcm_open(&pcm_handle, pcm_name, PcmInStream, 0) < 0) {
97+
fprintf(stderr, "ALSA: Error opening PCM device %s\n", pcm_name);
98+
if (cardnum == 0) {
99+
exit(EXIT_FAILURE);
100+
} else {
101+
cardnum--;
102+
}
103+
} else {
104+
break;
105+
}
98106
}
99107

100108
/* Init hwparams with full configuration space */

0 commit comments

Comments
 (0)