main.c
#include ……
……
#ifdef ACR320_V3
#define PORT "Speaker"
#else
#define PORT "Headphone"
#endif
static char *command;
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
#define error(...) do {\
fprintf(stderr, "%s: %s:%s:%d: ",command,__FILE__, __FUNCTION__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
putc('\n', stderr); \
} while (0)
#else
#define error(args...) do {\
fprintf(stderr, "%s:%s:%s:%d: ",command,__FILE__, __FUNCTION__, __LINE__); \
fprintf(stderr, ##args); \
putc('\n', stderr); \
} while (0)
#endif
int volume_set(void)
{
int err;
snd_mixer_t *mixerFD;
snd_mixer_elem_t *elem;
Volume_t * p = &v_state;
command = "amixer";
if((err = snd_mixer_open(&mixerFD,0))<0){
error("Mixer %s open error: %s\n", PORT, snd_strerror(err));
return err;
}
if((err = snd_mixer_attach(mixerFD,"default"))<0){
error("Mixer %s attach error: %s\n", PORT, snd_strerror(err));
snd_mixer_close(mixerFD);
return err;
}
if((err = snd_mixer_selem_register(mixerFD,0,0))<0){
error("Mixer %s register error: %s\n", PORT, snd_strerror(err));
snd_mixer_close(mixerFD);
return err;
}
if((err = snd_mixer_load(mixerFD))<0){
error("Mixer %s load error: %s\n", PORT, snd_strerror(err));
snd_mixer_close(mixerFD);
return err;
}
for(elem=snd_mixer_first_elem(mixerFD);elem;elem=snd_mixer_elem_next(elem))
{
if(snd_mixer_elem_get_type(elem)==SND_MIXER_ELEM_SIMPLE && snd_mixer_selem_is_active(elem))
{
if(!strcmp(PORT,snd_mixer_selem_get_name(elem)))
{
snd_mixer_selem_get_playback_volume_range(elem,&minVolume,&maxVolume);
snd_mixer_selem_get_playback_volume(elem,(snd_mixer_selem_channel_id_t)0,&Volume);
snd_mixer_selem_set_playback_switch(elem,(snd_mixer_selem_channel_id_t)0,(long)1);//设置不静音
snd_mixer_selem_set_playback_volume(elem,(snd_mixer_selem_channel_id_t)lr,volume);
}
}
}
snd_mixer_close(mixerFD);
return 0;
}
error.c
#include
……
const char *snd_strerror(int errnum)
{
if (errnum < 0)
errnum = -errnum;
if (errnum < SND_ERROR_BEGIN)
return (const char *) strerror(errnum);
errnum -= SND_ERROR_BEGIN;
if ((unsigned int) errnum >= sizeof(snd_error_codes) / sizeof(const char *))
return "Unknown error";
return snd_error_codes[errnum];
}
……
string.h
……
extern char *strerror (int __errnum) __THROW;
……
阅读(1986) | 评论(0) | 转发(1) |