Some people confuse vidix with kernel drivers, so let's add a note about it
[mplayer/glamo.git] / mp3lib / test2.c
blob17c92bf79bd83c7affae5ee77b5d902c2a4fe98f
2 //gcc test2.c -O2 -I.. -L. ../libvo/aclib.c -lMP3 -lm -o test2
4 #include <stdio.h>
5 #include <stdlib.h>
7 #include <fcntl.h>
8 #include <sys/ioctl.h>
9 #include <unistd.h>
10 #include <sys/soundcard.h>
12 #include "mp3lib/mp3.h"
13 #include "config.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);
22 #define BUFFLEN 4608
23 static unsigned char buffer[BUFFLEN];
26 int main(int argc,char* argv[]){
27 int len;
28 int total=0;
29 float length;
30 int r;
31 int audio_fd;
33 mp3file=fopen((argc>1)?argv[1]:"test.mp3","rb");
34 if(!mp3file){ printf("file not found\n"); exit(1); }
36 GetCpuCaps(&gCpuCaps);
38 // MPEG Audio:
39 #ifdef USE_FAKE_MONO
40 MP3_Init(0);
41 #else
42 MP3_Init();
43 #endif
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);
54 while(1){
55 int len2;
56 if(len==0) len=MP3_DecodeFrame(buffer,-1);
57 if(len<=0) break; // EOF
59 // play it
60 len2=write(audio_fd,buffer,len);
61 if(len2<0) break; // ERROR?
62 len-=len2; total+=len2;
63 if(len>0){
64 // this shouldn't happen...
65 memcpy(buffer,buffer+len2,len);
66 putchar('!');fflush(stdout);
70 fclose(mp3file);