Home | History | Annotate | Download | only in tinyalsa
      1 /* tinypcminfo.c
      2 **
      3 ** Copyright 2012, The Android Open Source Project
      4 **
      5 ** Redistribution and use in source and binary forms, with or without
      6 ** modification, are permitted provided that the following conditions are met:
      7 **     * Redistributions of source code must retain the above copyright
      8 **       notice, this list of conditions and the following disclaimer.
      9 **     * Redistributions in binary form must reproduce the above copyright
     10 **       notice, this list of conditions and the following disclaimer in the
     11 **       documentation and/or other materials provided with the distribution.
     12 **     * Neither the name of The Android Open Source Project nor the names of
     13 **       its contributors may be used to endorse or promote products derived
     14 **       from this software without specific prior written permission.
     15 **
     16 ** THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND
     17 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19 ** ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE
     20 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     23 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
     26 ** DAMAGE.
     27 */
     28 
     29 #include <tinyalsa/asoundlib.h>
     30 #include <stdio.h>
     31 #include <stdlib.h>
     32 #include <string.h>
     33 
     34 int main(int argc, char **argv)
     35 {
     36     unsigned int device = 0;
     37     unsigned int card = 0;
     38     int i;
     39 
     40     if (argc < 3) {
     41         fprintf(stderr, "Usage: %s -D card -d device\n", argv[0]);
     42         return 1;
     43     }
     44 
     45     /* parse command line arguments */
     46     argv += 1;
     47     while (*argv) {
     48         if (strcmp(*argv, "-D") == 0) {
     49             argv++;
     50             if (*argv)
     51                 card = atoi(*argv);
     52         }
     53         if (strcmp(*argv, "-d") == 0) {
     54             argv++;
     55             if (*argv)
     56                 device = atoi(*argv);
     57         }
     58         if (*argv)
     59             argv++;
     60     }
     61 
     62     printf("Info for card %d, device %d:\n", card, device);
     63 
     64     for (i = 0; i < 2; i++) {
     65         struct pcm_params *params;
     66         unsigned int min;
     67         unsigned int max;
     68 
     69         printf("\nPCM %s:\n", i == 0 ? "out" : "in");
     70 
     71         params = pcm_params_get(card, device, i == 0 ? PCM_OUT : PCM_IN);
     72         if (params == NULL) {
     73             printf("Device does not exist.\n");
     74             continue;
     75         }
     76 
     77         min = pcm_params_get_min(params, PCM_PARAM_RATE);
     78         max = pcm_params_get_max(params, PCM_PARAM_RATE);
     79         printf("        Rate:\tmin=%uHz\tmax=%uHz\n", min, max);
     80         min = pcm_params_get_min(params, PCM_PARAM_CHANNELS);
     81         max = pcm_params_get_max(params, PCM_PARAM_CHANNELS);
     82         printf("    Channels:\tmin=%u\t\tmax=%u\n", min, max);
     83         min = pcm_params_get_min(params, PCM_PARAM_SAMPLE_BITS);
     84         max = pcm_params_get_max(params, PCM_PARAM_SAMPLE_BITS);
     85         printf(" Sample bits:\tmin=%u\t\tmax=%u\n", min, max);
     86         min = pcm_params_get_min(params, PCM_PARAM_PERIOD_SIZE);
     87         max = pcm_params_get_max(params, PCM_PARAM_PERIOD_SIZE);
     88         printf(" Period size:\tmin=%u\t\tmax=%u\n", min, max);
     89         min = pcm_params_get_min(params, PCM_PARAM_PERIODS);
     90         max = pcm_params_get_max(params, PCM_PARAM_PERIODS);
     91         printf("Period count:\tmin=%u\t\tmax=%u\n", min, max);
     92 
     93         pcm_params_free(params);
     94     }
     95 
     96     return 0;
     97 }
     98