-#ifdef _V_SELFTEST
-
-/* Simple enough; pack a few candidate codebooks, unpack them. Code a
- number of vectors through (keeping track of the quantized values),
- and decode using the unpacked book. quantized version of in should
- exactly equal out */
-
-#include <stdio.h>
-
-#include "vorbis/book/lsp20_0.vqh"
-#include "vorbis/book/res0a_13.vqh"
-#define TESTSIZE 40
-
-double test1[TESTSIZE]={
- 0.105939,
- 0.215373,
- 0.429117,
- 0.587974,
-
- 0.181173,
- 0.296583,
- 0.515707,
- 0.715261,
-
- 0.162327,
- 0.263834,
- 0.342876,
- 0.406025,
-
- 0.103571,
- 0.223561,
- 0.368513,
- 0.540313,
-
- 0.136672,
- 0.395882,
- 0.587183,
- 0.652476,
-
- 0.114338,
- 0.417300,
- 0.525486,
- 0.698679,
-
- 0.147492,
- 0.324481,
- 0.643089,
- 0.757582,
-
- 0.139556,
- 0.215795,
- 0.324559,
- 0.399387,
-
- 0.120236,
- 0.267420,
- 0.446940,
- 0.608760,
-
- 0.115587,
- 0.287234,
- 0.571081,
- 0.708603,
-};
-
-double test3[TESTSIZE]={
- 0,1,-2,3,4,-5,6,7,8,9,
- 8,-2,7,-1,4,6,8,3,1,-9,
- 10,11,12,13,14,15,26,17,18,19,
- 30,-25,-30,-1,-5,-32,4,3,-2,0};
-
-static_codebook *testlist[]={&_vq_book_lsp20_0,
- &_vq_book_res0a_13,NULL};
-double *testvec[]={test1,test3};
-
-int main(){
- oggpack_buffer write;
- oggpack_buffer read;
- long ptr=0,i;
- _oggpack_writeinit(&write);
-
- fprintf(stderr,"Testing codebook abstraction...:\n");
-
- while(testlist[ptr]){
- codebook c;
- static_codebook s;
- double *qv=alloca(sizeof(double)*TESTSIZE);
- double *iv=alloca(sizeof(double)*TESTSIZE);
- memcpy(qv,testvec[ptr],sizeof(double)*TESTSIZE);
- memset(iv,0,sizeof(double)*TESTSIZE);
-
- fprintf(stderr,"\tpacking/coding %ld... ",ptr);
-
- /* pack the codebook, write the testvector */
- _oggpack_reset(&write);
- vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
- we can write */
- vorbis_staticbook_pack(testlist[ptr],&write);
- fprintf(stderr,"Codebook size %ld bytes... ",_oggpack_bytes(&write));
- for(i=0;i<TESTSIZE;i+=c.dim){
- int best=_best(&c,qv+i,1);
- vorbis_book_encodev(&c,best,qv+i,&write);
- }
- vorbis_book_clear(&c);
-
- fprintf(stderr,"OK.\n");
- fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
-
- /* transfer the write data to a read buffer and unpack/read */
- _oggpack_readinit(&read,_oggpack_buffer(&write),_oggpack_bytes(&write));
- if(vorbis_staticbook_unpack(&read,&s)){
- fprintf(stderr,"Error unpacking codebook.\n");
- exit(1);
- }
- if(vorbis_book_init_decode(&c,&s)){
- fprintf(stderr,"Error initializing codebook.\n");
- exit(1);
- }
-
- for(i=0;i<TESTSIZE;i+=c.dim)
- if(vorbis_book_decodevs(&c,iv+i,&read,1,-1)==-1){
- fprintf(stderr,"Error reading codebook test data (EOP).\n");
- exit(1);