Blob Blame History Raw
/* Copyright 2005 Red Hat, Inc.
 *
 * This software may be freely redistributed under the terms of the GNU
 * public license.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */
#include <stdio.h>
#include <string.h>
#include <alsa/asoundlib.h>

int get_card_device(const char *p_device)
{
  int err;
  snd_ctl_t *handle;
  snd_ctl_card_info_t *info;

  snd_ctl_card_info_alloca(&info);

  if ((err = snd_ctl_open(&handle, "default", 0)) < 0) {
    fprintf(stderr,"Open error: %s\n", snd_strerror(err));
    return(0);
  }
  if ((err = snd_ctl_card_info(handle, info)) < 0) {
    fprintf(stderr,"HW info error: %s\n", snd_strerror(err));
    return(0);
  }

  return (snd_ctl_card_info_get_card(info));
}

int main(int argc, char *argv[])
{
  char *p_device = "default";
  int   card;

  if (argc > 1 && argv[1])
    p_device = argv[1];

  card = get_card_device(p_device);
  printf("%d",card);
  return (card);
}