A lot of updates
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
INCLUDES = -I$(top_srcdir)/libcelt
|
||||
METASOURCES = AUTO
|
||||
|
||||
TESTS = type-test ectest cwrs32-test dft-test laplace-test mdct-test mathops-test tandem-test
|
||||
|
||||
noinst_PROGRAMS = type-test ectest cwrs32-test dft-test laplace-test mdct-test mathops-test tandem-test
|
||||
|
||||
type_test_SOURCES = type-test.c
|
||||
ectest_SOURCES = ectest.c
|
||||
cwrs32_test_SOURCES = cwrs32-test.c
|
||||
dft_test_SOURCES = dft-test.c
|
||||
laplace_test_SOURCES = laplace-test.c
|
||||
mdct_test_SOURCES = mdct-test.c
|
||||
#rotation_test_SOURCES = rotation-test.c
|
||||
mathops_test_SOURCES = mathops-test.c
|
||||
tandem_test_SOURCES = tandem-test.c
|
||||
tandem_test_LDADD = $(top_builddir)/libcelt/libcelt@LIBCELT_SUFFIX@.la
|
||||
@@ -1,176 +0,0 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define CELT_C
|
||||
#include "../libcelt/stack_alloc.h"
|
||||
#include "../libcelt/entenc.c"
|
||||
#include "../libcelt/entdec.c"
|
||||
#include "../libcelt/entcode.c"
|
||||
#include "../libcelt/cwrs.c"
|
||||
#include "../libcelt/mathops.c"
|
||||
|
||||
#define NMAX (14)
|
||||
#define KMAX (32767)
|
||||
|
||||
static const int kmax[15]={
|
||||
32767,32767,32767,32767, 1172,
|
||||
238, 95, 53, 36, 27,
|
||||
22, 18, 16, 15, 13
|
||||
};
|
||||
|
||||
|
||||
int main(int _argc,char **_argv){
|
||||
int n;
|
||||
ALLOC_STACK;
|
||||
for(n=2;n<=NMAX;n++){
|
||||
int dk;
|
||||
int k;
|
||||
dk=kmax[n]>7?kmax[n]/7:1;
|
||||
k=1-dk;
|
||||
do{
|
||||
celt_uint32 uu[KMAX+2U];
|
||||
celt_uint32 inc;
|
||||
celt_uint32 nc;
|
||||
celt_uint32 i;
|
||||
k=kmax[n]-dk<k?kmax[n]:k+dk;
|
||||
printf("Testing CWRS with N=%i, K=%i...\n",n,k);
|
||||
nc=ncwrs_urow(n,k,uu);
|
||||
inc=nc/10000;
|
||||
if(inc<1)inc=1;
|
||||
for(i=0;i<nc;i+=inc){
|
||||
celt_uint32 u[KMAX+2U];
|
||||
int y[NMAX];
|
||||
int yy[5];
|
||||
celt_uint32 v;
|
||||
celt_uint32 ii;
|
||||
int kk;
|
||||
int j;
|
||||
memcpy(u,uu,(k+2U)*sizeof(*u));
|
||||
cwrsi(n,k,i,y,u);
|
||||
/*printf("%6u of %u:",i,nc);
|
||||
for(j=0;j<n;j++)printf(" %+3i",y[j]);
|
||||
printf(" ->");*/
|
||||
ii=icwrs(n,k,&v,y,u);
|
||||
if(ii!=i){
|
||||
fprintf(stderr,"Combination-index mismatch (%lu!=%lu).\n",
|
||||
(long)ii,(long)i);
|
||||
return 1;
|
||||
}
|
||||
if(v!=nc){
|
||||
fprintf(stderr,"Combination count mismatch (%lu!=%lu).\n",
|
||||
(long)v,(long)nc);
|
||||
return 2;
|
||||
}
|
||||
#ifndef SMALL_FOOTPRINT
|
||||
if(n==2){
|
||||
cwrsi2(k,i,yy);
|
||||
for(j=0;j<2;j++)if(yy[j]!=y[j]){
|
||||
fprintf(stderr,"N=2 pulse vector mismatch ({%i,%i}!={%i,%i}).\n",
|
||||
yy[0],yy[1],y[0],y[1]);
|
||||
return 3;
|
||||
}
|
||||
ii=icwrs2(yy,&kk);
|
||||
if(ii!=i){
|
||||
fprintf(stderr,"N=2 combination-index mismatch (%lu!=%lu).\n",
|
||||
(long)ii,(long)i);
|
||||
return 4;
|
||||
}
|
||||
if(kk!=k){
|
||||
fprintf(stderr,"N=2 pulse count mismatch (%i,%i).\n",kk,k);
|
||||
return 5;
|
||||
}
|
||||
v=ncwrs2(k);
|
||||
if(v!=nc){
|
||||
fprintf(stderr,"N=2 combination count mismatch (%lu,%lu).\n",
|
||||
(long)v,(long)nc);
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
else if(n==3){
|
||||
cwrsi3(k,i,yy);
|
||||
for(j=0;j<3;j++)if(yy[j]!=y[j]){
|
||||
fprintf(stderr,"N=3 pulse vector mismatch "
|
||||
"({%i,%i,%i}!={%i,%i,%i}).\n",yy[0],yy[1],yy[2],y[0],y[1],y[2]);
|
||||
return 7;
|
||||
}
|
||||
ii=icwrs3(yy,&kk);
|
||||
if(ii!=i){
|
||||
fprintf(stderr,"N=3 combination-index mismatch (%lu!=%lu).\n",
|
||||
(long)ii,(long)i);
|
||||
return 8;
|
||||
}
|
||||
if(kk!=k){
|
||||
fprintf(stderr,"N=3 pulse count mismatch (%i!=%i).\n",kk,k);
|
||||
return 9;
|
||||
}
|
||||
v=ncwrs3(k);
|
||||
if(v!=nc){
|
||||
fprintf(stderr,"N=3 combination count mismatch (%lu!=%lu).\n",
|
||||
(long)v,(long)nc);
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
else if(n==4){
|
||||
cwrsi4(k,i,yy);
|
||||
for(j=0;j<4;j++)if(yy[j]!=y[j]){
|
||||
fprintf(stderr,"N=4 pulse vector mismatch "
|
||||
"({%i,%i,%i,%i}!={%i,%i,%i,%i}.\n",
|
||||
yy[0],yy[1],yy[2],yy[3],y[0],y[1],y[2],y[3]);
|
||||
return 11;
|
||||
}
|
||||
ii=icwrs4(yy,&kk);
|
||||
if(ii!=i){
|
||||
fprintf(stderr,"N=4 combination-index mismatch (%lu!=%lu).\n",
|
||||
(long)ii,(long)i);
|
||||
return 12;
|
||||
}
|
||||
if(kk!=k){
|
||||
fprintf(stderr,"N=4 pulse count mismatch (%i!=%i).\n",kk,k);
|
||||
return 13;
|
||||
}
|
||||
v=ncwrs4(k);
|
||||
if(v!=nc){
|
||||
fprintf(stderr,"N=4 combination count mismatch (%lu!=%lu).\n",
|
||||
(long)v,(long)nc);
|
||||
return 14;
|
||||
}
|
||||
}
|
||||
else if(n==5){
|
||||
cwrsi5(k,i,yy);
|
||||
for(j=0;j<5;j++)if(yy[j]!=y[j]){
|
||||
fprintf(stderr,"N=5 pulse vector mismatch "
|
||||
"({%i,%i,%i,%i,%i}!={%i,%i,%i,%i,%i}).\n",
|
||||
yy[0],yy[1],yy[2],yy[3],yy[4],y[0],y[1],y[2],y[3],y[4]);
|
||||
return 15;
|
||||
}
|
||||
ii=icwrs5(yy,&kk);
|
||||
if(ii!=i){
|
||||
fprintf(stderr,"N=5 combination-index mismatch (%lu!=%lu).\n",
|
||||
(long)ii,(long)i);
|
||||
return 16;
|
||||
}
|
||||
if(kk!=k){
|
||||
fprintf(stderr,"N=5 pulse count mismatch (%i!=%i).\n",kk,k);
|
||||
return 17;
|
||||
}
|
||||
v=ncwrs5(k);
|
||||
if(v!=nc){
|
||||
fprintf(stderr,"N=5 combination count mismatch (%lu!=%lu).\n",
|
||||
(long)v,(long)nc);
|
||||
return 18;
|
||||
}
|
||||
}
|
||||
#endif /* SMALL_FOOTPRINT */
|
||||
|
||||
/*printf(" %6u\n",i);*/
|
||||
}
|
||||
/*printf("\n");*/
|
||||
}
|
||||
while(k<kmax[n]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#define SKIP_CONFIG_H
|
||||
|
||||
#ifndef CUSTOM_MODES
|
||||
#define CUSTOM_MODES
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "kiss_fft.h"
|
||||
|
||||
#define CELT_C
|
||||
#include "../libcelt/stack_alloc.h"
|
||||
#include "../libcelt/kiss_fft.c"
|
||||
#include "../libcelt/mathops.c"
|
||||
#include "../libcelt/entcode.c"
|
||||
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.141592653
|
||||
#endif
|
||||
|
||||
#ifdef FIXED_DEBUG
|
||||
long long celt_mips=0;
|
||||
#endif
|
||||
int ret = 0;
|
||||
|
||||
void check(kiss_fft_cpx * in,kiss_fft_cpx * out,int nfft,int isinverse)
|
||||
{
|
||||
int bin,k;
|
||||
double errpow=0,sigpow=0, snr;
|
||||
|
||||
for (bin=0;bin<nfft;++bin) {
|
||||
double ansr = 0;
|
||||
double ansi = 0;
|
||||
double difr;
|
||||
double difi;
|
||||
|
||||
for (k=0;k<nfft;++k) {
|
||||
double phase = -2*M_PI*bin*k/nfft;
|
||||
double re = cos(phase);
|
||||
double im = sin(phase);
|
||||
if (isinverse)
|
||||
im = -im;
|
||||
|
||||
if (!isinverse)
|
||||
{
|
||||
re /= nfft;
|
||||
im /= nfft;
|
||||
}
|
||||
|
||||
ansr += in[k].r * re - in[k].i * im;
|
||||
ansi += in[k].r * im + in[k].i * re;
|
||||
}
|
||||
/*printf ("%d %d ", (int)ansr, (int)ansi);*/
|
||||
difr = ansr - out[bin].r;
|
||||
difi = ansi - out[bin].i;
|
||||
errpow += difr*difr + difi*difi;
|
||||
sigpow += ansr*ansr+ansi*ansi;
|
||||
}
|
||||
snr = 10*log10(sigpow/errpow);
|
||||
printf("nfft=%d inverse=%d,snr = %f\n",nfft,isinverse,snr );
|
||||
if (snr<60) {
|
||||
printf( "** poor snr: %f ** \n", snr);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void test1d(int nfft,int isinverse)
|
||||
{
|
||||
size_t buflen = sizeof(kiss_fft_cpx)*nfft;
|
||||
|
||||
kiss_fft_cpx * in = (kiss_fft_cpx*)malloc(buflen);
|
||||
kiss_fft_cpx * out= (kiss_fft_cpx*)malloc(buflen);
|
||||
kiss_fft_state *cfg = kiss_fft_alloc(nfft,0,0);
|
||||
int k;
|
||||
|
||||
for (k=0;k<nfft;++k) {
|
||||
in[k].r = (rand() % 32767) - 16384;
|
||||
in[k].i = (rand() % 32767) - 16384;
|
||||
}
|
||||
|
||||
#ifdef DOUBLE_PRECISION
|
||||
for (k=0;k<nfft;++k) {
|
||||
in[k].r *= 32768;
|
||||
in[k].i *= 32768;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (isinverse)
|
||||
{
|
||||
for (k=0;k<nfft;++k) {
|
||||
in[k].r /= nfft;
|
||||
in[k].i /= nfft;
|
||||
}
|
||||
}
|
||||
|
||||
/*for (k=0;k<nfft;++k) printf("%d %d ", in[k].r, in[k].i);printf("\n");*/
|
||||
|
||||
if (isinverse)
|
||||
kiss_ifft(cfg,in,out);
|
||||
else
|
||||
kiss_fft(cfg,in,out);
|
||||
|
||||
/*for (k=0;k<nfft;++k) printf("%d %d ", out[k].r, out[k].i);printf("\n");*/
|
||||
|
||||
check(in,out,nfft,isinverse);
|
||||
|
||||
free(in);
|
||||
free(out);
|
||||
free(cfg);
|
||||
}
|
||||
|
||||
int main(int argc,char ** argv)
|
||||
{
|
||||
ALLOC_STACK;
|
||||
if (argc>1) {
|
||||
int k;
|
||||
for (k=1;k<argc;++k) {
|
||||
test1d(atoi(argv[k]),0);
|
||||
test1d(atoi(argv[k]),1);
|
||||
}
|
||||
}else{
|
||||
test1d(32,0);
|
||||
test1d(32,1);
|
||||
test1d(128,0);
|
||||
test1d(128,1);
|
||||
test1d(256,0);
|
||||
test1d(256,1);
|
||||
#ifndef RADIX_TWO_ONLY
|
||||
test1d(36,0);
|
||||
test1d(36,1);
|
||||
test1d(50,0);
|
||||
test1d(50,1);
|
||||
test1d(120,0);
|
||||
test1d(120,1);
|
||||
#endif
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1,265 +0,0 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include "entcode.h"
|
||||
#include "entenc.h"
|
||||
#include "entdec.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "../libcelt/entenc.c"
|
||||
#include "../libcelt/entdec.c"
|
||||
#include "../libcelt/entcode.c"
|
||||
|
||||
#ifndef M_LOG2E
|
||||
# define M_LOG2E 1.4426950408889634074
|
||||
#endif
|
||||
#define DATA_SIZE 10000000
|
||||
#define DATA_SIZE2 10000
|
||||
|
||||
int main(int _argc,char **_argv){
|
||||
ec_enc enc;
|
||||
ec_dec dec;
|
||||
long nbits;
|
||||
long nbits2;
|
||||
double entropy;
|
||||
int ft;
|
||||
int ftb;
|
||||
int sym;
|
||||
int sz;
|
||||
int i;
|
||||
int ret;
|
||||
unsigned int seed;
|
||||
unsigned char *ptr;
|
||||
ret=0;
|
||||
entropy=0;
|
||||
if (_argc > 2) {
|
||||
fprintf(stderr, "Usage: %s [<seed>]\n", _argv[0]);
|
||||
return 1;
|
||||
}
|
||||
if (_argc > 1)
|
||||
seed = atoi(_argv[1]);
|
||||
else
|
||||
seed = time(NULL);
|
||||
/*Testing encoding of raw bit values.*/
|
||||
ptr = malloc(DATA_SIZE);
|
||||
ec_enc_init(&enc,ptr, DATA_SIZE);
|
||||
for(ft=2;ft<1024;ft++){
|
||||
for(i=0;i<ft;i++){
|
||||
entropy+=log(ft)*M_LOG2E;
|
||||
ec_enc_uint(&enc,i,ft);
|
||||
}
|
||||
}
|
||||
/*Testing encoding of raw bit values.*/
|
||||
for(ftb=0;ftb<16;ftb++){
|
||||
for(i=0;i<(1<<ftb);i++){
|
||||
entropy+=ftb;
|
||||
nbits=ec_tell(&enc);
|
||||
ec_enc_bits(&enc,i,ftb);
|
||||
nbits2=ec_tell(&enc);
|
||||
if(nbits2-nbits!=ftb){
|
||||
fprintf(stderr,"Used %li bits to encode %i bits directly.\n",
|
||||
nbits2-nbits,ftb);
|
||||
ret=-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
nbits=ec_tell_frac(&enc);
|
||||
ec_enc_done(&enc);
|
||||
fprintf(stderr,
|
||||
"Encoded %0.2lf bits of entropy to %0.2lf bits (%0.3lf%% wasted).\n",
|
||||
entropy,ldexp(nbits,-3),100*(nbits-ldexp(entropy,3))/nbits);
|
||||
fprintf(stderr,"Packed to %li bytes.\n",(long)ec_range_bytes(&enc));
|
||||
ec_dec_init(&dec,ptr,DATA_SIZE);
|
||||
for(ft=2;ft<1024;ft++){
|
||||
for(i=0;i<ft;i++){
|
||||
sym=ec_dec_uint(&dec,ft);
|
||||
if(sym!=i){
|
||||
fprintf(stderr,"Decoded %i instead of %i with ft of %i.\n",sym,i,ft);
|
||||
ret=-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(ftb=0;ftb<16;ftb++){
|
||||
for(i=0;i<(1<<ftb);i++){
|
||||
sym=ec_dec_bits(&dec,ftb);
|
||||
if(sym!=i){
|
||||
fprintf(stderr,"Decoded %i instead of %i with ftb of %i.\n",sym,i,ftb);
|
||||
ret=-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
nbits2=ec_tell_frac(&dec);
|
||||
if(nbits!=nbits2){
|
||||
fprintf(stderr,
|
||||
"Reported number of bits used was %0.2lf, should be %0.2lf.\n",
|
||||
ldexp(nbits2,-3),ldexp(nbits,-3));
|
||||
ret=-1;
|
||||
}
|
||||
srand(seed);
|
||||
fprintf(stderr,"Testing random streams... Random seed: %u (%.4X)\n", seed, rand() % 65536);
|
||||
for(i=0;i<409600;i++){
|
||||
unsigned *data;
|
||||
unsigned *tell;
|
||||
int j;
|
||||
int tell_bits;
|
||||
int zeros;
|
||||
ft=rand()/((RAND_MAX>>(rand()%11))+1)+10;
|
||||
sz=rand()/((RAND_MAX>>(rand()%9))+1);
|
||||
data=(unsigned *)malloc(sz*sizeof(*data));
|
||||
tell=(unsigned *)malloc((sz+1)*sizeof(*tell));
|
||||
ec_enc_init(&enc,ptr,DATA_SIZE2);
|
||||
zeros = rand()%13==0;
|
||||
tell[0]=ec_tell_frac(&enc);
|
||||
for(j=0;j<sz;j++){
|
||||
if (zeros)
|
||||
data[j]=0;
|
||||
else
|
||||
data[j]=rand()%ft;
|
||||
ec_enc_uint(&enc,data[j],ft);
|
||||
tell[j+1]=ec_tell_frac(&enc);
|
||||
}
|
||||
if (rand()%2==0)
|
||||
while(ec_tell(&enc)%8 != 0)
|
||||
ec_enc_uint(&enc, rand()%2, 2);
|
||||
tell_bits = ec_tell(&enc);
|
||||
ec_enc_done(&enc);
|
||||
if(tell_bits!=ec_tell(&enc)){
|
||||
fprintf(stderr,"ec_tell() changed after ec_enc_done(): %i instead of %i (Random seed: %u)\n",
|
||||
ec_tell(&enc),tell_bits,seed);
|
||||
ret=-1;
|
||||
}
|
||||
if ((tell_bits+7)/8 < ec_range_bytes(&enc))
|
||||
{
|
||||
fprintf (stderr, "ec_tell() lied, there's %i bytes instead of %d (Random seed: %u)\n",
|
||||
ec_range_bytes(&enc), (tell_bits+7)/8,seed);
|
||||
ret=-1;
|
||||
}
|
||||
tell_bits -= 8*ec_range_bytes(&enc);
|
||||
ec_dec_init(&dec,ptr,DATA_SIZE2);
|
||||
if(ec_tell_frac(&dec)!=tell[0]){
|
||||
fprintf(stderr,
|
||||
"Tell mismatch between encoder and decoder at symbol %i: %i instead of %i (Random seed: %u).\n",
|
||||
0,ec_tell_frac(&dec),tell[0],seed);
|
||||
}
|
||||
for(j=0;j<sz;j++){
|
||||
sym=ec_dec_uint(&dec,ft);
|
||||
if(sym!=data[j]){
|
||||
fprintf(stderr,
|
||||
"Decoded %i instead of %i with ft of %i at position %i of %i (Random seed: %u).\n",
|
||||
sym,data[j],ft,j,sz,seed);
|
||||
ret=-1;
|
||||
}
|
||||
if(ec_tell_frac(&dec)!=tell[j+1]){
|
||||
fprintf(stderr,
|
||||
"Tell mismatch between encoder and decoder at symbol %i: %i instead of %i (Random seed: %u).\n",
|
||||
j+1,ec_tell_frac(&dec),tell[j+1],seed);
|
||||
}
|
||||
}
|
||||
free(tell);
|
||||
free(data);
|
||||
}
|
||||
/*Test compatibility between multiple different encode/decode routines.*/
|
||||
for(i=0;i<409600;i++){
|
||||
unsigned *logp1;
|
||||
unsigned *data;
|
||||
unsigned *tell;
|
||||
unsigned *enc_method;
|
||||
int j;
|
||||
sz=rand()/((RAND_MAX>>(rand()%9))+1);
|
||||
logp1=(unsigned *)malloc(sz*sizeof(*logp1));
|
||||
data=(unsigned *)malloc(sz*sizeof(*data));
|
||||
tell=(unsigned *)malloc((sz+1)*sizeof(*tell));
|
||||
enc_method=(unsigned *)malloc(sz*sizeof(*enc_method));
|
||||
ec_enc_init(&enc,ptr,DATA_SIZE2);
|
||||
tell[0]=ec_tell_frac(&enc);
|
||||
for(j=0;j<sz;j++){
|
||||
data[j]=rand()/((RAND_MAX>>1)+1);
|
||||
logp1[j]=(rand()%15)+1;
|
||||
enc_method[j]=rand()/((RAND_MAX>>2)+1);
|
||||
switch(enc_method[j]){
|
||||
case 0:{
|
||||
ec_encode(&enc,data[j]?(1<<logp1[j])-1:0,
|
||||
(1<<logp1[j])-(data[j]?0:1),1<<logp1[j]);
|
||||
}break;
|
||||
case 1:{
|
||||
ec_encode_bin(&enc,data[j]?(1<<logp1[j])-1:0,
|
||||
(1<<logp1[j])-(data[j]?0:1),logp1[j]);
|
||||
}break;
|
||||
case 2:{
|
||||
ec_enc_bit_logp(&enc,data[j],logp1[j]);
|
||||
}break;
|
||||
case 3:{
|
||||
unsigned char icdf[2];
|
||||
icdf[0]=1;
|
||||
icdf[1]=0;
|
||||
ec_enc_icdf(&enc,data[j],icdf,logp1[j]);
|
||||
}break;
|
||||
}
|
||||
tell[j+1]=ec_tell_frac(&enc);
|
||||
}
|
||||
ec_enc_done(&enc);
|
||||
if((ec_tell(&enc)+7)/8<ec_range_bytes(&enc)){
|
||||
fprintf(stderr,"tell() lied, there's %i bytes instead of %d (Random seed: %u)\n",
|
||||
ec_range_bytes(&enc),(ec_tell(&enc)+7)/8,seed);
|
||||
ret=-1;
|
||||
}
|
||||
ec_dec_init(&dec,ptr,DATA_SIZE2);
|
||||
if(ec_tell_frac(&dec)!=tell[0]){
|
||||
fprintf(stderr,
|
||||
"Tell mismatch between encoder and decoder at symbol %i: %i instead of %i (Random seed: %u).\n",
|
||||
0,ec_tell_frac(&dec),tell[0],seed);
|
||||
}
|
||||
for(j=0;j<sz;j++){
|
||||
int fs;
|
||||
int dec_method;
|
||||
dec_method=rand()/((RAND_MAX>>2)+1);
|
||||
switch(dec_method){
|
||||
case 0:{
|
||||
fs=ec_decode(&dec,1<<logp1[j]);
|
||||
sym=fs>=(1<<logp1[j])-1;
|
||||
ec_dec_update(&dec,sym?(1<<logp1[j])-1:0,
|
||||
(1<<logp1[j])-(sym?0:1),1<<logp1[j]);
|
||||
}break;
|
||||
case 1:{
|
||||
fs=ec_decode_bin(&dec,logp1[j]);
|
||||
sym=fs>=(1<<logp1[j])-1;
|
||||
ec_dec_update(&dec,sym?(1<<logp1[j])-1:0,
|
||||
(1<<logp1[j])-(sym?0:1),1<<logp1[j]);
|
||||
}break;
|
||||
case 2:{
|
||||
sym=ec_dec_bit_logp(&dec,logp1[j]);
|
||||
}break;
|
||||
case 3:{
|
||||
unsigned char icdf[2];
|
||||
icdf[0]=1;
|
||||
icdf[1]=0;
|
||||
sym=ec_dec_icdf(&dec,icdf,logp1[j]);
|
||||
}break;
|
||||
}
|
||||
if(sym!=data[j]){
|
||||
fprintf(stderr,
|
||||
"Decoded %i instead of %i with logp1 of %i at position %i of %i (Random seed: %u).\n",
|
||||
sym,data[j],logp1[j],j,sz,seed);
|
||||
fprintf(stderr,"Encoding method: %i, decoding method: %i\n",
|
||||
enc_method[j],dec_method);
|
||||
ret=-1;
|
||||
}
|
||||
if(ec_tell_frac(&dec)!=tell[j+1]){
|
||||
fprintf(stderr,
|
||||
"Tell mismatch between encoder and decoder at symbol %i: %i instead of %i (Random seed: %u).\n",
|
||||
j+1,ec_tell_frac(&dec),tell[j+1],seed);
|
||||
}
|
||||
}
|
||||
free(enc_method);
|
||||
free(tell);
|
||||
free(data);
|
||||
free(logp1);
|
||||
}
|
||||
free(ptr);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "laplace.h"
|
||||
#define CELT_C
|
||||
#include "../libcelt/stack_alloc.h"
|
||||
|
||||
#include "../libcelt/entenc.c"
|
||||
#include "../libcelt/entdec.c"
|
||||
#include "../libcelt/entcode.c"
|
||||
#include "../libcelt/laplace.c"
|
||||
|
||||
#define DATA_SIZE 40000
|
||||
|
||||
int ec_laplace_get_start_freq(int decay)
|
||||
{
|
||||
celt_uint32 ft = 32768 - LAPLACE_MINP*(2*LAPLACE_NMIN+1);
|
||||
int fs = (ft*(16384-decay))/(16384+decay);
|
||||
return fs+LAPLACE_MINP;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
int ret = 0;
|
||||
ec_enc enc;
|
||||
ec_dec dec;
|
||||
unsigned char *ptr;
|
||||
int val[10000], decay[10000];
|
||||
ALLOC_STACK;
|
||||
ptr = malloc(DATA_SIZE);
|
||||
ec_enc_init(&enc,ptr,DATA_SIZE);
|
||||
|
||||
val[0] = 3; decay[0] = 6000;
|
||||
val[1] = 0; decay[1] = 5800;
|
||||
val[2] = -1; decay[2] = 5600;
|
||||
for (i=3;i<10000;i++)
|
||||
{
|
||||
val[i] = rand()%15-7;
|
||||
decay[i] = rand()%11000+5000;
|
||||
}
|
||||
for (i=0;i<10000;i++)
|
||||
ec_laplace_encode(&enc, &val[i],
|
||||
ec_laplace_get_start_freq(decay[i]), decay[i]);
|
||||
|
||||
ec_enc_done(&enc);
|
||||
|
||||
ec_dec_init(&dec,ec_get_buffer(&enc),ec_range_bytes(&enc));
|
||||
|
||||
for (i=0;i<10000;i++)
|
||||
{
|
||||
int d = ec_laplace_decode(&dec,
|
||||
ec_laplace_get_start_freq(decay[i]), decay[i]);
|
||||
if (d != val[i])
|
||||
{
|
||||
fprintf (stderr, "Got %d instead of %d\n", d, val[i]);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "mathops.c"
|
||||
#include "entcode.c"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef FIXED_POINT
|
||||
#define WORD "%d"
|
||||
#else
|
||||
#define WORD "%f"
|
||||
#endif
|
||||
|
||||
#ifdef FIXED_DEBUG
|
||||
long long celt_mips=0;
|
||||
#endif
|
||||
int ret = 0;
|
||||
|
||||
void testdiv(void)
|
||||
{
|
||||
celt_int32 i;
|
||||
for (i=1;i<=327670;i++)
|
||||
{
|
||||
double prod;
|
||||
celt_word32 val;
|
||||
val = celt_rcp(i);
|
||||
#ifdef FIXED_POINT
|
||||
prod = (1./32768./65526.)*val*i;
|
||||
#else
|
||||
prod = val*i;
|
||||
#endif
|
||||
if (fabs(prod-1) > .00025)
|
||||
{
|
||||
fprintf (stderr, "div failed: 1/%d="WORD" (product = %f)\n", i, val, prod);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testsqrt(void)
|
||||
{
|
||||
celt_int32 i;
|
||||
for (i=1;i<=1000000000;i++)
|
||||
{
|
||||
double ratio;
|
||||
celt_word16 val;
|
||||
val = celt_sqrt(i);
|
||||
ratio = val/sqrt(i);
|
||||
if (fabs(ratio - 1) > .0005 && fabs(val-sqrt(i)) > 2)
|
||||
{
|
||||
fprintf (stderr, "sqrt failed: sqrt(%d)="WORD" (ratio = %f)\n", i, val, ratio);
|
||||
ret = 1;
|
||||
}
|
||||
i+= i>>10;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef FIXED_POINT
|
||||
void testlog2(void)
|
||||
{
|
||||
float x;
|
||||
for (x=0.001;x<1677700.0;x+=(x/8.0))
|
||||
{
|
||||
float error = fabs((1.442695040888963387*log(x))-celt_log2(x));
|
||||
if (error>0.0009)
|
||||
{
|
||||
fprintf (stderr, "celt_log2 failed: fabs((1.442695040888963387*log(x))-celt_log2(x))>0.001 (x = %f, error = %f)\n", x,error);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testexp2(void)
|
||||
{
|
||||
float x;
|
||||
for (x=-11.0;x<24.0;x+=0.0007)
|
||||
{
|
||||
float error = fabs(x-(1.442695040888963387*log(celt_exp2(x))));
|
||||
if (error>0.0002)
|
||||
{
|
||||
fprintf (stderr, "celt_exp2 failed: fabs(x-(1.442695040888963387*log(celt_exp2(x))))>0.0005 (x = %f, error = %f)\n", x,error);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testexp2log2(void)
|
||||
{
|
||||
float x;
|
||||
for (x=-11.0;x<24.0;x+=0.0007)
|
||||
{
|
||||
float error = fabs(x-(celt_log2(celt_exp2(x))));
|
||||
if (error>0.001)
|
||||
{
|
||||
fprintf (stderr, "celt_log2/celt_exp2 failed: fabs(x-(celt_log2(celt_exp2(x))))>0.001 (x = %f, error = %f)\n", x,error);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
void testlog2(void)
|
||||
{
|
||||
celt_word32 x;
|
||||
for (x=8;x<1073741824;x+=(x>>3))
|
||||
{
|
||||
float error = fabs((1.442695040888963387*log(x/16384.0))-celt_log2(x)/1024.0);
|
||||
if (error>0.003)
|
||||
{
|
||||
fprintf (stderr, "celt_log2 failed: x = %ld, error = %f\n", (long)x,error);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testexp2(void)
|
||||
{
|
||||
celt_word16 x;
|
||||
for (x=-32768;x<-30720;x++)
|
||||
{
|
||||
float error1 = fabs(x/2048.0-(1.442695040888963387*log(celt_exp2(x)/65536.0)));
|
||||
float error2 = fabs(exp(0.6931471805599453094*x/2048.0)-celt_exp2(x)/65536.0);
|
||||
if (error1>0.0002&&error2>0.00004)
|
||||
{
|
||||
fprintf (stderr, "celt_exp2 failed: x = "WORD", error1 = %f, error2 = %f\n", x,error1,error2);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testexp2log2(void)
|
||||
{
|
||||
celt_word32 x;
|
||||
for (x=8;x<65536;x+=(x>>3))
|
||||
{
|
||||
float error = fabs(x-0.25*celt_exp2(celt_log2(x)<<1))/16384;
|
||||
if (error>0.004)
|
||||
{
|
||||
fprintf (stderr, "celt_log2/celt_exp2 failed: fabs(x-(celt_exp2(celt_log2(x))))>0.001 (x = %ld, error = %f)\n", (long)x,error);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testilog2(void)
|
||||
{
|
||||
celt_word32 x;
|
||||
for (x=1;x<=268435455;x+=127)
|
||||
{
|
||||
celt_word32 error = abs(celt_ilog2(x)-(int)floor(log2(x)));
|
||||
if (error!=0)
|
||||
{
|
||||
printf("celt_ilog2 failed: celt_ilog2(x)!=floor(log2(x)) (x = %d, error = %d)\n",x,error);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
testdiv();
|
||||
testsqrt();
|
||||
testlog2();
|
||||
testexp2();
|
||||
testexp2log2();
|
||||
#ifdef FIXED_POINT
|
||||
testilog2();
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
@@ -1,169 +0,0 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#define SKIP_CONFIG_H
|
||||
|
||||
#ifndef CUSTOM_MODES
|
||||
#define CUSTOM_MODES
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "mdct.h"
|
||||
#define CELT_C
|
||||
#include "../libcelt/stack_alloc.h"
|
||||
|
||||
#include "../libcelt/kiss_fft.c"
|
||||
#include "../libcelt/mdct.c"
|
||||
#include "../libcelt/mathops.c"
|
||||
#include "../libcelt/entcode.c"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.141592653
|
||||
#endif
|
||||
|
||||
#ifdef FIXED_DEBUG
|
||||
long long celt_mips=0;
|
||||
#endif
|
||||
int ret = 0;
|
||||
void check(kiss_fft_scalar * in,kiss_fft_scalar * out,int nfft,int isinverse)
|
||||
{
|
||||
int bin,k;
|
||||
double errpow=0,sigpow=0;
|
||||
double snr;
|
||||
for (bin=0;bin<nfft/2;++bin) {
|
||||
double ansr = 0;
|
||||
double difr;
|
||||
|
||||
for (k=0;k<nfft;++k) {
|
||||
double phase = 2*M_PI*(k+.5+.25*nfft)*(bin+.5)/nfft;
|
||||
double re = cos(phase);
|
||||
|
||||
re /= nfft/4;
|
||||
|
||||
ansr += in[k] * re;
|
||||
}
|
||||
/*printf ("%f %f\n", ansr, out[bin]);*/
|
||||
difr = ansr - out[bin];
|
||||
errpow += difr*difr;
|
||||
sigpow += ansr*ansr;
|
||||
}
|
||||
snr = 10*log10(sigpow/errpow);
|
||||
printf("nfft=%d inverse=%d,snr = %f\n",nfft,isinverse,snr );
|
||||
if (snr<60) {
|
||||
printf( "** poor snr: %f **\n", snr);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void check_inv(kiss_fft_scalar * in,kiss_fft_scalar * out,int nfft,int isinverse)
|
||||
{
|
||||
int bin,k;
|
||||
double errpow=0,sigpow=0;
|
||||
double snr;
|
||||
for (bin=0;bin<nfft;++bin) {
|
||||
double ansr = 0;
|
||||
double difr;
|
||||
|
||||
for (k=0;k<nfft/2;++k) {
|
||||
double phase = 2*M_PI*(bin+.5+.25*nfft)*(k+.5)/nfft;
|
||||
double re = cos(phase);
|
||||
|
||||
//re *= 2;
|
||||
|
||||
ansr += in[k] * re;
|
||||
}
|
||||
/*printf ("%f %f\n", ansr, out[bin]);*/
|
||||
difr = ansr - out[bin];
|
||||
errpow += difr*difr;
|
||||
sigpow += ansr*ansr;
|
||||
}
|
||||
snr = 10*log10(sigpow/errpow);
|
||||
printf("nfft=%d inverse=%d,snr = %f\n",nfft,isinverse,snr );
|
||||
if (snr<60) {
|
||||
printf( "** poor snr: %f **\n", snr);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void test1d(int nfft,int isinverse)
|
||||
{
|
||||
mdct_lookup cfg;
|
||||
size_t buflen = sizeof(kiss_fft_scalar)*nfft;
|
||||
|
||||
kiss_fft_scalar * in = (kiss_fft_scalar*)malloc(buflen);
|
||||
kiss_fft_scalar * out= (kiss_fft_scalar*)malloc(buflen);
|
||||
celt_word16 * window= (celt_word16*)malloc(sizeof(celt_word16)*nfft/2);
|
||||
int k;
|
||||
|
||||
clt_mdct_init(&cfg, nfft, 0);
|
||||
for (k=0;k<nfft;++k) {
|
||||
in[k] = (rand() % 32768) - 16384;
|
||||
}
|
||||
|
||||
for (k=0;k<nfft/2;++k) {
|
||||
window[k] = Q15ONE;
|
||||
}
|
||||
#ifdef DOUBLE_PRECISION
|
||||
for (k=0;k<nfft;++k) {
|
||||
in[k] *= 32768;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (isinverse)
|
||||
{
|
||||
for (k=0;k<nfft;++k) {
|
||||
in[k] /= nfft;
|
||||
}
|
||||
}
|
||||
|
||||
/*for (k=0;k<nfft;++k) printf("%d %d ", in[k].r, in[k].i);printf("\n");*/
|
||||
|
||||
if (isinverse)
|
||||
{
|
||||
for (k=0;k<nfft;++k)
|
||||
out[k] = 0;
|
||||
clt_mdct_backward(&cfg,in,out, window, nfft/2, 0);
|
||||
check_inv(in,out,nfft,isinverse);
|
||||
} else {
|
||||
clt_mdct_forward(&cfg,in,out,window, nfft/2, 0);
|
||||
check(in,out,nfft,isinverse);
|
||||
}
|
||||
/*for (k=0;k<nfft;++k) printf("%d %d ", out[k].r, out[k].i);printf("\n");*/
|
||||
|
||||
|
||||
free(in);
|
||||
free(out);
|
||||
clt_mdct_clear(&cfg);
|
||||
}
|
||||
|
||||
int main(int argc,char ** argv)
|
||||
{
|
||||
ALLOC_STACK;
|
||||
if (argc>1) {
|
||||
int k;
|
||||
for (k=1;k<argc;++k) {
|
||||
test1d(atoi(argv[k]),0);
|
||||
test1d(atoi(argv[k]),1);
|
||||
}
|
||||
}else{
|
||||
test1d(32,0);
|
||||
test1d(32,1);
|
||||
test1d(256,0);
|
||||
test1d(256,1);
|
||||
test1d(512,0);
|
||||
test1d(512,1);
|
||||
#ifndef RADIX_TWO_ONLY
|
||||
test1d(40,0);
|
||||
test1d(40,1);
|
||||
test1d(120,0);
|
||||
test1d(120,1);
|
||||
test1d(240,0);
|
||||
test1d(240,1);
|
||||
test1d(480,0);
|
||||
test1d(480,1);
|
||||
#endif
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "kiss_fftr.h"
|
||||
#include "_kiss_fft_guts.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define CELT_C
|
||||
#include "../libcelt/stack_alloc.h"
|
||||
#include "../libcelt/kiss_fft.c"
|
||||
#include "../libcelt/kiss_fftr.c"
|
||||
|
||||
#ifdef FIXED_DEBUG
|
||||
long long celt_mips=0;
|
||||
#endif
|
||||
int ret=0;
|
||||
|
||||
static
|
||||
kiss_fft_scalar rand_scalar(void)
|
||||
{
|
||||
return (rand()%32767)-16384;
|
||||
}
|
||||
|
||||
static
|
||||
double snr_compare( kiss_fft_cpx * vec1,kiss_fft_scalar * vec2, int n)
|
||||
{
|
||||
int k;
|
||||
double sigpow=1e-10, noisepow=1e-10, err,snr;
|
||||
|
||||
vec1[0].i = vec1[n].r;
|
||||
for (k=0;k<n;++k) {
|
||||
sigpow += (double)vec1[k].r * (double)vec1[k].r +
|
||||
(double)vec1[k].i * (double)vec1[k].i;
|
||||
err = (double)vec1[k].r - (double)vec2[2*k];
|
||||
/*printf ("%f %f\n", (double)vec1[k].r, (double)vec2[2*k]);*/
|
||||
noisepow += err * err;
|
||||
err = (double)vec1[k].i - (double)vec2[2*k+1];
|
||||
/*printf ("%f %f\n", (double)vec1[k].i, (double)vec2[2*k+1]);*/
|
||||
noisepow += err * err;
|
||||
|
||||
}
|
||||
snr = 10*log10( sigpow / noisepow );
|
||||
if (snr<60) {
|
||||
printf( "** poor snr: %f **\n", snr);
|
||||
ret = 1;
|
||||
}
|
||||
return snr;
|
||||
}
|
||||
|
||||
static
|
||||
double snr_compare_scal( kiss_fft_scalar * vec1,kiss_fft_scalar * vec2, int n)
|
||||
{
|
||||
int k;
|
||||
double sigpow=1e-10, noisepow=1e-10, err,snr;
|
||||
|
||||
for (k=0;k<n;++k) {
|
||||
sigpow += (double)vec1[k] * (double)vec1[k];
|
||||
err = (double)vec1[k] - (double)vec2[k];
|
||||
noisepow += err * err;
|
||||
}
|
||||
snr = 10*log10( sigpow / noisepow );
|
||||
if (snr<60) {
|
||||
printf( "\npoor snr: %f\n", snr);
|
||||
ret = 1;
|
||||
}
|
||||
return snr;
|
||||
}
|
||||
#ifdef RADIX_TWO_ONLY
|
||||
#define NFFT 1024
|
||||
#else
|
||||
#define NFFT 8*3*5
|
||||
#endif
|
||||
|
||||
#ifndef NUMFFTS
|
||||
#define NUMFFTS 10000
|
||||
#endif
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
kiss_fft_cpx cin[NFFT];
|
||||
kiss_fft_cpx cout[NFFT];
|
||||
kiss_fft_scalar fin[NFFT];
|
||||
kiss_fft_scalar sout[NFFT];
|
||||
kiss_fft_cfg kiss_fft_state;
|
||||
kiss_fftr_cfg kiss_fftr_state;
|
||||
|
||||
kiss_fft_scalar rin[NFFT+2];
|
||||
kiss_fft_scalar rout[NFFT+2];
|
||||
kiss_fft_scalar zero;
|
||||
ALLOC_STACK;
|
||||
memset(&zero,0,sizeof(zero) ); // ugly way of setting short,int,float,double, or __m128 to zero
|
||||
|
||||
for (i=0;i<NFFT;++i) {
|
||||
rin[i] = rand_scalar();
|
||||
#if defined(FIXED_POINT) && defined(DOUBLE_PRECISION)
|
||||
rin[i] *= 32768;
|
||||
#endif
|
||||
cin[i].r = rin[i];
|
||||
cin[i].i = zero;
|
||||
}
|
||||
|
||||
kiss_fft_state = kiss_fft_alloc(NFFT,0,0);
|
||||
kiss_fftr_state = kiss_fftr_alloc(NFFT,0,0);
|
||||
kiss_fft(kiss_fft_state,cin,cout);
|
||||
kiss_fftr(kiss_fftr_state,rin,sout);
|
||||
|
||||
printf( "nfft=%d, inverse=%d, snr=%g\n",
|
||||
NFFT,0, snr_compare(cout,sout,(NFFT/2)) );
|
||||
|
||||
memset(cin,0,sizeof(cin));
|
||||
cin[0].r = rand_scalar();
|
||||
cin[NFFT/2].r = rand_scalar();
|
||||
for (i=1;i< NFFT/2;++i) {
|
||||
//cin[i].r = (kiss_fft_scalar)(rand()-RAND_MAX/2);
|
||||
cin[i].r = rand_scalar();
|
||||
cin[i].i = rand_scalar();
|
||||
}
|
||||
|
||||
// conjugate symmetry of real signal
|
||||
for (i=1;i< NFFT/2;++i) {
|
||||
cin[NFFT-i].r = cin[i].r;
|
||||
cin[NFFT-i].i = - cin[i].i;
|
||||
}
|
||||
|
||||
|
||||
#ifdef FIXED_POINT
|
||||
#ifdef DOUBLE_PRECISION
|
||||
for (i=0;i< NFFT;++i) {
|
||||
cin[i].r *= 32768;
|
||||
cin[i].i *= 32768;
|
||||
}
|
||||
#endif
|
||||
for (i=0;i< NFFT;++i) {
|
||||
cin[i].r /= NFFT;
|
||||
cin[i].i /= NFFT;
|
||||
}
|
||||
#endif
|
||||
|
||||
fin[0] = cin[0].r;
|
||||
fin[1] = cin[NFFT/2].r;
|
||||
for (i=1;i< NFFT/2;++i)
|
||||
{
|
||||
fin[2*i] = cin[i].r;
|
||||
fin[2*i+1] = cin[i].i;
|
||||
}
|
||||
|
||||
kiss_ifft(kiss_fft_state,cin,cout);
|
||||
kiss_fftri(kiss_fftr_state,fin,rout);
|
||||
/*
|
||||
printf(" results from inverse kiss_fft : (%f,%f), (%f,%f), (%f,%f), (%f,%f), (%f,%f) ...\n "
|
||||
, (float)cout[0].r , (float)cout[0].i , (float)cout[1].r , (float)cout[1].i , (float)cout[2].r , (float)cout[2].i , (float)cout[3].r , (float)cout[3].i , (float)cout[4].r , (float)cout[4].i
|
||||
);
|
||||
|
||||
printf(" results from inverse kiss_fftr: %f,%f,%f,%f,%f ... \n"
|
||||
,(float)rout[0] ,(float)rout[1] ,(float)rout[2] ,(float)rout[3] ,(float)rout[4]);
|
||||
*/
|
||||
for (i=0;i<NFFT;++i) {
|
||||
sout[i] = cout[i].r;
|
||||
}
|
||||
|
||||
printf( "nfft=%d, inverse=%d, snr=%g\n",
|
||||
NFFT,1, snr_compare_scal(rout,sout,NFFT) );
|
||||
free(kiss_fft_state);
|
||||
free(kiss_fftr_state);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "celt_types.h"
|
||||
#include "bands.h"
|
||||
#include <math.h>
|
||||
#define MAX_SIZE 100
|
||||
|
||||
int ret=0;
|
||||
void test_rotation(int N, int K)
|
||||
{
|
||||
int i;
|
||||
double err = 0, ener = 0, snr, snr0;
|
||||
celt_word16 x0[MAX_SIZE];
|
||||
celt_word16 x1[MAX_SIZE];
|
||||
int nb_rotations = (N+4*K)/(8*K);
|
||||
for (i=0;i<N;i++)
|
||||
x1[i] = x0[i] = rand()%32767-16384;
|
||||
exp_rotation(x1, N, 1, 1, nb_rotations);
|
||||
for (i=0;i<N;i++)
|
||||
{
|
||||
err += (x0[i]-(double)x1[i])*(x0[i]-(double)x1[i]);
|
||||
ener += x0[i]*(double)x0[i];
|
||||
}
|
||||
snr0 = 20*log10(ener/err);
|
||||
err = ener = 0;
|
||||
exp_rotation(x1, N, -1, 1, nb_rotations);
|
||||
for (i=0;i<N;i++)
|
||||
{
|
||||
err += (x0[i]-(double)x1[i])*(x0[i]-(double)x1[i]);
|
||||
ener += x0[i]*(double)x0[i];
|
||||
}
|
||||
snr = 20*log10(ener/err);
|
||||
printf ("SNR for size %d (%d pulses) is %f (was %f without inverse)\n", N, K, snr, snr0);
|
||||
if (snr < 60 || snr0 > 20)
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_rotation(15, 3);
|
||||
test_rotation(23, 5);
|
||||
test_rotation(50, 3);
|
||||
test_rotation(80, 1);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,204 +0,0 @@
|
||||
/* (C) 2009 Gregory Maxwell
|
||||
|
||||
This test runs pink noise through the encoder and decoder many times
|
||||
while feeding the output back into the input. It checks that after
|
||||
a number of cycles the energy has not increased or decreased by too
|
||||
large an amount.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "celt.h"
|
||||
#include "arch.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
int async_tandem(int rate, int frame_size, int channels, int bitrate_min,
|
||||
int bitrate_max)
|
||||
{
|
||||
int error;
|
||||
unsigned char data[648];
|
||||
CELTMode *mode = NULL;
|
||||
CELTEncoder *enc;
|
||||
short carry[2];
|
||||
short pcm[960 * 2];
|
||||
CELTDecoder *dec;
|
||||
int bmin, bmax;
|
||||
float ms;
|
||||
int ret, i, j, bytes_per_frame;
|
||||
int increment = 1;
|
||||
|
||||
bmin = floor((bitrate_min / (rate / (float) frame_size)) / 8.0);
|
||||
bmax = ceil((bitrate_max / (rate / (float) frame_size)) / 8.0);
|
||||
if (bmin < 8)
|
||||
bmin = 8;
|
||||
if (bmax > 640)
|
||||
bmax = 640;
|
||||
if (bmin >= bmax)
|
||||
bmax = bmin + 8;
|
||||
|
||||
increment += (bmax - bmin) / 128;
|
||||
|
||||
printf ("Testing asynchronous tandeming (%dHz, %dch, %d samples, %d - %d bytes).\n",
|
||||
rate, channels, frame_size, bmin, bmax);
|
||||
|
||||
mode = celt_mode_create(rate, frame_size, &error);
|
||||
if (mode == NULL || error) {
|
||||
fprintf(stderr, "Error: failed to create a mode: %s\n", celt_strerror(error));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
dec = celt_decoder_create_custom(mode, channels, &error);
|
||||
if (error){
|
||||
fprintf(stderr, "Error: celt_decoder_create returned %s\n", celt_strerror(error));
|
||||
exit(1);
|
||||
}
|
||||
enc = celt_encoder_create_custom(mode, channels, &error);
|
||||
if (error){
|
||||
fprintf(stderr, "Error: celt_encoder_create returned %s\n", celt_strerror(error));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (j = 0; j < frame_size * channels; j++)
|
||||
pcm[j] = 0;
|
||||
|
||||
for (bytes_per_frame = bmin; bytes_per_frame <= bmax;
|
||||
bytes_per_frame += increment) {
|
||||
/*Prime the encoder and decoder */
|
||||
for (i = 0; i < (1024 + (frame_size >> 1)) / frame_size + 2; i++) {
|
||||
|
||||
for (j = 0; j < channels; j++)
|
||||
pcm[j] = pcm[frame_size * channels - (channels - j + 1)];
|
||||
for (j = channels; j < frame_size * channels - 1; j++)
|
||||
pcm[j] = ((rand() % 4096) - 2048) + .9 * pcm[j - channels];
|
||||
|
||||
ret = celt_encode(enc, pcm, frame_size, data, bytes_per_frame);
|
||||
if (ret != bytes_per_frame) {
|
||||
fprintf(stderr, "Error: celt_encode returned %s\n", celt_strerror(ret));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = celt_decode(dec, data, ret, pcm, frame_size);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Error: celt_decode returned %s\n", celt_strerror(ret));
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < channels; j++)
|
||||
pcm[j] = pcm[frame_size * channels - (channels - j)];
|
||||
for (j = channels; j < frame_size * channels - 1; j++)
|
||||
pcm[j] = ((rand() % 4096) - 2048) + .9 * pcm[j - channels];
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
for (j = 0; j < channels; j++)
|
||||
carry[j] = pcm[frame_size * channels - (channels - j)];
|
||||
memmove(pcm + channels, pcm, sizeof(short) * frame_size * channels);
|
||||
for (j = 0; j < channels; j++)
|
||||
pcm[j] = carry[j];
|
||||
|
||||
ret = celt_encode(enc, pcm, frame_size, data, bytes_per_frame);
|
||||
if (ret != bytes_per_frame) {
|
||||
fprintf(stderr, "Error: at %d bytes_per_frame celt_encode returned %s\n",
|
||||
bytes_per_frame, celt_strerror(ret));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = celt_decode(dec, data, ret, pcm, frame_size);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Error: at %d bytes_per_frame celt_decode returned %s\n",
|
||||
bytes_per_frame, celt_strerror(ret));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
ms = 0;
|
||||
for (j = 0; j < frame_size * channels; j++)
|
||||
ms += pcm[j] * pcm[j];
|
||||
ms = sqrt(ms / (frame_size * channels));
|
||||
if (ms > 7000 || ms < 1000) {
|
||||
fprintf(stderr, "Error: Signal out of expected range. %d %d %d %d %f\n",
|
||||
rate, channels, frame_size, bytes_per_frame, ms);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
celt_encoder_destroy(enc);
|
||||
celt_decoder_destroy(dec);
|
||||
celt_mode_destroy(mode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifdef CUSTOM_MODES
|
||||
int sizes[8]={960,512,480,256,240,128,120,64};
|
||||
#else
|
||||
int sizes[4]={960,480,240,120};
|
||||
#endif
|
||||
unsigned int seed;
|
||||
int ch, n;
|
||||
|
||||
if (argc > 2) {
|
||||
fprintf(stderr, "Usage: %s [<seed>]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
seed = atoi(argv[1]);
|
||||
else
|
||||
seed = (time(NULL) ^ ((getpid() % 65536) << 16));
|
||||
|
||||
srand(seed);
|
||||
printf("CELT codec tests. Random seed: %u (%.4X)\n", seed, rand() % 65536);
|
||||
|
||||
#ifdef CUSTOM_MODES
|
||||
for (n = 0; n < 8; n++) {
|
||||
for (ch = 1; ch <= 2; ch++) {
|
||||
async_tandem(48000, sizes[n], ch, 12000 * ch, 128000 * ch);
|
||||
async_tandem(44100, sizes[n], ch, 12000 * ch, 128000 * ch);
|
||||
if(n>0)async_tandem(32000, sizes[n], ch, 12000 * ch, 128000 * ch);
|
||||
if(n>2)async_tandem(16000, sizes[n], ch, 12000 * ch, 64000 * ch);
|
||||
}
|
||||
}
|
||||
#else
|
||||
for (n = 0; n < 4; n++) {
|
||||
for (ch = 1; ch <= 2; ch++) {
|
||||
async_tandem(48000, sizes[n], ch, 12000 * ch, 128000 * ch);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "celt_types.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
celt_int16 i = 1;
|
||||
i <<= 14;
|
||||
if (i>>14 != 1)
|
||||
{
|
||||
fprintf(stderr, "celt_int16 isn't 16 bits\n");
|
||||
return 1;
|
||||
}
|
||||
if (sizeof(celt_int16)*2 != sizeof(celt_int32))
|
||||
{
|
||||
fprintf(stderr, "16*2 != 32\n");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user