From 44582b2fbe674da8fef272bf8f9551115ecd6a34 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Mon, 24 Aug 1998 16:23:22 +0000 Subject: [PATCH] New updated mixer interface and better protocol handling... --- include/config.h | 2 +- include/mixer.h | 8 ++++--- include/soundlib.h | 10 +++++---- include/version.h | 2 +- src/control/control.c | 3 ++- src/mixer/mixer.c | 51 ++++++++++++++++++++++++++++++++++++++----- src/pcm/pcm.c | 5 +++-- 7 files changed, 63 insertions(+), 18 deletions(-) diff --git a/include/config.h b/include/config.h index b6845796..103f1983 100644 --- a/include/config.h +++ b/include/config.h @@ -3,5 +3,5 @@ * Configuration header file for compilation of the ALSA driver */ -#define SND_LIB_VERSION "0.0.9" +#define SND_LIB_VERSION "0.0.10" /* #undef WORDS_BIGENDIAN */ diff --git a/include/mixer.h b/include/mixer.h index 38c0024d..b4026d36 100644 --- a/include/mixer.h +++ b/include/mixer.h @@ -8,7 +8,8 @@ typedef struct snd_mixer_callbacks { void *private_data; /* should be used by application */ void (*channel_was_changed)( void *private_data, int channel ); - void *reserved[15]; /* reserved for future use - must be NULL!!! */ + void (*switch_was_changed)( void *private_data, int switchn ); + void *reserved[14]; /* reserved for future use - must be NULL!!! */ } snd_mixer_callbacks_t; #ifdef __cplusplus @@ -25,8 +26,9 @@ int snd_mixer_channel( void *handle, const char *channel_id ); int snd_mixer_channel_info( void *handle, int channel, snd_mixer_channel_info_t *info ); int snd_mixer_channel_read( void *handle, int channel, snd_mixer_channel_t *data ); int snd_mixer_channel_write( void *handle, int channel, snd_mixer_channel_t *data ); -int snd_mixer_special_read( void *handle, snd_mixer_special_t *special ); -int snd_mixer_special_write( void *handle, snd_mixer_special_t *special ); +int snd_mixer_switches( void *handle ); +int snd_mixer_switch_read( void *handle, int switchn, snd_mixer_switch_t *data ); +int snd_mixer_switch_write( void *handle, int switchn, snd_mixer_switch_t *data ); int snd_mixer_read( void *handle, snd_mixer_callbacks_t *callbacks ); #ifdef __cplusplus diff --git a/include/soundlib.h b/include/soundlib.h index 681fe40b..fa845195 100644 --- a/include/soundlib.h +++ b/include/soundlib.h @@ -31,7 +31,7 @@ #define SOUNDLIB_VERSION_MAJOR 0 #define SOUNDLIB_VERSION_MINOR 0 -#define SOUNDLIB_VERSION_SUBMINOR 9 +#define SOUNDLIB_VERSION_SUBMINOR 10 #define SOUNDLIB_VERSION ( ( LIBULTRA_VERSION_MAJOR << 16 ) | ( LIBULTRA_VERSION_MINOR << 8 ) | LIB_ULTRA_VERSION_SUBMINOR ) /* @@ -89,7 +89,8 @@ int snd_ctl_mixer_info( void *handle, int dev, snd_mixer_info_t *info ); typedef struct snd_mixer_callbacks { void *private_data; /* should be used by application */ void (*channel_was_changed)( void *private_data, int channel ); - void *reserved[15]; /* reserved for future use - must be NULL!!! */ + void (*switch_was_changed)( void *private_data, int switchn ); + void *reserved[14]; /* reserved for future use - must be NULL!!! */ } snd_mixer_callbacks_t; #ifdef __cplusplus @@ -106,8 +107,9 @@ int snd_mixer_channel( void *handle, const char *channel_id ); int snd_mixer_channel_info( void *handle, int channel, snd_mixer_channel_info_t *info ); int snd_mixer_channel_read( void *handle, int channel, snd_mixer_channel_t *data ); int snd_mixer_channel_write( void *handle, int channel, snd_mixer_channel_t *data ); -int snd_mixer_special_read( void *handle, snd_mixer_special_t *special ); -int snd_mixer_special_write( void *handle, snd_mixer_special_t *special ); +int snd_mixer_switches( void *handle ); +int snd_mixer_switch_read( void *handle, int switchn, snd_mixer_switch_t *data ); +int snd_mixer_switch_write( void *handle, int switchn, snd_mixer_switch_t *data ); int snd_mixer_read( void *handle, snd_mixer_callbacks_t *callbacks ); #ifdef __cplusplus diff --git a/include/version.h b/include/version.h index 8e0e73cb..8c777ae7 100644 --- a/include/version.h +++ b/include/version.h @@ -4,6 +4,6 @@ #define SOUNDLIB_VERSION_MAJOR 0 #define SOUNDLIB_VERSION_MINOR 0 -#define SOUNDLIB_VERSION_SUBMINOR 9 +#define SOUNDLIB_VERSION_SUBMINOR 10 #define SOUNDLIB_VERSION ( ( LIBULTRA_VERSION_MAJOR << 16 ) | ( LIBULTRA_VERSION_MINOR << 8 ) | LIB_ULTRA_VERSION_SUBMINOR ) diff --git a/src/control/control.c b/src/control/control.c index 6debff6b..a46ca0fc 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -49,7 +49,8 @@ int snd_ctl_open( void **handle, int card ) close( fd ); return -errno; } - if ( ver > SND_CTL_VERSION_MAX ) return -SND_ERROR_UNCOMPATIBLE_VERSION; + if ( SND_PROTOCOL_UNCOMPATIBLE( ver, SND_CTL_VERSION_MAX ) ) + return -SND_ERROR_UNCOMPATIBLE_VERSION; ctl = (snd_ctl_t *)calloc( 1, sizeof( snd_ctl_t ) ); if ( ctl == NULL ) { close( fd ); diff --git a/src/mixer/mixer.c b/src/mixer/mixer.c index 3f973acc..1cc3aefa 100644 --- a/src/mixer/mixer.c +++ b/src/mixer/mixer.c @@ -29,7 +29,7 @@ #include "soundlib.h" #define SND_FILE_MIXER "/dev/sndmixer%i%i" -#define SND_CTL_VERSION_MAX SND_PROTOCOL_VERSION( 1, 0, 0 ) +#define SND_MIXER_VERSION_MAX SND_PROTOCOL_VERSION( 1, 0, 1 ) typedef struct { int card; @@ -51,7 +51,8 @@ int snd_mixer_open( void **handle, int card, int device ) close( fd ); return -errno; } - if ( ver > SND_CTL_VERSION_MAX ) return -SND_ERROR_UNCOMPATIBLE_VERSION; + if ( SND_PROTOCOL_UNCOMPATIBLE( ver, SND_MIXER_VERSION_MAX ) ) + return -SND_ERROR_UNCOMPATIBLE_VERSION; mixer = (snd_mixer_t *)calloc( 1, sizeof( snd_mixer_t ) ); if ( mixer == NULL ) { close( fd ); @@ -176,24 +177,59 @@ int snd_mixer_channel_write( void *handle, int channel, snd_mixer_channel_t *dat return 0; } -int snd_mixer_special_read( void *handle, snd_mixer_special_t *special ) +int snd_mixer_switches( void *handle ) { snd_mixer_t *mixer; + int result; mixer = (snd_mixer_t *)handle; if ( !mixer ) return -EINVAL; - if ( ioctl( mixer -> fd, SND_MIXER_IOCTL_SPECIAL_READ, special ) < 0 ) + if ( ioctl( mixer -> fd, SND_MIXER_IOCTL_SWITCHES, &result ) < 0 ) + return -errno; + return result; +} + +int snd_mixer_switch( void *handle, const char *switch_id ) +{ + snd_mixer_t *mixer; + snd_mixer_switch_t uswitch; + int idx, switches, err; + + mixer = (snd_mixer_t *)handle; + if ( !mixer ) return -EINVAL; + /* bellow implementation isn't optimized for speed */ + /* info about switches should be cached in the snd_mixer_t structure */ + if ( (switches = snd_mixer_switches( handle )) < 0 ) + return switches; + for ( idx = 0; idx < switches; idx++ ) { + if ( (err = snd_mixer_switch_read( handle, idx, &uswitch )) < 0 ) + return err; + if ( !strncmp( switch_id, uswitch.name, sizeof( uswitch.name ) ) ) + return idx; + } + return -EINVAL; +} + +int snd_mixer_switch_read( void *handle, int switchn, snd_mixer_switch_t *data ) +{ + snd_mixer_t *mixer; + + mixer = (snd_mixer_t *)handle; + if ( !mixer ) return -EINVAL; + data -> switchn = switchn; + if ( ioctl( mixer -> fd, SND_MIXER_IOCTL_SWITCH_READ, data ) < 0 ) return -errno; return 0; } -int snd_mixer_special_write( void *handle, snd_mixer_special_t *special ) +int snd_mixer_switch_write( void *handle, int switchn, snd_mixer_switch_t *data ) { snd_mixer_t *mixer; mixer = (snd_mixer_t *)handle; if ( !mixer ) return -EINVAL; - if ( ioctl( mixer -> fd, SND_MIXER_IOCTL_SPECIAL_WRITE, special ) < 0 ) + data -> switchn = switchn; + if ( ioctl( mixer -> fd, SND_MIXER_IOCTL_SWITCH_WRITE, data ) < 0 ) return -errno; return 0; } @@ -217,6 +253,9 @@ int snd_mixer_read( void *handle, snd_mixer_callbacks_t *callbacks ) if ( cmd == 0 && callbacks -> channel_was_changed ) { callbacks -> channel_was_changed( callbacks -> private_data, (int)tmp ); } + if ( cmd == 1 && callbacks -> switch_was_changed ) { + callbacks -> switch_was_changed( callbacks -> private_data, (int)tmp ); + } } count += result >> 3; /* return only number of changes */ } diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 9687f7d1..470b9f79 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -12,7 +12,7 @@ #include "soundlib.h" #define SND_FILE_PCM "/dev/sndpcm%i%i" -#define SND_CTL_VERSION_MAX SND_PROTOCOL_VERSION( 1, 0, 0 ) +#define SND_PCM_VERSION_MAX SND_PROTOCOL_VERSION( 1, 0, 0 ) typedef struct { int card; @@ -34,7 +34,8 @@ int snd_pcm_open( void **handle, int card, int device, int mode ) close( fd ); return -errno; } - if ( ver > SND_CTL_VERSION_MAX ) return -SND_ERROR_UNCOMPATIBLE_VERSION; + if ( SND_PROTOCOL_UNCOMPATIBLE( ver, SND_PCM_VERSION_MAX ) ) + return -SND_ERROR_UNCOMPATIBLE_VERSION; pcm = (snd_pcm_t *)calloc( 1, sizeof( snd_pcm_t ) ); if ( pcm == NULL ) { close( fd ); -- 2.47.1