1998-08-28 14:04:48 +00:00
# include <stdio.h>
# include <string.h>
1999-03-27 19:44:51 +00:00
# include <malloc.h>
# include <errno.h>
1998-08-30 21:08:44 +00:00
# include "../include/asoundlib.h"
1998-08-28 14:04:48 +00:00
1998-11-27 15:07:56 +00:00
const char * get_type ( unsigned int type )
1998-08-28 14:04:48 +00:00
{
1998-11-27 15:07:56 +00:00
switch ( type ) {
1999-03-27 19:44:51 +00:00
case SND_SW_TYPE_BOOLEAN :
1998-11-27 15:07:56 +00:00
return " Boolean " ;
1999-03-27 19:44:51 +00:00
case SND_SW_TYPE_BYTE :
1998-11-27 15:07:56 +00:00
return " Byte " ;
1999-03-27 19:44:51 +00:00
case SND_SW_TYPE_WORD :
1998-11-27 15:07:56 +00:00
return " Word " ;
1999-03-27 19:44:51 +00:00
case SND_SW_TYPE_DWORD :
return " Double Word " ;
case SND_SW_TYPE_LIST :
return " List " ;
case SND_SW_TYPE_LIST_ITEM :
return " List Item " ;
case SND_SW_TYPE_USER :
1998-11-27 15:07:56 +00:00
return " User " ;
default :
return " Unknown " ;
}
1998-08-28 14:04:48 +00:00
}
2000-03-01 18:12:30 +00:00
const char * get_interface ( int iface )
1998-08-28 14:04:48 +00:00
{
2000-03-01 18:12:30 +00:00
switch ( iface ) {
case SND_CTL_IFACE_CONTROL :
1999-03-27 19:44:51 +00:00
return " control " ;
2000-03-01 18:12:30 +00:00
case SND_CTL_IFACE_MIXER :
1999-03-27 19:44:51 +00:00
return " mixer " ;
2000-03-01 18:12:30 +00:00
case SND_CTL_IFACE_PCM :
return " pcm " ;
case SND_CTL_IFACE_RAWMIDI :
return " rawmidi " ;
1999-03-27 19:44:51 +00:00
default :
return " unknown " ;
}
}
1998-08-28 14:04:48 +00:00
2000-03-01 18:12:30 +00:00
void print_switch ( snd_ctl_t * ctl_handle , char * space , char * prefix , snd_switch_t * sw )
1999-03-27 19:44:51 +00:00
{
snd_switch_t sw1 ;
int low , err ;
printf ( " %s%s : '%s' [%s] \n " , space , prefix , sw - > name , get_type ( sw - > type ) ) ;
if ( sw - > type = = SND_SW_TYPE_LIST ) {
for ( low = sw - > low ; low < = sw - > high ; low + + ) {
memcpy ( & sw1 , sw , sizeof ( sw1 ) ) ;
sw1 . type = SND_SW_TYPE_LIST_ITEM ;
sw1 . low = sw1 . high = low ;
2000-03-01 18:12:30 +00:00
if ( ( err = snd_ctl_switch_read ( ctl_handle , & sw1 ) ) < 0 ) {
2000-05-27 16:52:17 +00:00
printf ( " Switch list item read failed for %s interface and device %i stream %i: %s \n " , get_interface ( sw - > iface ) , sw - > device , sw - > stream , snd_strerror ( err ) ) ;
1998-11-27 15:07:56 +00:00
continue ;
}
1999-03-27 19:44:51 +00:00
printf ( " %s%s : '%s' [%s] {%s} \n " , space , prefix , sw1 . name , get_type ( sw1 . type ) , sw1 . value . item ) ;
1998-11-27 15:07:56 +00:00
}
}
1999-03-27 19:44:51 +00:00
}
1998-08-28 14:04:48 +00:00
2000-05-27 16:52:17 +00:00
void process ( snd_ctl_t * ctl_handle , char * space , char * prefix , int iface , int device , int stream )
1999-03-27 19:44:51 +00:00
{
snd_switch_list_t list ;
snd_switch_t sw ;
int err , idx ;
1998-08-28 14:04:48 +00:00
1999-03-27 19:44:51 +00:00
bzero ( & list , sizeof ( list ) ) ;
2000-03-01 18:12:30 +00:00
list . iface = iface ;
list . device = device ;
2000-05-27 16:52:17 +00:00
list . stream = stream ;
2000-03-01 18:12:30 +00:00
if ( ( err = snd_ctl_switch_list ( ctl_handle , & list ) ) < 0 ) {
printf ( " Switch listing failed for the %s interface and the device %i: %s \n " , get_interface ( iface ) , device , snd_strerror ( err ) ) ;
1999-03-27 19:44:51 +00:00
return ;
}
if ( list . switches_over < = 0 )
return ;
list . switches_size = list . switches_over + 16 ;
list . switches = list . switches_over = 0 ;
list . pswitches = malloc ( sizeof ( snd_switch_list_item_t ) * list . switches_size ) ;
if ( ! list . pswitches ) {
printf ( " No enough memory... (%i switches) \n " , list . switches_size ) ;
return ;
}
2000-03-01 18:12:30 +00:00
if ( ( err = snd_ctl_switch_list ( ctl_handle , & list ) ) < 0 ) {
printf ( " Second switch listing failed for the %s interface and the device %i: %s \n " , get_interface ( iface ) , device , snd_strerror ( err ) ) ;
1999-03-27 19:44:51 +00:00
return ;
}
for ( idx = 0 ; idx < list . switches ; idx + + ) {
bzero ( & sw , sizeof ( sw ) ) ;
2000-03-01 18:12:30 +00:00
sw . iface = iface ;
sw . device = device ;
2000-05-27 16:52:17 +00:00
sw . stream = stream ;
1999-03-27 19:44:51 +00:00
strncpy ( sw . name , list . pswitches [ idx ] . name , sizeof ( sw . name ) ) ;
2000-03-01 18:12:30 +00:00
if ( ( err = snd_ctl_switch_read ( ctl_handle , & sw ) ) < 0 ) {
2000-05-27 16:52:17 +00:00
printf ( " Switch read failed for the %s interface and the device %i stream %i: %s \n " , get_interface ( iface ) , device , stream , snd_strerror ( err ) ) ;
1999-03-27 19:44:51 +00:00
continue ;
1998-11-27 15:07:56 +00:00
}
2000-03-01 18:12:30 +00:00
print_switch ( ctl_handle , space , prefix , & sw ) ;
1998-11-27 15:07:56 +00:00
}
1999-03-27 19:44:51 +00:00
free ( list . pswitches ) ;
}
1999-06-03 21:41:29 +00:00
int main ( void )
1999-03-27 19:44:51 +00:00
{
2000-03-01 18:12:30 +00:00
snd_ctl_t * ctl_handle ;
1999-03-27 19:44:51 +00:00
int cards , card , err , idx ;
snd_ctl_hw_info_t info ;
1998-08-28 14:04:48 +00:00
1999-03-27 19:44:51 +00:00
cards = snd_cards ( ) ;
printf ( " Detected %i soundcard%s... \n " , cards , cards > 1 ? " s " : " " ) ;
if ( cards < = 0 ) {
printf ( " Giving up... \n " ) ;
1999-06-03 21:41:29 +00:00
return 0 ;
1999-03-27 19:44:51 +00:00
}
/* control interface */
1998-11-27 15:07:56 +00:00
for ( card = 0 ; card < cards ; card + + ) {
1999-03-27 19:44:51 +00:00
if ( ( err = snd_ctl_open ( & ctl_handle , card ) ) < 0 ) {
1998-11-27 15:07:56 +00:00
printf ( " CTL open error: %s \n " , snd_strerror ( err ) ) ;
continue ;
}
1999-03-27 19:44:51 +00:00
if ( ( err = snd_ctl_hw_info ( ctl_handle , & info ) ) < 0 ) {
printf ( " HWINFO error: %s \n " , snd_strerror ( err ) ) ;
1998-11-27 15:07:56 +00:00
continue ;
}
1999-03-27 19:44:51 +00:00
printf ( " CARD %i: \n " , card ) ;
2000-03-01 18:12:30 +00:00
process ( ctl_handle , " " , " Control " , SND_CTL_IFACE_CONTROL , 0 , 0 ) ;
1999-03-27 19:44:51 +00:00
for ( idx = 0 ; idx < info . mixerdevs ; idx + + )
2000-03-01 18:12:30 +00:00
process ( ctl_handle , " " , " Mixer " , SND_CTL_IFACE_MIXER , idx , 0 ) ;
1999-03-27 19:44:51 +00:00
for ( idx = 0 ; idx < info . pcmdevs ; idx + + ) {
2000-05-27 16:52:17 +00:00
process ( ctl_handle , " " , " PCM playback " , SND_CTL_IFACE_PCM , idx , SND_PCM_STREAM_PLAYBACK ) ;
process ( ctl_handle , " " , " PCM capture " , SND_CTL_IFACE_PCM , idx , SND_PCM_STREAM_CAPTURE ) ;
1998-11-27 15:07:56 +00:00
}
1999-03-27 19:44:51 +00:00
snd_ctl_close ( ctl_handle ) ;
1998-11-27 15:07:56 +00:00
}
1999-06-03 21:41:29 +00:00
return 0 ;
1998-08-28 14:04:48 +00:00
}