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