我在学音频方面的,希望各位指教。我用gec2410的开发版,在uda1341的录音和放音上出现问题。好像是不能放,录时也有一点问题。
录音
程序:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define BUFSIZE 128
//#define
SOUNDFILE "./iis.wav"
int main()
{
int fd;
int
format,rate,stereo,channel;
FILE *frp;
char buf[BUFSIZE];
//int
total_size;
//int total_count;
//int count;
int fread_size;
int
rsize;
int timelimit=0;
if((fd=open("/dev/dsp",O_RDWR,0))==-1)
{
perror("OSS: Erroe Opening Device\\n");
return;
}
format=AFMT_S16_LE;
if(ioctl(fd,SNDCTL_DSP_SETFMT,&format)==-1)
{
perror("SOUND_PCM_SETFMT");
return -1;
}
channel=1;
if(ioctl(fd,SOUND_PCM_READ_CHANNELS,&channel)==-1)
{
perror("SOUND_READ_CHANNEL");
return -1;
}
rate=8000;
if(ioctl(fd,SOUND_PCM_READ_RATE,&rate)==-1)
{
perror("SOUND_READ_SPEED");
}
frp=fopen("./mtest.wav","wb");
while(timelimit<500)
{
rsize=read(fd,buf,128);
printf("read size:%d\n",rsize);
fwrite(buf,sizeof(char),rsize,frp);
timelimit++;
}
fclose(frp);
}
放
音程序:
#include
#include
#include
#include
#include
#include
#include
#define LENGTH 3
#define RATE 8000
#define
SIZE 8
#define CHANNELS 1
unsigned char
buf[LENGTH*RATE*SIZE*CHANNELS/8];
int main()
{
int fd;
int
id;
int arg;
int status;
int i;
int j;
fd=open("/dev/dsp",O_RDWR);
if(fd<0){
perror("open of /dev/dsp failed");
exit(1);
}
id=open("night.wav",O_RDWR);
if(id<0){
perror("open of sound file failed");
exit(1);
}
arg=SIZE;
status=ioctl(fd,SOUND_PCM_WRITE_BITS,&arg);
if(status==-1)
perror("SOUND_PCM_WRITE_BITS ioctl faild");
if(arg!=SIZE)
perror("unable to set sample sie");
arg=CHANNELS;
status=ioctl(fd,SOUND_PCM_WRITE_CHANNELS,&arg);
if(status==-1)
perror("SOUND_PCM_WRITE_CHANNELS ioctl faild");
if(arg!=CHANNELS)
perror("unable to set number of channels");
//arg=RATE;
//status=ioctl(fd,SOUND_PCM_WRITE_RATE,&arg);
//if(status==-1)
//perror("SOUND_PCM_WRITE_WRITE
ioctl failed");
for(i=0;i<10;i++){
j=read(id,buf,sizeof(buf));
if(j>0){
write(fd,buf,j);
}
}
close(fd);
close(id);
return 1;
}
阅读(1572) | 评论(0) | 转发(0) |