1 #include <stdio.h>
2 #include <string.h>
3 #include "../include/asoundlib.h"
4
main(void)5 int main(void)
6 {
7 int idx, dev, err;
8 snd_ctl_t *handle;
9 snd_ctl_card_info_t *info;
10 snd_pcm_info_t *pcminfo;
11 snd_rawmidi_info_t *rawmidiinfo;
12 char str[128];
13
14 snd_ctl_card_info_alloca(&info);
15 snd_pcm_info_alloca(&pcminfo);
16 snd_rawmidi_info_alloca(&rawmidiinfo);
17
18 idx = -1;
19 while (1) {
20 if ((err = snd_card_next(&idx)) < 0) {
21 printf("Card next error: %s\n", snd_strerror(err));
22 break;
23 }
24 if (idx < 0)
25 break;
26 sprintf(str, "hw:CARD=%i", idx);
27 if ((err = snd_ctl_open(&handle, str, 0)) < 0) {
28 printf("Open error: %s\n", snd_strerror(err));
29 continue;
30 }
31 if ((err = snd_ctl_card_info(handle, info)) < 0) {
32 printf("HW info error: %s\n", snd_strerror(err));
33 continue;
34 }
35 printf("Soundcard #%i:\n", idx + 1);
36 printf(" card - %i\n", snd_ctl_card_info_get_card(info));
37 printf(" id - '%s'\n", snd_ctl_card_info_get_id(info));
38 printf(" driver - '%s'\n", snd_ctl_card_info_get_driver(info));
39 printf(" name - '%s'\n", snd_ctl_card_info_get_name(info));
40 printf(" longname - '%s'\n", snd_ctl_card_info_get_longname(info));
41 printf(" mixername - '%s'\n", snd_ctl_card_info_get_mixername(info));
42 printf(" components - '%s'\n", snd_ctl_card_info_get_components(info));
43 dev = -1;
44 while (1) {
45 snd_pcm_sync_id_t sync;
46 if ((err = snd_ctl_pcm_next_device(handle, &dev)) < 0) {
47 printf(" PCM next device error: %s\n", snd_strerror(err));
48 break;
49 }
50 if (dev < 0)
51 break;
52 snd_pcm_info_set_device(pcminfo, dev);
53 snd_pcm_info_set_subdevice(pcminfo, 0);
54 snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_PLAYBACK);
55 if ((err = snd_ctl_pcm_info(handle, pcminfo)) < 0) {
56 printf(" PCM info error: %s\n", snd_strerror(err));
57 continue;
58 }
59 printf("PCM info, device #%i:\n", dev);
60 printf(" device - %i\n", snd_pcm_info_get_device(pcminfo));
61 printf(" subdevice - %i\n", snd_pcm_info_get_subdevice(pcminfo));
62 printf(" stream - %i\n", snd_pcm_info_get_stream(pcminfo));
63 printf(" card - %i\n", snd_pcm_info_get_card(pcminfo));
64 printf(" id - '%s'\n", snd_pcm_info_get_id(pcminfo));
65 printf(" name - '%s'\n", snd_pcm_info_get_name(pcminfo));
66 printf(" subdevice name - '%s'\n", snd_pcm_info_get_subdevice_name(pcminfo));
67 printf(" class - 0x%x\n", snd_pcm_info_get_class(pcminfo));
68 printf(" subclass - 0x%x\n", snd_pcm_info_get_subclass(pcminfo));
69 printf(" subdevices count - %i\n", snd_pcm_info_get_subdevices_count(pcminfo));
70 printf(" subdevices avail - %i\n", snd_pcm_info_get_subdevices_avail(pcminfo));
71 sync = snd_pcm_info_get_sync(pcminfo);
72 printf(" sync - 0x%x,0x%x,0x%x,0x%x\n", sync.id32[0], sync.id32[1], sync.id32[2], sync.id32[3]);
73 }
74 dev = -1;
75 while (1) {
76 if ((err = snd_ctl_rawmidi_next_device(handle, &dev)) < 0) {
77 printf(" RAWMIDI next device error: %s\n", snd_strerror(err));
78 break;
79 }
80 if (dev < 0)
81 break;
82 snd_rawmidi_info_set_device(rawmidiinfo, dev);
83 snd_rawmidi_info_set_subdevice(rawmidiinfo, 0);
84 snd_rawmidi_info_set_stream(rawmidiinfo, SND_RAWMIDI_STREAM_OUTPUT);
85 if ((err = snd_ctl_rawmidi_info(handle, rawmidiinfo)) < 0) {
86 printf(" RAWMIDI info error: %s\n", snd_strerror(err));
87 continue;
88 }
89 printf("RAWMIDI info, device #%i:\n", dev);
90 printf(" device - %i\n", snd_rawmidi_info_get_device(rawmidiinfo));
91 printf(" subdevice - %i\n", snd_rawmidi_info_get_subdevice(rawmidiinfo));
92 printf(" stream - %i\n", snd_rawmidi_info_get_stream(rawmidiinfo));
93 printf(" card - %i\n", snd_rawmidi_info_get_card(rawmidiinfo));
94 printf(" flags - 0x%x\n", snd_rawmidi_info_get_flags(rawmidiinfo));
95 printf(" id - '%s'\n", snd_rawmidi_info_get_id(rawmidiinfo));
96 printf(" name - '%s'\n", snd_rawmidi_info_get_name(rawmidiinfo));
97 printf(" subname - '%s'\n", snd_rawmidi_info_get_subdevice_name(rawmidiinfo));
98 printf(" subdevices count - %i\n", snd_rawmidi_info_get_subdevices_count(rawmidiinfo));
99 printf(" subdevices avail - %i\n", snd_rawmidi_info_get_subdevices_avail(rawmidiinfo));
100 }
101 snd_ctl_close(handle);
102 }
103
104 snd_config_update_free_global();
105 return 0;
106 }
107