#define DR_MP3_IMPLEMENTATION #include "dr_mp3.h" #include #include #include #include static double now(){ struct timespec ts; clock_gettime(CLOCK_MONOTONIC,&ts); return ts.tv_sec+ts.tv_nsec*1e-9; } int main(int argc,char**argv){ if(argc<2){fprintf(stderr,"usage: %s file.mp3\n",argv[0]);return 1;} drmp3 d; if(!drmp3_init_file(&d,argv[1],NULL)){fprintf(stderr,"open fail\n");return 1;} printf("rate=%d ch=%d\n",d.sampleRate,d.channels); float *pcm=malloc(2048*2*sizeof(float)); double t0=now(); long long frames=0; drmp3_uint64 n; while((n=drmp3_read_pcm_frames_f32(&d,2048,pcm))!=0){ frames+=n; } double t1=now(); printf("total_pcm_frames=%lld\n",frames); printf("wall=%.3f s throughput=%.1f xRT (%.1f frames/s)\n",(t1-t0), (double)frames/d.sampleRate/(t1-t0),(double)frames/(t1-t0)); drmp3_uninit(&d); free(pcm); return 0; }