Mercurial > mplayer.hg
comparison TOOLS/audio-block2.c @ 686:0b3b56e9b9fa
new audio block/select test
author | arpi_esp |
---|---|
date | Wed, 02 May 2001 04:29:04 +0000 |
parents | |
children | 0544dd78f455 |
comparison
equal
deleted
inserted
replaced
685:32697fe58055 | 686:0b3b56e9b9fa |
---|---|
1 // This small util discovers your audio driver's behaviour | |
2 | |
3 #define OUTBURST 512 | |
4 //#define OUTBURST 4096 | |
5 | |
6 | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <fcntl.h> | |
10 #include <sys/soundcard.h> | |
11 | |
12 #include <sys/time.h> | |
13 #include <sys/types.h> | |
14 #include <unistd.h> | |
15 | |
16 | |
17 // Returns current time in microseconds | |
18 unsigned int GetTimer(){ | |
19 struct timeval tv; | |
20 struct timezone tz; | |
21 // float s; | |
22 gettimeofday(&tv,&tz); | |
23 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec; | |
24 return (tv.tv_sec*1000000+tv.tv_usec); | |
25 } | |
26 | |
27 static unsigned char a_buffer[OUTBURST]; | |
28 | |
29 int main(){ | |
30 int audio_buffer_size=0; | |
31 int r; | |
32 int xxx=1024*2; | |
33 int audio_fd; | |
34 char *dsp="/dev/dsp"; | |
35 unsigned int t0,t1,t2; | |
36 | |
37 audio_fd=open(dsp, O_WRONLY); | |
38 if(audio_fd<0){ | |
39 printf("Can't open audio device %s\n",dsp); | |
40 return 1; | |
41 } | |
42 | |
43 r=AFMT_S16_LE;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r); | |
44 r=1; ioctl (audio_fd, SNDCTL_DSP_STEREO, &r); | |
45 r=44100; if(ioctl (audio_fd, SNDCTL_DSP_SPEED, &r)==-1) | |
46 printf("audio_setup: your card doesn't support %d Hz samplerate\n",r); | |
47 | |
48 t0=t1=GetTimer(); | |
49 | |
50 while(xxx-->0){ | |
51 char c='B'; | |
52 fd_set rfds; | |
53 struct timeval tv; | |
54 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds); | |
55 tv.tv_sec=0; tv.tv_usec = 0; | |
56 if(select(audio_fd+1, NULL, &rfds, NULL, &tv)) c=' '; | |
57 | |
58 r=write(audio_fd,a_buffer,OUTBURST); | |
59 t2=GetTimer(); | |
60 if(r<0) printf("Error writting to device\n"); else | |
61 if(r==0) printf("EOF writting to device???\n"); else { | |
62 printf("%c %6.3f %6.3f [%6d] writting %3d of %3d bytes in %7d us\n",c, | |
63 (float)audio_buffer_size/(44100.0f*4.0f),(float)(t1-t0)*0.000001f, | |
64 audio_buffer_size,r,OUTBURST,t2-t1); | |
65 audio_buffer_size+=r; | |
66 } | |
67 t1=t2; | |
68 } | |
69 | |
70 close(audio_fd); | |
71 | |
72 return 0; | |
73 } | |
74 |