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