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 256
|
|
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=0;
|
|
28 int r;
|
|
29 int xxx=1024*2;
|
|
30 int audio_fd;
|
|
31 char *dsp="/dev/dsp";
|
|
32 unsigned int t1,t2;
|
|
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 t1=GetTimer();
|
|
46
|
|
47 while(xxx-->0){
|
|
48 r=write(audio_fd,a_buffer,OUTBURST);
|
|
49 t2=GetTimer();
|
|
50 if(r<0) printf("Error writting to device\n"); else
|
|
51 if(r==0) printf("EOF writting to device???\n"); else {
|
|
52 printf("[%6d] writting %3d of %3d bytes in %7d us\n",audio_buffer_size,r,OUTBURST,t2-t1);
|
|
53 audio_buffer_size+=r;
|
|
54 }
|
|
55 t1=t2;
|
|
56 }
|
|
57
|
|
58 close(audio_fd);
|
|
59
|
|
60 return 0;
|
|
61 }
|
|
62
|