814
|
1
|
|
2 #define DUMP_PCM
|
788
|
3
|
826
|
4 // gcc test.c -I.. -L. -lMP3 -lm -o test1 -O4
|
788
|
5
|
|
6 #include <stdio.h>
|
|
7 #include <stdlib.h>
|
|
8
|
|
9 #include <unistd.h>
|
|
10 #include <sys/time.h>
|
|
11
|
|
12 #include "mp3lib/mp3.h"
|
|
13 #include "config.h"
|
|
14
|
|
15 static inline unsigned int GetTimer(){
|
|
16 struct timeval tv;
|
|
17 struct timezone tz;
|
|
18 // float s;
|
|
19 gettimeofday(&tv,&tz);
|
|
20 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
|
|
21 return (tv.tv_sec*1000000+tv.tv_usec);
|
|
22 }
|
|
23
|
|
24 static FILE* mp3file=NULL;
|
|
25
|
|
26 int mplayer_audio_read(char *buf,int size){
|
|
27 return fread(buf,1,size,mp3file);
|
|
28 }
|
|
29
|
|
30 #define BUFFLEN 4608
|
|
31 static unsigned char buffer[BUFFLEN];
|
|
32
|
|
33 int main(int argc,char* argv[]){
|
|
34 int len;
|
|
35 int total=0;
|
|
36 unsigned int time1;
|
|
37 float length;
|
814
|
38 #ifdef DUMP_PCM
|
|
39 FILE *f=NULL;
|
|
40 f=fopen("test.pcm","wb");
|
|
41 #endif
|
788
|
42
|
|
43 mp3file=fopen((argc>1)?argv[1]:"test.mp3","rb");
|
|
44 if(!mp3file){ printf("file not found\n"); exit(1); }
|
|
45
|
|
46 // MPEG Audio:
|
|
47 #ifdef USE_FAKE_MONO
|
|
48 MP3_Init(0);
|
|
49 #else
|
|
50 MP3_Init();
|
|
51 #endif
|
|
52 MP3_samplerate=MP3_channels=0;
|
|
53
|
|
54 time1=GetTimer();
|
814
|
55 while((len=MP3_DecodeFrame(buffer,-1))>0 && total<2000000){
|
788
|
56 total+=len;
|
|
57 // play it
|
814
|
58 #ifdef DUMP_PCM
|
|
59 fwrite(buffer,len,1,f);
|
|
60 #endif
|
788
|
61 //putchar('.');fflush(stdout);
|
|
62 }
|
|
63 time1=GetTimer()-time1;
|
|
64 length=(float)total/(float)(MP3_samplerate*MP3_channels*2);
|
|
65 printf("\nDecoding time: %8.6f\n",(float)time1*0.000001f);
|
|
66 printf("Uncompressed size: %d bytes (%8.3f secs)\n",total,length);
|
|
67 printf("CPU usage at normal playback: %5.2f %\n",time1*0.0001f/length);
|
|
68
|
|
69 fclose(mp3file);
|
|
70
|
|
71 }
|