From 829e701e2c78be9671e992de7c7ed63f5a39056c Mon Sep 17 00:00:00 2001 From: arpi_esp Date: Wed, 2 May 2001 04:29:04 +0000 Subject: new audio block/select test git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@687 b3059339-0415-0410-9bf9-f77b7e298cf2 --- TOOLS/audio-block2.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 TOOLS/audio-block2.c (limited to 'TOOLS') diff --git a/TOOLS/audio-block2.c b/TOOLS/audio-block2.c new file mode 100644 index 0000000000..9720d2af0a --- /dev/null +++ b/TOOLS/audio-block2.c @@ -0,0 +1,74 @@ +// This small util discovers your audio driver's behaviour + +#define OUTBURST 512 +//#define OUTBURST 4096 + + +#include +#include +#include +#include + +#include +#include +#include + + +// Returns current time in microseconds +unsigned int GetTimer(){ + struct timeval tv; + struct timezone tz; +// float s; + gettimeofday(&tv,&tz); +// s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec; + return (tv.tv_sec*1000000+tv.tv_usec); +} + +static unsigned char a_buffer[OUTBURST]; + +int main(){ + int audio_buffer_size=0; + int r; + int xxx=1024*2; + int audio_fd; + char *dsp="/dev/dsp"; + unsigned int t0,t1,t2; + + audio_fd=open(dsp, O_WRONLY); + if(audio_fd<0){ + printf("Can't open audio device %s\n",dsp); + return 1; + } + + r=AFMT_S16_LE;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r); + r=1; ioctl (audio_fd, SNDCTL_DSP_STEREO, &r); + r=44100; if(ioctl (audio_fd, SNDCTL_DSP_SPEED, &r)==-1) + printf("audio_setup: your card doesn't support %d Hz samplerate\n",r); + + t0=t1=GetTimer(); + +while(xxx-->0){ + char c='B'; + fd_set rfds; + struct timeval tv; + FD_ZERO(&rfds); FD_SET(audio_fd,&rfds); + tv.tv_sec=0; tv.tv_usec = 0; + if(select(audio_fd+1, NULL, &rfds, NULL, &tv)) c=' '; + + r=write(audio_fd,a_buffer,OUTBURST); + t2=GetTimer(); + if(r<0) printf("Error writting to device\n"); else + if(r==0) printf("EOF writting to device???\n"); else { + printf("%c %6.3f %6.3f [%6d] writting %3d of %3d bytes in %7d us\n",c, + (float)audio_buffer_size/(44100.0f*4.0f),(float)(t1-t0)*0.000001f, + audio_buffer_size,r,OUTBURST,t2-t1); + audio_buffer_size+=r; + } + t1=t2; +} + +close(audio_fd); + +return 0; +} + -- cgit v1.2.3