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