#include #include #include #include #define OPUS_PI (3.14159265F) #define OPUS_MIN(_x,_y) ((_x)<(_y)?(_x):(_y)) #define OPUS_MAX(_x,_y) ((_x)>(_y)?(_x):(_y)) #define OPUS_CLAMP(_a,_b,_c) OPUS_MAX(_a,OPUS_MIN(_b,_c)) #define OPUS_COSF(_x) ((float)cos(_x)) #define OPUS_SINF(_x) ((float)sin(_x)) #define OPUS_SQRTF(_x) ((float)sqrt(_x)) #define OPUS_LOG10F(_x) ((float)log10(_x)) static void *check_alloc(void *_ptr){ if(_ptr==NULL){ fprintf(stderr,"Out of memory.\n"); exit(EXIT_FAILURE); } return _ptr; } static void *opus_malloc(size_t _size){ return check_alloc(malloc(_size)); } static void *opus_realloc(void *_ptr,size_t _size){ return check_alloc(realloc(_ptr,_size)); } static size_t read_pcm16(float **_samples,FILE *_fin, int _nchannels){ unsigned char buf[1024]; float *samples; size_t nsamples; size_t csamples; size_t xi; size_t nread; samples=NULL; nsamples=csamples=0; for(;;){ nread=fread(buf,2*_nchannels,1024/(2*_nchannels),_fin); if(nread<=0)break; if(nsamples+nread>csamples){ do csamples=csamples<<1|1; while(nsamples+nread>csamples); samples=(float *)opus_realloc(samples, _nchannels*csamples*sizeof(*samples)); } for(xi=0;xi=_window_sz)ti-=_window_sz; } p+=OPUS_SQRTF(re*re+im*im); } p*=(1.0F/_nchannels); e2+=p*p; } _out[xi*_nbands+bi]=e2/(_bands[bi+1]-_bands[bi])+1; } } free(window); } static int cmp_float(const void *_a,const void *_b){ float a; float b; a=*(const float *)_a; b=*(const float *)_b; return (a>b)-(a>1) int main(int _argc,const char **_argv){ FILE *fin1; FILE *fin2; float *x; float *y; float *xb; float *eb; float *nmr; float thresh; float mismatch; float err; float nmr_sum; size_t weight; size_t xlength; size_t ylength; size_t nframes; size_t xi; int bi; int nchannels; if(_argc<3||_argc>4){ fprintf(stderr,"Usage: %s [-s] \n", _argv[0]); return EXIT_FAILURE; } nchannels=1; if(strcmp(_argv[1],"-s")==0)nchannels=2; fin1=fopen(_argv[nchannels],"rb"); if(fin1==NULL){ fprintf(stderr,"Error opening '%s'.\n",_argv[nchannels]); return EXIT_FAILURE; } fin2=fopen(_argv[nchannels+1],"rb"); if(fin2==NULL){ fprintf(stderr,"Error opening '%s'.\n",_argv[nchannels+1]); fclose(fin1); return EXIT_FAILURE; } /*Read in the data and allocate scratch space.*/ xlength=read_pcm16(&x,fin1,nchannels); fclose(fin1); ylength=read_pcm16(&y,fin2,nchannels); fclose(fin2); if(xlength!=ylength){ fprintf(stderr,"Sample counts do not match (%lu!=%lu).\n", (unsigned long)xlength,(unsigned long)ylength); return EXIT_FAILURE; } if(xlength0;) xb[xi*NBANDS+bi]+=0.03F*xb[xi*NBANDS+bi+1]; if(xi>0){ /*Temporal masking: 5 dB/5ms slope.*/ for(bi=0;bithresh){ mismatch+=NMR_THRESH[bi]/nmr[xi*NBANDS+bi]; weight++; } } } free(nmr); free(eb); printf("Average pseudo-NMR: %3.2f dB\n",nmr_sum/(nframes*NBANDS)); if(weight<=0){ err=-100; printf("Mismatch level: below noise floor\n"); } else{ err=10*OPUS_LOG10F(mismatch/weight); printf("Weighted mismatch: %3.2f dB\n",err); } printf("\n"); if(err<0){ printf("**Decoder PASSES test (mismatch < 0 dB)\n"); return EXIT_SUCCESS; } printf("**Decoder FAILS test (mismatch >= 0 dB)\n"); return EXIT_FAILURE; }