int main() { int val; printf("ALSA library version: %s\n", SND_LIB_VERSION_STR); printf("PCM stream types:\n"); for (val = 0; val <= SND_PCM_STREAM_LAST; val++) { printf(" %s\n", snd_pcm_stream_name((snd_pcm_stream_t)val)); } printf("PCM access types:\n"); for (val = 0; val <= SND_PCM_ACCESS_LAST; val++) { printf(" %s\n", snd_pcm_access_name((snd_pcm_access_t)val)); } printf("PCM formats:\n"); for (val = 0; val <= SND_PCM_STREAM_LAST; val++) { if (snd_pcm_format_name((snd_pcm_format_t)val) != NULL) { printf(" %s (%s)\n", snd_pcm_format_name((snd_pcm_format_t)val), snd_pcm_format_description((snd_pcm_format_t)val)); } } printf("\nPCM subformats:\n"); for (val = 0; val <= SND_PCM_SUBFORMAT_LAST; val++) { printf(" %s (%s)\n", snd_pcm_subformat_name((snd_pcm_subformat_t)val), snd_pcm_subformat_description((snd_pcm_subformat_t)val)); } return 0; }
int snd_pcm_dump_hw_setup(snd_pcm_t *pcm, snd_output_t *out) { snd_output_printf(out, " stream : %s\n", snd_pcm_stream_name(pcm->stream)); snd_output_printf(out, " access : %s\n", snd_pcm_access_name(pcm->access)); snd_output_printf(out, " format : %s\n", snd_pcm_format_name(pcm->format)); snd_output_printf(out, " subformat : %s\n", snd_pcm_subformat_name(pcm->subformat)); snd_output_printf(out, " channels : %u\n", pcm->channels); snd_output_printf(out, " rate : %u\n", pcm->rate); snd_output_printf(out, " exact rate : %g (%u/%u)\n", (pcm->hw_params.rate_den ? ((double) pcm->hw_params.rate_num / pcm->hw_params.rate_den) : 0.0), pcm->hw_params.rate_num, pcm->hw_params.rate_den); snd_output_printf(out, " msbits : %u\n", pcm->hw_params.msbits); snd_output_printf(out, " buffer_size : %lu\n", pcm->buffer_size); snd_output_printf(out, " period_size : %lu\n", pcm->period_size); snd_output_printf(out, " period_time : %u\n", pcm->period_time); #if 0 /* deprecated */ snd_output_printf(out, " tick_time : %u\n", pcm->tick_time); #endif return 0; }
int main(int argc, char **argv) { char *device = NULL; int stream = SND_PCM_STREAM_PLAYBACK; int format = SND_PCM_FORMAT_UNKNOWN; int channels = 0; int rate = 0; snd_pcm_t *pcm; int c; while ((c = getopt(argc, argv, "D:s:f:c:r:")) != -1) { switch (c) { case 'D': device = optarg; break; case 's': if (*optarg == 'c' || *optarg == 'C') stream = SND_PCM_STREAM_CAPTURE; else stream = SND_PCM_STREAM_PLAYBACK; break; case 'f': format = snd_pcm_format_value(optarg); break; case 'c': channels = atoi(optarg); break; case 'r': rate = atoi(optarg); break; default: usage(); return 1; } } if (argc <= optind) { usage(); return 1; } if (!device) { printf("No device is specified\n"); return 1; } if (snd_pcm_open(&pcm, device, stream, SND_PCM_NONBLOCK) < 0) { printf("Cannot open PCM stream %s for %s\n", device, snd_pcm_stream_name(stream)); return 1; } switch (*argv[optind]) { case 'q': return query_chmaps(pcm); case 'g': return get_chmap(pcm, format, channels, rate); case 's': return set_chmap(pcm, format, channels, rate, argc - optind - 1, argv + optind + 1); } usage(); return 1; }
static void device_list(snd_pcm_stream_t stream) { snd_ctl_t *handle; int card, err, dev, idx; snd_ctl_card_info_t *info; snd_pcm_info_t *pcminfo; snd_ctl_card_info_alloca(&info); snd_pcm_info_alloca(&pcminfo); card = -1; if (snd_card_next(&card) < 0 || card < 0) { error(_("no soundcards found...")); return; } printf(_("**** List of %s Hardware Devices ****\n"), snd_pcm_stream_name(stream)); while (card >= 0) { char name[32]; sprintf(name, "hw:%d", card); if ((err = snd_ctl_open(&handle, name, 0)) < 0) { error("control open (%i): %s", card, snd_strerror(err)); goto next_card; } if ((err = snd_ctl_card_info(handle, info)) < 0) { error("control hardware info (%i): %s", card, snd_strerror(err)); snd_ctl_close(handle); goto next_card; } dev = -1; while (1) { unsigned int count; if (snd_ctl_pcm_next_device(handle, &dev)<0) error("snd_ctl_pcm_next_device"); if (dev < 0) break; snd_pcm_info_set_device(pcminfo, dev); snd_pcm_info_set_subdevice(pcminfo, 0); snd_pcm_info_set_stream(pcminfo, stream); if ((err = snd_ctl_pcm_info(handle, pcminfo)) < 0) { if (err != -ENOENT) error("control digital audio info (%i): %s", card, snd_strerror(err)); continue; } printf(_("card %i: [%s,%i] %s [%s], device %i: %s [%s]\n"), card, name, dev, snd_ctl_card_info_get_id(info), snd_ctl_card_info_get_name(info), dev, snd_pcm_info_get_id(pcminfo), snd_pcm_info_get_name(pcminfo)); count = snd_pcm_info_get_subdevices_count(pcminfo); printf( _(" Subdevices: %i/%i\n"), snd_pcm_info_get_subdevices_avail(pcminfo), count); for (idx = 0; idx < (int)count; idx++) { snd_pcm_info_set_subdevice(pcminfo, idx); if ((err = snd_ctl_pcm_info(handle, pcminfo)) < 0) { error("control digital audio playback info (%i): %s", card, snd_strerror(err)); } else { printf(_(" Subdevice #%i: %s\n"), idx, snd_pcm_info_get_subdevice_name(pcminfo)); } } } snd_ctl_close(handle); next_card: if (snd_card_next(&card) < 0) { error("snd_card_next"); break; } } }