8 #include <sys/soundcard.h>
11 #include "mp3lib/mp3.h"
12 #include "cpudetect.h"
14 static FILE* mp3file
=NULL
;
16 int mplayer_audio_read(char *buf
,int size
){
17 return fread(buf
,1,size
,mp3file
);
21 static unsigned char buffer
[BUFFLEN
];
24 int main(int argc
,char* argv
[]){
30 mp3file
=fopen((argc
>1)?argv
[1]:"test.mp3","rb");
31 if(!mp3file
){ printf("file not found\n"); exit(1); }
33 GetCpuCaps(&gCpuCaps
);
36 #ifdef CONFIG_FAKE_MONO
41 MP3_samplerate
=MP3_channels
=0;
42 len
=MP3_DecodeFrame(buffer
,-1);
44 audio_fd
=open("/dev/dsp", O_WRONLY
);
45 if(audio_fd
<0){ printf("Can't open audio device\n");exit(1); }
46 r
=AFMT_S16_LE
;ioctl (audio_fd
, SNDCTL_DSP_SETFMT
, &r
);
47 r
=MP3_channels
-1;ioctl (audio_fd
, SNDCTL_DSP_STEREO
, &r
);
48 r
=MP3_samplerate
;ioctl (audio_fd
, SNDCTL_DSP_SPEED
, &r
);
49 printf("audio_setup: using %d Hz samplerate (requested: %d)\n",r
,MP3_samplerate
);
53 if(len
==0) len
=MP3_DecodeFrame(buffer
,-1);
54 if(len
<=0) break; // EOF
57 len2
=write(audio_fd
,buffer
,len
);
58 if(len2
<0) break; // ERROR?
59 len
-=len2
; total
+=len2
;
61 // this shouldn't happen...
62 memcpy(buffer
,buffer
+len2
,len
);
63 putchar('!');fflush(stdout
);