您现在的位置: 主页 > MCU > 单片机技术应用 > ARM-Linux:设备-mixer-linux系统声音效果调节 -
本文所属标签:
为本文创立个标签吧:

ARM-Linux:设备-mixer-linux系统声音效果调节 -

来源: 网络用户发布,如有版权联系网管删除 2018-09-07 

[导读]
系统:arm板/Linux系统内核:2.6.7设备:/dev/mixer功能:linux系统声音效果调节文件名:xxx.c编译:gcc xxx.c -o mixerSet终端执行:./mixerSet [leftvalue] [rightvalue]测试:无问题#include #inclu

系统:arm板/Linux系统
内核:2.6.7
设备:/dev/mixer
功能:linux系统声音效果调节
文件名:xxx.c
编译:gcc xxx.c -o mixerSet
终端执行:./mixerSet [leftvalue] [rightvalue]
测试:无问题

本文引用地址: http://www.21ic.com/app/mcu/201806/764790.htm

#include

#include

#include

#include

#include

#include



/* 用来存储所有可用混音设备的名称 */

const char *sound_device_names[] = SOUND_DEVICE_NAMES;

/* 混音设备所对应的文件描述符 */

int fd;

/* 混音器信息对应的位图掩码 */

int devmask, stereodevs;

char *name;


/* 显示命令的使用方法及所有可用的混音设备 */

void usage()

{

int i;


fprintf(stderr, "usage: %s n"

" %s nn"

"Where is one of:n", name, name);

for (i = 0 ; i < SOUND_MIXER_NRDEVICES ; i++)

if ((1 << i) & devmask) /* 只显示有效的混音设备 */

fprintf(stderr, "%s ", sound_device_names[i]);

fprintf(stderr, "n");

exit(1);

}


int main(int argc, char *argv[])

{


int left, right, level; /* 增益设置 */

int status; /* 系统调用的返回值 */

int device; /* 选用的混音设备 */

char *dev; /* 混音设备的名称 */

int i;

name = argv[0];


/* 以只读方式打开混音设备 */

fd = open("/dev/mixer", O_RDONLY);

if (fd == -1) {

perror("unable to open /dev/mixer");

exit(1);

}


/* 获得所需要的信息 */

status = ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devmask);

if (status == -1)

perror("SOUND_MIXER_READ_DEVMASK ioctl failed");

status = ioctl(fd, SOUND_MIXER_READ_STEREODEVS, &stereodevs);


if (status == -1)

perror("SOUND_MIXER_READ_STEREODEVS ioctl failed");


/* 检查用户输入 */

if (argc != 3 && argc != 4)

usage();

/* 保存用户输入的混音器名称 */

dev = argv[1];

/* 确定即将用到的混音设备 */

for (i = 0 ; i < SOUND_MIXER_NRDEVICES ; i++)

if (((1 << i) & devmask) && !strcmp(dev, sound_device_names[i]))break;

if (i == SOUND_MIXER_NRDEVICES) { /* 没有找到匹配项 */

fprintf(stderr, "%s is not a valid mixer devicen", dev);

usage();

}

/* 查找到有效的混音设备 */

device = i;

/* 获取增益值 */

if (argc == 4) {

/* 左、右声道均给定 */

left = atoi(argv[2]);

right = atoi(argv[3]);

} else {

/* 左、右声道设为相等 */

left = atoi(argv[2]);

right = atoi(argv[2]);

}

/* 对非立体声设备给出警告信息 */

if ((left != right) && !((1 << i) & stereodevs)) {

fprintf(stderr, "warning: %s is not a stereo devicen", dev);

}

/* 将两个声道的值合到同一变量中 */

level = (right << 8) + left;

/* 设置增益 */

status = ioctl(fd, MIXER_WRITE(device), &level);

if (status == -1) {

perror("MIXER_WRITE ioctl failed");

exit(1);

}

/* 获得从驱动返回的左右声道的增益 */

left = level & 0xff;

right = (level & 0xff00) >> 8;

/* 显示实际设置的增益 */

fprintf(stderr, "%s gain set to %d%% / %d%%n", dev, left, right);

/* 关闭混音设备 */

close(fd);

return 0;

}


注:
首先不带参数执行编译出来的程序,得到系统中有效的混音设备,我使用的是飞凌OK210,里面已经有的设备有:speakerpcm2 igain ogain phout 共五个。
speaker:测试无效果
pcm2:测试可以调节音量大小,在40%时已经听不见声音了,在100%时声音最大
igain:测试无效果
ogain:测试可以调节音量大小,在40%时已经听不见声音了,在100%时声音最大,但相对于pcm2设备来说,效果较差。
phout:测试无效果



              查看评论 回复



嵌入式交流网主页 > MCU > 单片机技术应用 > ARM-Linux:设备-mixer-linux系统声音效果调节 -
 

"ARM-Linux:设备-mixer-linux系统声音效果调节 -"的相关文章

网站地图

围观()