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