#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <ogg/ogg.h>
#include "os.h"
#include "misc.h"
#include "vorbis/codec.h"
#include "codebook.h"
#include "scales.h"
int ov_ilog(ogg_uint32_t v){ … }
#define VQ_FEXP …
#define VQ_FMAN …
#define VQ_FEXP_BIAS …
long _float32_pack(float val){ … }
float _float32_unpack(long val){ … }
ogg_uint32_t *_make_words(char *l,long n,long sparsecount){ … }
long _book_maptype1_quantvals(const static_codebook *b){ … }
float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){ … }
void vorbis_staticbook_destroy(static_codebook *b){ … }
void vorbis_book_clear(codebook *b){ … }
int vorbis_book_init_encode(codebook *c,const static_codebook *s){ … }
static ogg_uint32_t bitreverse(ogg_uint32_t x){ … }
static int sort32a(const void *a,const void *b){ … }
int vorbis_book_init_decode(codebook *c,const static_codebook *s){ … }
long vorbis_book_codeword(codebook *book,int entry){ … }
long vorbis_book_codelen(codebook *book,int entry){ … }
#ifdef _V_SELFTEST
#include <stdio.h>
static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
static long partial_quantlist1[]={0,7,2};
static_codebook test1={
4,16,
NULL,
0,
0,0,0,0,
NULL,
0
};
static float *test1_result=NULL;
static_codebook test2={
4,3,
NULL,
2,
-533200896,1611661312,4,0,
full_quantlist1,
0
};
static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
static_codebook test3={
4,3,
NULL,
2,
-533200896,1611661312,4,1,
full_quantlist1,
0
};
static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
static_codebook test4={
3,27,
NULL,
1,
-533200896,1611661312,4,0,
partial_quantlist1,
0
};
static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
-3, 4,-3, 4, 4,-3, -1, 4,-3,
-3,-1,-3, 4,-1,-3, -1,-1,-3,
-3,-3, 4, 4,-3, 4, -1,-3, 4,
-3, 4, 4, 4, 4, 4, -1, 4, 4,
-3,-1, 4, 4,-1, 4, -1,-1, 4,
-3,-3,-1, 4,-3,-1, -1,-3,-1,
-3, 4,-1, 4, 4,-1, -1, 4,-1,
-3,-1,-1, 4,-1,-1, -1,-1,-1};
static_codebook test5={
3,27,
NULL,
1,
-533200896,1611661312,4,1,
partial_quantlist1,
0
};
static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
-3, 1,-2, 4, 8, 5, -1, 3, 0,
-3,-4,-7, 4, 3, 0, -1,-2,-5,
-3,-6,-2, 4, 1, 5, -1,-4, 0,
-3, 1, 5, 4, 8,12, -1, 3, 7,
-3,-4, 0, 4, 3, 7, -1,-2, 2,
-3,-6,-7, 4, 1, 0, -1,-4,-5,
-3, 1, 0, 4, 8, 7, -1, 3, 2,
-3,-4,-5, 4, 3, 2, -1,-2,-3};
void run_test(static_codebook *b,float *comp){
float *out=_book_unquantize(b,b->entries,NULL);
int i;
if(comp){
if(!out){
fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
exit(1);
}
for(i=0;i<b->entries*b->dim;i++)
if(fabs(out[i]-comp[i])>.0001){
fprintf(stderr,"disagreement in unquantized and reference data:\n"
"position %d, %g != %g\n",i,out[i],comp[i]);
exit(1);
}
}else{
if(out){
fprintf(stderr,"_book_unquantize returned a value array: \n"
" correct result should have been NULL\n");
exit(1);
}
}
free(out);
}
int main(){
fprintf(stderr,"Dequant test 1... ");
run_test(&test1,test1_result);
fprintf(stderr,"OK\nDequant test 2... ");
run_test(&test2,test2_result);
fprintf(stderr,"OK\nDequant test 3... ");
run_test(&test3,test3_result);
fprintf(stderr,"OK\nDequant test 4... ");
run_test(&test4,test4_result);
fprintf(stderr,"OK\nDequant test 5... ");
run_test(&test5,test5_result);
fprintf(stderr,"OK\n\n");
return(0);
}
#endif