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