libfaad2: cosmetics: Make local_changes.diff apply cleanly
[mplayer.git] / mp3lib / test.c
blob446d45400802709d39ed2efea168771d192c62c0
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #define DUMP_PCM
21 #include <stdio.h>
22 #include <stdlib.h>
24 #include <unistd.h>
25 #include <sys/time.h>
27 #include "config.h"
28 #include "mp3lib/mp3.h"
29 #include "cpudetect.h"
31 static inline unsigned int GetTimer(void){
32 struct timeval tv;
33 struct timezone tz;
34 // float s;
35 gettimeofday(&tv,&tz);
36 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
37 return tv.tv_sec * 1000000 + tv.tv_usec;
40 static FILE* mp3file=NULL;
42 int mplayer_audio_read(char *buf,int size){
43 return fread(buf,1,size,mp3file);
46 #define BUFFLEN 4608
47 static unsigned char buffer[BUFFLEN];
49 int main(int argc,char* argv[]){
50 int len;
51 int total=0;
52 unsigned int time1;
53 float length;
54 #ifdef DUMP_PCM
55 FILE *f=NULL;
56 f=fopen("test.pcm","wb");
57 #endif
59 mp3file=fopen((argc>1)?argv[1]:"test.mp3","rb");
60 if(!mp3file){ printf("file not found\n"); exit(1); }
62 GetCpuCaps(&gCpuCaps);
64 // MPEG Audio:
65 #ifdef CONFIG_FAKE_MONO
66 MP3_Init(0);
67 #else
68 MP3_Init();
69 #endif
70 MP3_samplerate=MP3_channels=0;
72 time1=GetTimer();
73 while((len=MP3_DecodeFrame(buffer,-1))>0 && total<2000000){
74 total+=len;
75 // play it
76 #ifdef DUMP_PCM
77 fwrite(buffer,len,1,f);
78 #endif
79 //putchar('.');fflush(stdout);
81 time1=GetTimer()-time1;
82 length=(float)total/(float)(MP3_samplerate*MP3_channels*2);
83 printf("\nDecoding time: %8.6f\n",(float)time1*0.000001f);
84 printf("Uncompressed size: %d bytes (%8.3f secs)\n",total,length);
85 printf("CPU usage at normal playback: %5.2f %%\n",time1*0.0001f/length);
87 fclose(mp3file);
88 return 0;