comparison TOOLS/audio-block2.c @ 730:0544dd78f455

fragment info added (disabled)
author arpi_esp
date Tue, 08 May 2001 21:28:04 +0000
parents 0b3b56e9b9fa
children cd1f0d4de0b8
comparison
equal deleted inserted replaced
729:dcaa9fbcdddf 730:0544dd78f455
24 return (tv.tv_sec*1000000+tv.tv_usec); 24 return (tv.tv_sec*1000000+tv.tv_usec);
25 } 25 }
26 26
27 static unsigned char a_buffer[OUTBURST]; 27 static unsigned char a_buffer[OUTBURST];
28 28
29 void inline print_info(int audio_fd){
30 #if 1
31 audio_buf_info zz;
32 ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz);
33 printf("Status: %3d/%d (%d byte/frag) free: %6d\n",
34 zz.fragments, zz.fragstotal, zz.fragsize, zz.bytes);
35 #endif
36 }
37
29 int main(){ 38 int main(){
30 int audio_buffer_size=0; 39 int audio_buffer_size=0;
31 int r; 40 int r;
32 int xxx=1024*2; 41 int xxx=1024*2;
33 int audio_fd; 42 int audio_fd;
37 audio_fd=open(dsp, O_WRONLY); 46 audio_fd=open(dsp, O_WRONLY);
38 if(audio_fd<0){ 47 if(audio_fd<0){
39 printf("Can't open audio device %s\n",dsp); 48 printf("Can't open audio device %s\n",dsp);
40 return 1; 49 return 1;
41 } 50 }
51
52 // ioctl(audio_fd, SNDCTL_DSP_RESET, NULL);
53 // print_info(audio_fd);
54
55 ioctl(audio_fd, SNDCTL_DSP_RESET, NULL);
42 56
43 r=AFMT_S16_LE;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r); 57 r=AFMT_S16_LE;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r);
44 r=1; ioctl (audio_fd, SNDCTL_DSP_STEREO, &r); 58 r=1; ioctl (audio_fd, SNDCTL_DSP_STEREO, &r);
45 r=44100; if(ioctl (audio_fd, SNDCTL_DSP_SPEED, &r)==-1) 59 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); 60 printf("audio_setup: your card doesn't support %d Hz samplerate\n",r);
61
62 // print_info(audio_fd);
47 63
48 t0=t1=GetTimer(); 64 t0=t1=GetTimer();
49 65
50 while(xxx-->0){ 66 while(xxx-->0){
51 char c='B'; 67 char c='B';
52 fd_set rfds; 68 fd_set rfds;
53 struct timeval tv; 69 struct timeval tv;
54 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds); 70 FD_ZERO(&rfds); FD_SET(audio_fd,&rfds);
55 tv.tv_sec=0; tv.tv_usec = 0; 71 tv.tv_sec=0; tv.tv_usec = 0;
56 if(select(audio_fd+1, NULL, &rfds, NULL, &tv)) c=' '; 72 if(select(audio_fd+1, NULL, &rfds, NULL, &tv)) c=' ';
73
74 // print_info(audio_fd);
57 75
58 r=write(audio_fd,a_buffer,OUTBURST); 76 r=write(audio_fd,a_buffer,OUTBURST);
59 t2=GetTimer(); 77 t2=GetTimer();
60 if(r<0) printf("Error writting to device\n"); else 78 if(r<0) printf("Error writting to device\n"); else
61 if(r==0) printf("EOF writting to device???\n"); else { 79 if(r==0) printf("EOF writting to device???\n"); else {