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

📄 audio_test.c

📁 IIS 音频驱动实验 基于TEB-44B0实验平台 包括音频驱动程序与测试程序
💻 C
字号:
// Audio test : Using CS4334 to play wav file// Vencent // 2005.10.11#include <stdio.h>#include <stdlib.h> //#include <sys/types.h> //#include <sys/stat.h> #include <fcntl.h>//#include <linux/sound.h> #include <linux/soundcard.h>#include "s3c44b0x.h"#include "wav.h"#define AUDIODEVE	"/dev/audio"#define WAVEFILE 	"/bin/test.wav"//#define AUDIOBUFLEN	200*1024                  // 200K byte buffer//unsigned char buf[AUDIOBUFLEN];//#define WAVE_FORMAT_PCM	0x0001//#define IIS_FIFOREADY	!(((inl(S3C44B0X_IISCON))>>7)&1)int verbose = 1;int raw = 0;struct wavefile wav;/* *	Endian re-arranger :-) */#define	SWAPLONG(a)	((((a) & 0xff000000) >> 24) | \			(((a) & 0x00ff0000) >> 8) | \			(((a) & 0x0000ff00) << 8) | \			(((a) & 0x000000ff) << 24))#define	SWAPSHORT(a)	(((a) >> 8) | ((a) << 8))int main(void){ 	int fd_dev, fd_file;	int i, j, k, n ;	int freq, chans, bitspersample;	int ret;	char c;	unsigned long data_size;	        /* Default to not set for now */ 	freq = 0;	chans = 0;	bitspersample = 0;		fd_dev = open(AUDIODEVE, O_WRONLY);           // open the audio device 	if(fd_dev < 0) 	{  		printf("Failed to open the audio device!\n");  	 	exit(1); 	} 	printf("The audio device is open successfully!\n"); 	fd_file = open(WAVEFILE, O_RDONLY);             // open the test wave file 	if(fd_file < 0)	{		printf("Failed to open the test wave file!\n");		exit(2);	}	printf("The test wave file is open successfully!\n");		if(!raw)	{	 /* Parse wave file... */	 if (!(n = read(fd_file, &wav, sizeof(wav)))) 	 {	  	//printf("ERROR: failed to read wave header!\n");		printf("ERROR: failed to read wave file!\n");	  	exit(3);	 }	 	 wav.riffid = SWAPLONG(wav.riffid);       //add//	 wav.filesize = SWAPLONG(wav.filesize);	 wav.waveid = SWAPLONG(wav.waveid);       //add	 wav.fmtid = SWAPLONG(wav.fmtid);         //add//	 wav.formattag = SWAPSHORT(wav.formattag);//	 wav.channels = SWAPSHORT(wav.channels);//	 wav.samplerate = SWAPLONG(wav.samplerate);//	 wav.bytespersec = SWAPLONG(wav.bytespersec);//	 wav.samplesize = SWAPSHORT(wav.samplesize);//	 wav.bitspersample = SWAPSHORT(wav.bitspersample);	 	 if (verbose) 	 {	  	printf("FILE=%s\n  Type=0x%x\n  File Length=%d\n", WAVEFILE, wav.riffid, wav.filesize);		printf("  Hdr len=%d\n  Formattatg=%d\n", wav.hdrlen, wav.formattag);   //add	  	printf("  Channels=%d\n  Sample Rate=%d\n  Bytes Per Second=%d\n  Sample Size=%d\n  Bits per Sample=%d\n", 	        	wav.channels, wav.samplerate, wav.bytespersec, wav.samplesize, wav.bitspersample);	 }	 	 if (wav.riffid != WAV_RIFFTYPE) 	 {	  	printf("ERROR: unknown file type, riffid=%x??\n", wav.riffid);	  	exit(4);	 }	 if (wav.waveid != WAV_WAVETYPE) 	 {	  	printf("ERROR: unknown file type, waveid=%x??\n", wav.waveid);	  	exit(5);	 }	 if (wav.fmtid != WAV_FMTTYPE) 	 {	  	printf("ERROR: unknown file type, fmtid=%x??\n", wav.fmtid);	  	exit(6);	 }	 if (freq == 0)	 	freq = wav.samplerate;	 if (chans == 0)	  	chans = wav.channels;	 if (bitspersample == 0)	  	bitspersample = wav.bitspersample;	}	/* Set any remaining defaults if neccessary */	if (freq == 0)		freq = 8000;	if (chans == 0)		chans = 1;	if (bitspersample == 0)		bitspersample = 8;		if(ioctl(fd_dev, SNDCTL_DSP_SPEED, &freq) < 0)	{	 	printf("ERROR: ioctl speed failed!\n");	 	exit(7);	}		if(ioctl(fd_dev, SNDCTL_DSP_STEREO, &chans) < 0)	{	 	printf("ERROR: ioctl stereo failed!\n");	 	exit(8);	}		if(ioctl(fd_dev, SNDCTL_DSP_SAMPLESIZE, &bitspersample) < 0)	{		printf("ERROR: ioctl samplesize failed!\n");	 	exit(9);	}			//wav.datasize = SWAPLONG(wav.datasize);       //add	printf("  Data size: %d\n", wav.datasize);	data_size = wav.datasize >> 1;		/* Now playing the wave file */	ret = write(fd_dev, &wav.databuf, data_size);	if(ret < 0)	{	 	printf("Write Audio error!\n");	 	exit(10);	}		close(fd_file);	printf("Close the test wave file!\n");		close(fd_dev);	printf("Close the audio device!\n");		return 0;	 }  

⌨️ 快捷键说明

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