annotate TOOLS/audio-block2.c @ 10754:2ca1fc045731

Recieving of mouse events can be switched off. Patch by Markus Rechberger <mrechberger@web.de>
author alex
date Sun, 31 Aug 2003 22:02:25 +0000
parents a40ee717336e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
686
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
1 // This small util discovers your audio driver's behaviour
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
2
752
a40ee717336e some more printfs
arpi_esp
parents: 746
diff changeset
3 //#define OUTBURST 512
686
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
4 //#define OUTBURST 4096
752
a40ee717336e some more printfs
arpi_esp
parents: 746
diff changeset
5 #define MAX_OUTBURST 32768
686
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
6
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
7
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
8 #include <stdio.h>
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
9 #include <stdlib.h>
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
10 #include <fcntl.h>
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
11 #include <sys/soundcard.h>
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
12
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
13 #include <sys/time.h>
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
14 #include <sys/types.h>
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
15 #include <unistd.h>
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
16
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
17
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
18 // Returns current time in microseconds
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
19 unsigned int GetTimer(){
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
20 struct timeval tv;
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
21 struct timezone tz;
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
22 // float s;
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
23 gettimeofday(&tv,&tz);
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
24 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
25 return (tv.tv_sec*1000000+tv.tv_usec);
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
26 }
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
27
752
a40ee717336e some more printfs
arpi_esp
parents: 746
diff changeset
28 static unsigned char a_buffer[MAX_OUTBURST];
686
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
29
730
0544dd78f455 fragment info added (disabled)
arpi_esp
parents: 686
diff changeset
30 void inline print_info(int audio_fd){
0544dd78f455 fragment info added (disabled)
arpi_esp
parents: 686
diff changeset
31 #if 1
0544dd78f455 fragment info added (disabled)
arpi_esp
parents: 686
diff changeset
32 audio_buf_info zz;
0544dd78f455 fragment info added (disabled)
arpi_esp
parents: 686
diff changeset
33 ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz);
0544dd78f455 fragment info added (disabled)
arpi_esp
parents: 686
diff changeset
34 printf("Status: %3d/%d (%d byte/frag) free: %6d\n",
0544dd78f455 fragment info added (disabled)
arpi_esp
parents: 686
diff changeset
35 zz.fragments, zz.fragstotal, zz.fragsize, zz.bytes);
0544dd78f455 fragment info added (disabled)
arpi_esp
parents: 686
diff changeset
36 #endif
0544dd78f455 fragment info added (disabled)
arpi_esp
parents: 686
diff changeset
37 }
0544dd78f455 fragment info added (disabled)
arpi_esp
parents: 686
diff changeset
38
686
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
39 int main(){
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
40 int audio_buffer_size=0;
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
41 int r;
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
42 int xxx=1024*2;
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
43 int audio_fd;
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
44 char *dsp="/dev/dsp";
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
45 unsigned int t0,t1,t2;
752
a40ee717336e some more printfs
arpi_esp
parents: 746
diff changeset
46 int outburst;
686
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
47
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
48 audio_fd=open(dsp, O_WRONLY);
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
49 if(audio_fd<0){
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
50 printf("Can't open audio device %s\n",dsp);
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
51 return 1;
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
52 }
730
0544dd78f455 fragment info added (disabled)
arpi_esp
parents: 686
diff changeset
53
0544dd78f455 fragment info added (disabled)
arpi_esp
parents: 686
diff changeset
54 // ioctl(audio_fd, SNDCTL_DSP_RESET, NULL);
0544dd78f455 fragment info added (disabled)
arpi_esp
parents: 686
diff changeset
55
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 730
diff changeset
56 // ioctl(audio_fd, SNDCTL_DSP_RESET, NULL);
686
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
57
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
58 r=AFMT_S16_LE;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r);
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
59 r=1; ioctl (audio_fd, SNDCTL_DSP_STEREO, &r);
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
60 r=44100; if(ioctl (audio_fd, SNDCTL_DSP_SPEED, &r)==-1)
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
61 printf("audio_setup: your card doesn't support %d Hz samplerate\n",r);
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
62
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 730
diff changeset
63 r=0; ioctl (audio_fd, SNDCTL_DSP_GETBLKSIZE, &r);
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 730
diff changeset
64 printf("fragment size = %d\n",r);
752
a40ee717336e some more printfs
arpi_esp
parents: 746
diff changeset
65 outburst=r; if(outburst>4096) outburst=4096;
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 730
diff changeset
66
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 730
diff changeset
67 print_info(audio_fd);
730
0544dd78f455 fragment info added (disabled)
arpi_esp
parents: 686
diff changeset
68
686
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
69 t0=t1=GetTimer();
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
70
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
71 while(xxx-->0){
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
72 char c='B';
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
73 fd_set rfds;
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
74 struct timeval tv;
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
75 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds);
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
76 tv.tv_sec=0; tv.tv_usec = 0;
752
a40ee717336e some more printfs
arpi_esp
parents: 746
diff changeset
77 // if(select(audio_fd+1, NULL, &rfds, NULL, &tv)) c=' ';
a40ee717336e some more printfs
arpi_esp
parents: 746
diff changeset
78
a40ee717336e some more printfs
arpi_esp
parents: 746
diff changeset
79 print_info(audio_fd);
686
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
80
752
a40ee717336e some more printfs
arpi_esp
parents: 746
diff changeset
81 r=0; ioctl (audio_fd, SNDCTL_DSP_GETODELAY, &r); printf("delay = %d\n",r);
730
0544dd78f455 fragment info added (disabled)
arpi_esp
parents: 686
diff changeset
82
752
a40ee717336e some more printfs
arpi_esp
parents: 746
diff changeset
83 r=write(audio_fd,a_buffer,outburst);
686
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
84 t2=GetTimer();
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
85 if(r<0) printf("Error writting to device\n"); else
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
86 if(r==0) printf("EOF writting to device???\n"); else {
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
87 printf("%c %6.3f %6.3f [%6d] writting %3d of %3d bytes in %7d us\n",c,
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
88 (float)audio_buffer_size/(44100.0f*4.0f),(float)(t1-t0)*0.000001f,
752
a40ee717336e some more printfs
arpi_esp
parents: 746
diff changeset
89 audio_buffer_size,r,outburst,t2-t1);
686
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
90 audio_buffer_size+=r;
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
91 }
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
92 t1=t2;
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
93 }
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
94
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
95 close(audio_fd);
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
96
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
97 return 0;
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
98 }
0b3b56e9b9fa new audio block/select test
arpi_esp
parents:
diff changeset
99