Allow compilation with gcc 2.95.3 if videodev2.h does not support it.
[mplayer.git] / mp3lib / test2.c
blobf9bcfc073f25a715aeaaefea2676852348494384
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include <fcntl.h>
6 #include <sys/ioctl.h>
7 #include <unistd.h>
8 #include <sys/soundcard.h>
10 #include "config.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);
20 #define BUFFLEN 4608
21 static unsigned char buffer[BUFFLEN];
24 int main(int argc,char* argv[]){
25 int len;
26 int total=0;
27 int r;
28 int audio_fd;
30 mp3file=fopen((argc>1)?argv[1]:"test.mp3","rb");
31 if(!mp3file){ printf("file not found\n"); exit(1); }
33 GetCpuCaps(&gCpuCaps);
35 // MPEG Audio:
36 #ifdef CONFIG_FAKE_MONO
37 MP3_Init(0);
38 #else
39 MP3_Init();
40 #endif
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);
51 while(1){
52 int len2;
53 if(len==0) len=MP3_DecodeFrame(buffer,-1);
54 if(len<=0) break; // EOF
56 // play it
57 len2=write(audio_fd,buffer,len);
58 if(len2<0) break; // ERROR?
59 len-=len2; total+=len2;
60 if(len>0){
61 // this shouldn't happen...
62 memcpy(buffer,buffer+len2,len);
63 putchar('!');fflush(stdout);
67 fclose(mp3file);
68 return 0;