Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/next/external/cache/sources/tinyalsa/tinypcminfo.c
Views: 3959
/* tinypcminfo.c1**2** Copyright 2012, The Android Open Source Project3**4** Redistribution and use in source and binary forms, with or without5** modification, are permitted provided that the following conditions are met:6** * Redistributions of source code must retain the above copyright7** notice, this list of conditions and the following disclaimer.8** * Redistributions in binary form must reproduce the above copyright9** notice, this list of conditions and the following disclaimer in the10** documentation and/or other materials provided with the distribution.11** * Neither the name of The Android Open Source Project nor the names of12** its contributors may be used to endorse or promote products derived13** from this software without specific prior written permission.14**15** THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND16** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18** ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE19** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR21** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER22** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH25** DAMAGE.26*/2728#include <tinyalsa/asoundlib.h>29#include <stdio.h>30#include <stdlib.h>31#include <string.h>3233#ifndef ARRAY_SIZE34#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))35#endif3637/* The format_lookup is in order of SNDRV_PCM_FORMAT_##index and38* matches the grouping in sound/asound.h. Note this is not39* continuous and has an empty gap from (25 - 30).40*/41static const char *format_lookup[] = {42/*[0] =*/ "S8",43"U8",44"S16_LE",45"S16_BE",46"U16_LE",47"U16_BE",48"S24_LE",49"S24_BE",50"U24_LE",51"U24_BE",52"S32_LE",53"S32_BE",54"U32_LE",55"U32_BE",56"FLOAT_LE",57"FLOAT_BE",58"FLOAT64_LE",59"FLOAT64_BE",60"IEC958_SUBFRAME_LE",61"IEC958_SUBFRAME_BE",62"MU_LAW",63"A_LAW",64"IMA_ADPCM",65"MPEG",66/*[24] =*/ "GSM",67[31] = "SPECIAL",68"S24_3LE",69"S24_3BE",70"U24_3LE",71"U24_3BE",72"S20_3LE",73"S20_3BE",74"U20_3LE",75"U20_3BE",76"S18_3LE",77"S18_3BE",78"U18_3LE",79/*[43] =*/ "U18_3BE",80#if 081/* recent additions, may not be present on local asound.h */82"G723_24",83"G723_24_1B",84"G723_40",85"G723_40_1B",86"DSD_U8",87"DSD_U16_LE",88#endif89};9091/* Returns a human readable name for the format associated with bit_index,92* NULL if bit_index is not known.93*/94char *pcm_get_format_name(unsigned bit_index)95{96return bit_index < ARRAY_SIZE(format_lookup) ? format_lookup[bit_index] : NULL;97}9899int main(int argc, char **argv)100{101unsigned int device = 0;102unsigned int card = 0;103int i;104105if (argc < 3) {106fprintf(stderr, "Usage: %s -D card -d device\n", argv[0]);107return 1;108}109110/* parse command line arguments */111argv += 1;112while (*argv) {113if (strcmp(*argv, "-D") == 0) {114argv++;115if (*argv)116card = atoi(*argv);117}118if (strcmp(*argv, "-d") == 0) {119argv++;120if (*argv)121device = atoi(*argv);122}123if (*argv)124argv++;125}126127printf("Info for card %d, device %d:\n", card, device);128129for (i = 0; i < 2; i++) {130struct pcm_params *params;131struct pcm_mask *m;132unsigned int min;133unsigned int max;134135printf("\nPCM %s:\n", i == 0 ? "out" : "in");136137params = pcm_params_get(card, device, i == 0 ? PCM_OUT : PCM_IN);138if (params == NULL) {139printf("Device does not exist.\n");140continue;141}142143m = pcm_params_get_mask(params, PCM_PARAM_ACCESS);144if (m) { /* bitmask, refer to SNDRV_PCM_ACCESS_*, generally interleaved */145printf(" Access:\t%#08x\n", m->bits[0]);146}147m = pcm_params_get_mask(params, PCM_PARAM_FORMAT);148if (m) { /* bitmask, refer to: SNDRV_PCM_FORMAT_* */149unsigned j, k, count = 0;150const unsigned bitcount = sizeof(m->bits[0]) * 8;151152/* we only check first two format masks (out of 8) - others are zero. */153printf(" Format[0]:\t%#08x\n", m->bits[0]);154printf(" Format[1]:\t%#08x\n", m->bits[1]);155156/* print friendly format names, if they exist */157for (k = 0; k < 2; ++k) {158for (j = 0; j < bitcount; ++j) {159const char *name;160161if (m->bits[k] & (1 << j)) {162name = pcm_get_format_name(j + k*bitcount);163if (name) {164if (count++ == 0) {165printf(" Format Name:\t");166} else {167printf (", ");168}169printf("%s", name);170}171}172}173}174if (count) {175printf("\n");176}177}178m = pcm_params_get_mask(params, PCM_PARAM_SUBFORMAT);179if (m) { /* bitmask, should be 1: SNDRV_PCM_SUBFORMAT_STD */180printf(" Subformat:\t%#08x\n", m->bits[0]);181}182min = pcm_params_get_min(params, PCM_PARAM_RATE);183max = pcm_params_get_max(params, PCM_PARAM_RATE);184printf(" Rate:\tmin=%uHz\tmax=%uHz\n", min, max);185min = pcm_params_get_min(params, PCM_PARAM_CHANNELS);186max = pcm_params_get_max(params, PCM_PARAM_CHANNELS);187printf(" Channels:\tmin=%u\t\tmax=%u\n", min, max);188min = pcm_params_get_min(params, PCM_PARAM_SAMPLE_BITS);189max = pcm_params_get_max(params, PCM_PARAM_SAMPLE_BITS);190printf(" Sample bits:\tmin=%u\t\tmax=%u\n", min, max);191min = pcm_params_get_min(params, PCM_PARAM_PERIOD_SIZE);192max = pcm_params_get_max(params, PCM_PARAM_PERIOD_SIZE);193printf(" Period size:\tmin=%u\t\tmax=%u\n", min, max);194min = pcm_params_get_min(params, PCM_PARAM_PERIODS);195max = pcm_params_get_max(params, PCM_PARAM_PERIODS);196printf("Period count:\tmin=%u\t\tmax=%u\n", min, max);197198pcm_params_free(params);199}200201return 0;202}203204205