⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listen.c

📁 s3c2410IIS总线实验代码 实现录音以及放音功能
💻 C
字号:
#include <unistd.h>#include <fcntl.h>#include <sys/types.h>#include <sys/ioctl.h>#include <stdlib.h>#include <stdio.h>#include<string.h>#include <linux/soundcard.h>#define RATE 44000#define SIZE 16#define CHANNELS 1int main(int argc,char * argv[]){	int id,fd;	int arg;	int status;	char buf[1024];	if((id = open("/dev/dsp",O_WRONLY)) < 0 )	{		printf("Can't open sound device!\n");		exit(1);	}	if((fd = open(argv[1],O_RDWR)) < 0)	{		printf("Can't open output file!\n");		exit (1);	}	arg = SIZE;  	status = ioctl(id,SOUND_PCM_WRITE_BITS,&arg);  	if(status == -1)  		printf("SOUND_PCM_WRITE_BITS ioctl failed\n");  	if(arg != SIZE)  		printf("unable to set sample size\n");	arg = CHANNELS;   	status = ioctl(id,SOUND_PCM_WRITE_CHANNELS,&arg);  	if(status == -1)    		printf("SOUND_PCM_WRITE_CHANNELS ioctl failed\n");  	if(arg != CHANNELS)    		printf("unable to set number of channels\n");	arg = RATE;  	status = ioctl(id,SOUND_PCM_WRITE_RATE,&arg);  	if(status == -1)    		printf("SOUND_PCM_WRITE_WRITE ioctl failed\n");	while(read(fd,buf,sizeof(buf)) > 0)		write(id,buf,sizeof(buf));	close(fd);	close(id);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -