playback.c
上传用户:sy_wanhua
上传日期:2013-07-25
资源大小:3048k
文件大小:2k
- #include <sys/types.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <strings.h>
- #include <sys/ioctl.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <asm/errno.h>
- #include "ixjuser.h"
- void closeall(void);
- int ixj1;
- int recfile;
- int main(int argc, char *argv[])
- {
- char pname1[80], pname2[80], buff1[480], buff2[480];
- unsigned long cnt, write1;
- int size, codec, len;
- if(argc<4)
- {
- printf("Use: %s <ixj dev number> <filename> <codec number>n",argv[0]);
- printf(" example: %s 0 audio-file 3n",argv[0]);
- exit(0);
- }
- sprintf(pname1, "/dev/ixj%s", argv[1]);
- sprintf(pname2, "%s", argv[2]);
- printf("Reading from %s, Writing to %sn", pname2, pname1);
-
- ixj1 = open(pname1, O_WRONLY);
- recfile = open(pname2, O_RDONLY);
- printf("file handle %dn", recfile);
- atexit(closeall);
- if(!ioctl(ixj1, IXJCTL_RING))
- {
- exit(0);
- }
- codec = atoi(argv[3]);
- switch(codec)
- {
- case G723_63:
- len = 24;
- break;
- case G723_53:
- len = 20;
- break;
- case TS85:
- len = 32;
- break;
- case TS48:
- len = 18;
- break;
- case TS41:
- len = 16;
- break;
- case G728:
- len = 96;
- break;
- case G729:
- len = 36;
- break;
- case ULAW:
- len = 240;
- break;
- case ALAW:
- len = 240;
- break;
- case LINEAR16:
- len = 480;
- break;
- case LINEAR8:
- len = 240;
- break;
- case WSS:
- len = 240;
- break;
- }
- cnt = write1 = 0;
- ioctl(ixj1, IXJCTL_PLAY_CODEC, codec);
- ioctl(ixj1, IXJCTL_PLAY_START);
- while(ioctl(ixj1, IXJCTL_HOOKSTATE))
- {
- size = read(recfile, buff1, len);
- fflush(stdout);
- if(size > 0)
- {
- write(ixj1, buff1, size);
- write1++;
- }
- else
- {
- break;
- }
- }
- }
- void closeall(void)
- {
- ioctl(ixj1, IXJCTL_PLAY_STOP);
- ioctl(ixj1, IXJCTL_AEC_STOP);
- close(ixj1);
- close(recfile);
- }