2 //gcc test2.c -O2 -I.. -L. ../libvo/aclib.c -lMP3 -lm -o test2
10 #include <sys/soundcard.h>
12 #include "mp3lib/mp3.h"
14 #include "cpudetect.h"
16 static FILE* mp3file
=NULL
;
18 int mplayer_audio_read(char *buf
,int size
){
19 return fread(buf
,1,size
,mp3file
);
23 static unsigned char buffer
[BUFFLEN
];
26 int main(int argc
,char* argv
[]){
33 mp3file
=fopen((argc
>1)?argv
[1]:"test.mp3","rb");
34 if(!mp3file
){ printf("file not found\n"); exit(1); }
36 GetCpuCaps(&gCpuCaps
);
44 MP3_samplerate
=MP3_channels
=0;
45 len
=MP3_DecodeFrame(buffer
,-1);
47 audio_fd
=open("/dev/dsp", O_WRONLY
);
48 if(audio_fd
<0){ printf("Can't open audio device\n");exit(1); }
49 r
=AFMT_S16_LE
;ioctl (audio_fd
, SNDCTL_DSP_SETFMT
, &r
);
50 r
=MP3_channels
-1;ioctl (audio_fd
, SNDCTL_DSP_STEREO
, &r
);
51 r
=MP3_samplerate
;ioctl (audio_fd
, SNDCTL_DSP_SPEED
, &r
);
52 printf("audio_setup: using %d Hz samplerate (requested: %d)\n",r
,MP3_samplerate
);
56 if(len
==0) len
=MP3_DecodeFrame(buffer
,-1);
57 if(len
<=0) break; // EOF
60 len2
=write(audio_fd
,buffer
,len
);
61 if(len2
<0) break; // ERROR?
62 len
-=len2
; total
+=len2
;
64 // this shouldn't happen...
65 memcpy(buffer
,buffer
+len2
,len
);
66 putchar('!');fflush(stdout
);