annotate TOOLS/audio-block.c @ 5512:4ccfa77d8e86

postprocessing filter (fixme: -pp 0)
author arpi
date Sun, 07 Apr 2002 03:20:41 +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 256
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=0;
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*2;
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;
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 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 r=write(audio_fd,a_buffer,OUTBURST);
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
49 t2=GetTimer();
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
50 if(r<0) printf("Error writting to device\n"); else
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
51 if(r==0) printf("EOF writting to device???\n"); else {
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
52 printf("[%6d] writting %3d of %3d bytes in %7d us\n",audio_buffer_size,r,OUTBURST,t2-t1);
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
53 audio_buffer_size+=r;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
54 }
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
55 t1=t2;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
56 }
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
57
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
58 close(audio_fd);
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
59
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
60 return 0;
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
61 }
e5d07da09f9b added audio driver debug tools
arpi_esp
parents:
diff changeset
62