2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <sys/ioctl.h>
26 #include <sys/soundcard.h>
29 #include "mp3lib/mp3.h"
30 #include "cpudetect.h"
32 static FILE* mp3file
=NULL
;
34 int mplayer_audio_read(char *buf
,int size
){
35 return fread(buf
,1,size
,mp3file
);
39 static unsigned char buffer
[BUFFLEN
];
42 int main(int argc
,char* argv
[]){
48 mp3file
=fopen((argc
>1)?argv
[1]:"test.mp3","rb");
49 if(!mp3file
){ printf("file not found\n"); exit(1); }
51 GetCpuCaps(&gCpuCaps
);
54 #ifdef CONFIG_FAKE_MONO
59 MP3_samplerate
=MP3_channels
=0;
60 len
=MP3_DecodeFrame(buffer
,-1);
62 audio_fd
=open("/dev/dsp", O_WRONLY
);
63 if(audio_fd
<0){ printf("Can't open audio device\n");exit(1); }
64 r
=AFMT_S16_LE
;ioctl (audio_fd
, SNDCTL_DSP_SETFMT
, &r
);
65 r
=MP3_channels
-1;ioctl (audio_fd
, SNDCTL_DSP_STEREO
, &r
);
66 r
=MP3_samplerate
;ioctl (audio_fd
, SNDCTL_DSP_SPEED
, &r
);
67 printf("audio_setup: using %d Hz samplerate (requested: %d)\n",r
,MP3_samplerate
);
71 if(len
==0) len
=MP3_DecodeFrame(buffer
,-1);
72 if(len
<=0) break; // EOF
75 len2
=write(audio_fd
,buffer
,len
);
76 if(len2
<0) break; // ERROR?
77 len
-=len2
; total
+=len2
;
79 // this shouldn't happen...
80 memcpy(buffer
,buffer
+len2
,len
);
81 putchar('!');fflush(stdout
);