DSP

linux 下用oss播放音乐

2019-07-13 16:23发布

#include #include #include #include #include #include #include #include #include int main() { int fd = open("/home/test/bb.wav",O_RDONLY); if(fd) { int oss_fd = open("/dev/dsp", O_CREAT | O_APPEND | O_WRONLY); if(-1 != oss_fd) { int i,j; /* 存储音频数据的缓冲区,可以调整*/ char testbuf[65536] = {0}; int tmp = 1; if (ioctl(oss_fd, SNDCTL_DSP_STEREO, &tmp) == -1) { } tmp = 16; if (ioctl(oss_fd, SNDCTL_DSP_SAMPLESIZE, &tmp) == -1) { } tmp = 44100; if (ioctl(oss_fd, SNDCTL_DSP_SPEED, &tmp) == -1) { } tmp = 2097164; if (ioctl(oss_fd, SNDCTL_DSP_SETFRAGMENT, &tmp) == -1) { } /* 读取一定数量的音频数据,并将之写到输出文件中去*/ for ( j=0; j<600;j++) { i=read(fd,testbuf,65536); write(oss_fd,testbuf,i); } /* 关闭输入、输出文件*/ close(fd); close(oss_fd); }else { close(oss_fd); } close(oss_fd); } close(fd); return 0; }