comparison mp3lib/test2.c @ 789:989b921361d0

test2 added for playback test, testreanmed to test1 to make Atmosfear happy...
author arpi_esp
date Sun, 13 May 2001 19:18:52 +0000
parents
children 93304e7353c8
comparison
equal deleted inserted replaced
788:214ea3f02d13 789:989b921361d0
1
2 // gcc test.c -I.. -L. -lMP3 -o test -O4
3
4 #include <stdio.h>
5 #include <stdlib.h>
6
7 #include <fcntl.h>
8 #include <sys/ioctl.h>
9 #include <unistd.h>
10 #include <sys/soundcard.h>
11
12 #include "mp3lib/mp3.h"
13 #include "config.h"
14
15 static FILE* mp3file=NULL;
16
17 int mplayer_audio_read(char *buf,int size){
18 return fread(buf,1,size,mp3file);
19 }
20
21 #define BUFFLEN 4608
22 static unsigned char buffer[BUFFLEN];
23
24 int main(int argc,char* argv[]){
25 int len;
26 int total=0;
27 float length;
28 int r;
29 int audio_fd;
30
31 mp3file=fopen((argc>1)?argv[1]:"test.mp3","rb");
32 if(!mp3file){ printf("file not found\n"); exit(1); }
33
34 // MPEG Audio:
35 #ifdef USE_FAKE_MONO
36 MP3_Init(0);
37 #else
38 MP3_Init();
39 #endif
40 MP3_samplerate=MP3_channels=0;
41 len=MP3_DecodeFrame(buffer,-1);
42
43 audio_fd=open("/dev/dsp", O_WRONLY);
44 if(audio_fd<0){ printf("Can't open audio device\n");exit(1); }
45 r=AFMT_S16_LE;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r);
46 r=MP3_channels-1;ioctl (audio_fd, SNDCTL_DSP_STEREO, &r);
47 r=MP3_samplerate;ioctl (audio_fd, SNDCTL_DSP_SPEED, &r);
48 printf("audio_setup: using %d Hz samplerate (requested: %d)\n",r,MP3_samplerate);
49
50 while(1){
51 int len2;
52 if(len==0) len=MP3_DecodeFrame(buffer,-1);
53 if(len<=0) break; // EOF
54
55 // play it
56 len2=write(audio_fd,buffer,len);
57 if(len2<0) break; // ERROR?
58 len-=len2; total+=len2;
59 if(len>0){
60 // this shouldn't happen...
61 memcpy(buffer,buffer+len2,len);
62 putchar('!');fflush(stdout);
63 }
64 }
65
66 fclose(mp3file);
67
68 }