comparison vorbis_enc.c @ 3858:70b4bc721531 libavcodec

Original Commit: r58 | ods15 | 2006-09-24 17:35:28 +0300 (Sun, 24 Sep 2006) | 2 lines add ability to use codebook dimentions in residue
author ods15
date Mon, 02 Oct 2006 06:07:42 +0000
parents 2d1d529a90d4
children 0d0bd4b2baef
comparison
equal deleted inserted replaced
3857:2d1d529a90d4 3858:70b4bc721531
665 venc->have_saved = 0; 665 venc->have_saved = 0;
666 } 666 }
667 return 1; 667 return 1;
668 } 668 }
669 669
670 static float put_vector(codebook_t * book, PutBitContext * pb, float num) { 670 static float * put_vector(codebook_t * book, PutBitContext * pb, float * num) {
671 int i; 671 int i;
672 int entry = -1; 672 int entry = -1;
673 float distance = 0; 673 float distance = 0;
674 assert(book->dimentions); 674 assert(book->dimentions);
675 assert(book->ndimentions == 1);
676 for (i = 0; i < book->nentries; i++) { 675 for (i = 0; i < book->nentries; i++) {
677 float d = (book->dimentions[i] - num)*(book->dimentions[i] - num); 676 float d = 0.;
677 int j;
678 for (j = 0; j < book->ndimentions; j++) {
679 float a = (book->dimentions[i * book->ndimentions + j] - num[j]);
680 d += a*a;
681 }
678 if (entry == -1 || distance > d) { 682 if (entry == -1 || distance > d) {
679 entry = i; 683 entry = i;
680 distance = d; 684 distance = d;
681 } 685 }
682 } 686 }
683 put_bits(pb, book->entries[entry].len, book->entries[entry].codeword); 687 put_bits(pb, book->entries[entry].len, book->entries[entry].codeword);
684 return book->dimentions[entry]; 688 return &book->dimentions[entry * book->ndimentions];
685 } 689 }
686 690
687 static void residue_encode(venc_context_t * venc, residue_t * rc, PutBitContext * pb, float * coeffs, int samples, int channels) { 691 static void residue_encode(venc_context_t * venc, residue_t * rc, PutBitContext * pb, float * coeffs, int samples, int channels) {
688 int pass, i, j, p, k; 692 int pass, i, j, p, k;
689 int psize = rc->partition_size; 693 int psize = rc->partition_size;
709 codebook_t * book = &venc->codebooks[nbook]; 713 codebook_t * book = &venc->codebooks[nbook];
710 float * buf = coeffs + samples*j + rc->begin + p*psize; 714 float * buf = coeffs + samples*j + rc->begin + p*psize;
711 if (nbook == -1) continue; 715 if (nbook == -1) continue;
712 716
713 assert(rc->type == 0); 717 assert(rc->type == 0);
714 assert(book->ndimentions == 1); 718 assert(!(psize % book->ndimentions));
715 719
716 for (k = 0; k < psize; k++) { 720 for (k = 0; k < psize; k += book->ndimentions) {
717 buf[k] -= put_vector(book, pb, buf[k]); 721 float * a = put_vector(book, pb, &buf[k]);
722 int l;
723 for (l = 0; l < book->ndimentions; l++) buf[k + l] -= a[l];
718 } 724 }
719 } 725 }
720 } 726 }
721 } 727 }
722 } 728 }