annotate TOOLS/audio-select.c @ 4205:c42ab0e5bbbc

possible sig11 fixed - noticed by Fredrik Kuivinen <freku045@student.liu.se>
author arpi
date Thu, 17 Jan 2002 00:49:21 +0000
parents e5d07da09f9b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
119
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
1 // This small util discovers your audio driver's behaviour
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
2
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
3 #include <stdio.h>
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
4 #include <stdlib.h>
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
5 #include <fcntl.h>
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
6 #include <sys/soundcard.h>
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
7
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
8 #include <sys/time.h>
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
9 #include <sys/types.h>
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
10 #include <unistd.h>
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
11
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
12 #define OUTBURST 128
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
13
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
14 // Returns current time in microseconds
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
15 unsigned int GetTimer(){
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
16 struct timeval tv;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
17 struct timezone tz;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
18 // float s;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
19 gettimeofday(&tv,&tz);
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
20 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
21 return (tv.tv_sec*1000000+tv.tv_usec);
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
22 }
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
23
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
24 static unsigned char a_buffer[OUTBURST];
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
25
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
26 int main(){
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
27 int audio_buffer_size;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
28 int r;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
29 int xxx=1024;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
30 int audio_fd;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
31 char *dsp="/dev/dsp";
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
32 unsigned int t1,t2,t3;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
33
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
34 audio_fd=open(dsp, O_WRONLY);
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
35 if(audio_fd<0){
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
36 printf("Can't open audio device %s\n",dsp);
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
37 return 1;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
38 }
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
39
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
40 r=AFMT_S16_LE;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r);
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
41 r=1; ioctl (audio_fd, SNDCTL_DSP_STEREO, &r);
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
42 r=44100; if(ioctl (audio_fd, SNDCTL_DSP_SPEED, &r)==-1)
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
43 printf("audio_setup: your card doesn't support %d Hz samplerate\n",r);
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
44
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
45 t3=t1=GetTimer();
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
46
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
47 while(xxx>0){
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
48 audio_buffer_size=0;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
49 while(audio_buffer_size<0x100000){
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
50 fd_set rfds;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
51 struct timeval tv;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
52 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds);
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
53 tv.tv_sec=0; tv.tv_usec = 0;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
54 if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
55 r=write(audio_fd,a_buffer,OUTBURST);
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
56 if(r<0) printf("Error writting to device\n"); else
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
57 if(r==0) printf("EOF writting to device???\n"); else
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
58 audio_buffer_size+=r;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
59 }
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
60 t2=GetTimer();
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
61 if(audio_buffer_size>0){
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
62 printf("%6d bytes written in %5d us (wait %5d us)\n",audio_buffer_size,t2-t1,t1-t3);
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
63 --xxx;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
64 t3=t2;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
65 }
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
66 t1=t2;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
67 }
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
68
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
69 close(audio_fd);
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
70
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
71 return 0;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
72 }
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
73