26 #include "../ogg/ogg.h"
27 #include "../vorbis/codec.h"
56 long *training_data[8][64];
57 float training_max[8][64];
58 float training_min[8][64];
68 memset(info,0,
sizeof(*info));
82 for(j=0;j<look->
parts;j++){
85 if(look->training_data[k][j]){
91 sprintf(buffer,
"res_part%d_pass%d.vqd",j,k);
94 for(l=0;l<statebook->
entries;l++)
95 fprintf(of,
"%d:%ld\n",l,look->training_data[k][j][l]);
107 fprintf(stderr,
"min/max residue: %g::%g\n",look->tmin,look->tmax);
138 for(j=0;j<look->
parts;j++)
145 memset(look,0,
sizeof(*look));
150 static int ilog(
unsigned int v){
159 static int icount(
unsigned int v){
216 acc+=icount(cascade);
249 for(j=0;j<look->
parts;j++){
252 if(stages>maxstage)maxstage=stages;
254 for(k=0;k<stages;k++)
259 sizeof(***look->training_data));
281 static int train_seq=0;
282 look->train_seq=train_seq++;
289 static int local_book_besterror(
codebook *book,
float *
a){
290 int dim=book->
dim,
i,k,o;
295 for(k=0,o=dim;k<dim;++k){
299 if(val<tt->quantthresh[
i]){
300 if(val<tt->quantthresh[i-1]){
308 if(val<tt->quantthresh[i])
break;
326 float val=(e[
j]-a[
j]);
329 if(best==-1 ||
this<bestf){
354 int entry=local_book_besterror(book,vec+i*dim);
375 int samples_per_partition=info->
grouping;
379 int partvals=n/samples_per_partition;
381 float scale=100./samples_per_partition;
389 memset(partword[i],0,n/samples_per_partition*
sizeof(*partword[i]));
392 for(i=0;i<partvals;i++){
397 for(k=0;k<samples_per_partition;k++){
398 if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
399 ent+=fabs(rint(in[j][offset+k]));
403 for(k=0;k<possible_partitions-1;k++)
404 if(max<=info->classmetric1[k] &&
405 (info->
classmetric2[k]<0 || (
int)ent<info->classmetric2[k]))
418 sprintf(buffer,
"resaux_%d.vqd",look->train_seq);
419 of=fopen(buffer,
"a");
420 for(j=0;j<partvals;j++)
421 fprintf(of,
"%ld, ",partword[i][j]);
442 int samples_per_partition=info->
grouping;
446 int partvals=n/samples_per_partition;
455 memset(partword[0],0,n*ch/samples_per_partition*
sizeof(*partword[0]));
457 for(i=0,l=info->
begin/ch;i<partvals;i++){
460 for(j=0;j<samples_per_partition;j+=ch){
461 if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
463 if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
467 for(j=0;j<possible_partitions-1;j++)
468 if(magmax<=info->classmetric1[j] &&
469 angmax<=info->classmetric2[j])
477 sprintf(buffer,
"resaux_%d.vqd",look->train_seq);
478 of=fopen(buffer,
"a");
479 for(i=0;i<partvals;i++)
480 fprintf(of,
"%ld, ",partword[0][i]);
502 int samples_per_partition=info->
grouping;
507 int partvals=n/samples_per_partition;
514 if(in[i][j]>look->tmax)look->tmax=in[
i][
j];
515 if(in[i][j]<look->tmin)look->tmin=in[
i][
j];
519 memset(resbits,0,
sizeof(resbits));
520 memset(resvals,0,
sizeof(resvals));
527 for(s=0;s<look->
stages;s++){
529 for(i=0;i<partvals;){
534 long val=partword[
j][
i];
535 for(k=1;k<partitions_per_word;k++){
536 val*=possible_partitions;
538 val+=partword[
j][i+k];
542 if(val<look->phrasebook->entries)
553 for(k=0;k<partitions_per_word && i<partvals;k++,i++){
554 long offset=i*samples_per_partition+info->
begin;
557 if(s==0)resvals[partword[
j][
i]]+=samples_per_partition;
562 long *accumulator=
NULL;
565 accumulator=look->training_data[
s][partword[
j][
i]];
569 for(l=0;l<samples_per_partition;l++){
570 if(samples[l]<look->training_min[s][partword[j][i]])
571 look->training_min[
s][partword[
j][
i]]=samples[
l];
572 if(samples[l]>look->training_max[s][partword[j][i]])
573 look->training_max[
s][partword[
j][
i]]=samples[
l];
578 ret=encode(&vb->
opb,in[j]+offset,samples_per_partition,
579 statebook,accumulator);
582 resbits[partword[
j][
i]]+=ret;
608 long (*decodepart)(
codebook *,
float *,
616 int samples_per_partition=info->
grouping;
620 int partvals=n/samples_per_partition;
621 int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
622 int ***partword=alloca(ch*
sizeof(*partword));
627 for(s=0;s<look->
stages;s++){
631 for(i=0,l=0;i<partvals;l++){
636 if(temp==-1)
goto eopbreak;
638 if(partword[j][l]==
NULL)
goto errout;
643 for(k=0;k<partitions_per_word && i<partvals;k++,i++)
645 long offset=info->
begin+i*samples_per_partition;
649 if(decodepart(stagebook,in[j]+offset,&vb->
opb,
650 samples_per_partition)==-1)
goto eopbreak;
666 float **in,
int *nonzero,
int ch){
674 return(_01class(vb,vl,in,used));
680 float **in,
float **out,
int *nonzero,
int ch,
692 int ret=_01forward(vb,vl,in,used,partword,
693 _interleaved_encodepart);
699 out[i][j]-=in[used][j];
711 float **in,
int *nonzero,
int ch){
723 float **in,
float **out,
int *nonzero,
int ch,
735 int ret=_01forward(vb,vl,in,used,partword,_encodepart);
741 out[i][j]-=in[used][j];
752 float **in,
int *nonzero,
int ch){
758 return(_01class(vb,vl,in,used));
764 float **in,
int *nonzero,
int ch){
776 float **in,
int *nonzero,
int ch){
779 if(nonzero[i])used++;
781 return(_2class(vb,vl,in,ch));
790 float **in,
float **out,
int *nonzero,
int ch,
800 if(nonzero[i])used++;
801 for(j=0,k=i;j<
n;j++,k+=ch)
806 int ret=_01forward(vb,vl,&work,1,partword,_encodepart);
812 for(j=0,k=i;j<
n;j++,k+=ch)
813 sofar[j]+=pcm[j]-work[k];
825 float **in,
int *nonzero,
int ch){
831 int samples_per_partition=info->
grouping;
835 int partvals=n/samples_per_partition;
836 int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
839 for(i=0;i<ch;i++)
if(nonzero[i])
break;
842 for(s=0;s<look->
stages;s++){
843 for(i=0,l=0;i<partvals;l++){
848 if(temp==-1)
goto eopbreak;
850 if(partword[l]==
NULL)
goto errout;
854 for(k=0;k<partitions_per_word && i<partvals;k++,i++)
860 i*samples_per_partition+info->
begin,ch,
861 &vb->
opb,samples_per_partition)==-1)
vorbis_func_residue residue2_exportbundle
vorbis_func_residue residue1_exportbundle
long vorbis_book_decodevs_add(codebook *book, float *a, oggpack_buffer *b, int n)
const static_codebook * c
int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b)
GLenum GLenum GLenum GLenum GLenum scale
int res2_inverse(vorbis_block *vb, vorbis_look_residue *vl, float **in, int *nonzero, int ch)
int res0_inverse(vorbis_block *vb, vorbis_look_residue *vl, float **in, int *nonzero, int ch)
void oggpack_write(oggpack_buffer *b, unsigned long value, int bits)
long ** res1_class(vorbis_block *vb, vorbis_look_residue *vl, float **in, int *nonzero, int ch)
void res0_pack(vorbis_info_residue *vr, oggpack_buffer *opb)
long vorbis_book_decode(codebook *book, oggpack_buffer *b)
void res0_free_look(vorbis_look_residue *i)
long vorbis_book_decodev_add(codebook *book, float *a, oggpack_buffer *b, int n)
int res1_inverse(vorbis_block *vb, vorbis_look_residue *vl, float **in, int *nonzero, int ch)
int res1_forward(vorbis_block *vb, vorbis_look_residue *vl, float **in, float **out, int *nonzero, int ch, long **partword)
GLubyte GLubyte GLubyte a
int res2_forward(vorbis_block *vb, vorbis_look_residue *vl, float **in, float **out, int *nonzero, int ch, long **partword)
long ** res2_class(vorbis_block *vb, vorbis_look_residue *vl, float **in, int *nonzero, int ch)
vorbis_look_residue * res0_look(vorbis_dsp_state *vd, vorbis_info_residue *vr)
vorbis_info_residue0 * info
vorbis_func_residue residue0_exportbundle
vorbis_info_residue * res0_unpack(vorbis_info *vi, oggpack_buffer *opb)
struct encode_aux_threshmatch * thresh_tree
void res0_free_info(vorbis_info_residue *i)
long vorbis_book_decodevv_add(codebook *book, float **a, long offset, int ch, oggpack_buffer *b, int n)
long oggpack_read(oggpack_buffer *b, int bits)
int sprintf(idStr &string, const char *fmt,...)
void * _vorbis_block_alloc(vorbis_block *vb, long bytes)