光盘自带的2.6.30.4内核使用的声卡驱动为ALSA的,因为ALSA兼容OSS的API,所以我用OSS的函数写了一个播放程序,但是在板子上运行时,声音跟快进一样,但是使用板子中QT的播放程序播放正常。
我的代码如下:
- //play
- #include "stdio.h"
- #include "stdlib.h"
- #include "unistd.h"
- #include "fcntl.h"
- #include "sys/types.h"
- #include "sys/ioctl.h"
- #include "linux/soundcard.h"
- #include "termios.h"
- #define RATE 8000
- #define CHANNELS 1
- #define BITS 16
- #define SIZE 320
- unsigned char buf[SIZE];
- int main(int argc,char **argv)
- {
- int dspw;
- int arg;
- FILE *outfd;
- char *name;
-
- if(argc!=2)
- {
- printf("usage: %s file_name\n",argv[0]);
- return 0;
- }
- name=argv[1];
-
- //write only /dev/dsp
- dspw=open("/dev/dsp",O_WRONLY);
- if(dspw<0)
- {
- perror("open /dev/dsp writeonly error\n");
- return 1;
- }
- arg=BITS;
- if(ioctl(dspw,SOUND_PCM_WRITE_BITS,&arg)==-1)
- {
- perror("set writeonly /dev/dsp bits error\n");
- return 1;
- }
- arg=RATE;
- if(ioctl(dspw,SOUND_PCM_WRITE_RATE,&arg)==-1)
- {
- perror("set writeonly /dev/dsp rate error\n");
- return 1;
- }
- arg=CHANNELS;
- if(ioctl(dspw,SOUND_PCM_WRITE_CHANNELS,&arg)==-1)
- {
- perror("set writeonly /dev/dsp channels error\n");
- return 1;
- }
-
- //outfile open
- outfd=fopen(name,"r");
- if(outfd==NULL)
- {
- printf("open %s error\n",argv[1]);
- return 1;
- }
-
- while(!feof(outfd))
- {
- fread(buf,1,sizeof(buf),outfd);
- write(dspw,buf,sizeof(buf));
- }
-
- close(dspw);
- fclose(outfd);
- return 0;
- }
复制代码
|