2 * hdrec -- some sort of multi tracker (not right now, but in the future :p)
4 * author: hackbard@hackdaworld.dyndns.org
11 #include <sys/ioctl.h>
12 #include <sys/types.h>
14 #include <sys/soundcard.h>
24 printf("-h \t\t print this help\n");
25 printf("-i \t\t use/print file info\n");
26 printf("-r <file> \t record to <file>\n");
27 printf("-p <file> \t play from <file>\n");
28 printf("-s \t\t stereo\n");
29 printf("-m \t\t mono\n");
30 printf("-f <format> \t 1=8bit - 2=16bit (le)\n");
31 printf("-F <hz> \t frequency\n");
36 int main(int argc,char **argv) {
40 char device[MAX_C_DEVICE];
45 char record_file[MAX_C_FILE];
46 char play_file[MAX_C_FILE];
49 unsigned char print_info=0;
50 unsigned char info[8];
55 set.format=AFMT_S16_LE;
71 strcpy(record_file,argv[++i]);
75 strcpy(play_file,argv[++i]);
85 if(atoi(argv[i])==1) set.format=AFMT_U8;
86 if(atoi(argv[i])==2) set.format=AFMT_S16_LE;
89 set.freq=atoi(argv[++i]);
92 strncpy(device,argv[++i],MAX_C_DEVICE-1);
101 if(!strcmp("",device)) {
102 printf("you have to specify a device!\n");
107 if(mode&RECORD) o_mode=O_RDONLY;
108 if(mode&PLAY) o_mode=O_WRONLY;
109 if(mode&RECORD && mode&PLAY) o_mode=O_RDWR;
110 if((audio_fd=open_sound_dev(device,o_mode))==-1) {
111 printf("unable to open %s\n",device);
117 if((pfile_fd=open_file(play_file,O_RDONLY))==-1) {
118 printf("unable to open file %s for reading\n",play_file);
123 if((sfile_fd=open_file(record_file,O_CREAT|O_WRONLY))==-1) {
124 printf("unable to open file %s for writing\n",record_file);
131 printf("file info:\n");
132 lseek(pfile_fd,4,SEEK_SET);
133 read(pfile_fd,&info_int,4);
134 printf("file size: %d\n",info_int);
135 lseek(pfile_fd,8,SEEK_CUR);
136 read(pfile_fd,&info_int,4);
137 printf("fmtsize: %d\n",info_int);
138 read(pfile_fd,&info_int,4);
139 printf("format tag: %d\n",(info_int>>16)&1<<16);
140 printf("channels: %d\n",info_int&1<<16);
141 read(pfile_fd,&info_int,4);
142 printf("samples/sec: %d\n",info_int);
143 read(pfile_fd,&info_int,4);
144 printf("bytes/sec: %d\n",info_int);
145 read(pfile_fd,&info_int,4);
146 printf("block allign: %d\n",(info_int>>16)&1<<16);
147 printf("bits/sample: %d\n",info_int&1<<16);
148 lseek(pfile_fd,4,SEEK_CUR);
149 read(pfile_fd,&info_int,4);
150 printf("datasize: %d\n\n",info_int);
151 /* return to start */
152 lseek(pfile_fd,0,SEEK_SET);
156 /* set dsp and get capabilities */
157 if(get_dsp_cap(audio_fd,&set,1)==-1) {
158 printf("unable to get capabilities :(\n");
161 if(set_dsp(audio_fd,&set)==-1) {
162 printf("unable to set dsp :(\n");
166 /* allocating buffer */
167 if((buf=malloc(set.bufsize*sizeof(unsigned char)))==NULL) {
168 printf("allocating memory failed :(\n");
174 printf("playing file %s ...\n",play_file);
177 rw=read(pfile_fd,buf,set.bufsize);
178 write(audio_fd,buf,set.bufsize);
183 printf("recording to file %s ...\n",record_file);
186 rw=read(audio_fd,buf,set.bufsize);
187 write(sfile_fd,buf,set.bufsize);