From 840d157323a5b82646c88d31700558a3f9189461 Mon Sep 17 00:00:00 2001 From: Oded Shimon Date: Mon, 2 Oct 2006 06:08:33 +0000 Subject: [PATCH] Original Commit: r80 | ods15 | 2006-09-29 15:44:22 +0300 (Fri, 29 Sep 2006) | 2 lines import libvorbis codebooks for residue Originally committed as revision 6485 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/vorbis_enc.c | 131 +++++++++++++++++++++++++--------------- 1 file changed, 83 insertions(+), 48 deletions(-) diff --git a/libavcodec/vorbis_enc.c b/libavcodec/vorbis_enc.c index 3bc93a644d..b1408a81d2 100644 --- a/libavcodec/vorbis_enc.c +++ b/libavcodec/vorbis_enc.c @@ -198,6 +198,7 @@ static void ready_codebook(codebook_t * cb) { for (i = 0; i < cb->nentries; i++) { cb_entry_t * e = &cb->entries[i]; int j = 0; + if (!e->len) continue; if (h[0]) h[0] = 0; else { for (j = e->len; j; j--) @@ -273,7 +274,7 @@ static void create_vorbis_context(venc_context_t * venc, AVCodecContext * avccon venc->sample_rate = avccontext->sample_rate; venc->blocksize[0] = venc->blocksize[1] = 11; - venc->ncodebooks = 15 + 1 + 8; + venc->ncodebooks = 29; venc->codebooks = av_malloc(sizeof(codebook_t) * venc->ncodebooks); int codebook0[] = { 2, 10, 8, 14, 7, 12, 11, 14, 1, 5, 3, 7, 4, 9, 7, 13, }; @@ -291,52 +292,75 @@ static void create_vorbis_context(venc_context_t * venc, AVCodecContext * avccon int codebook12[] = { 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 5, 4, }; int codebook13[] = { 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8, 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8, 10, 8, 11, 9, 12, 9, 12, }; int codebook14[] = { 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5, 11, 6, 11, 6, 11, 7, 11, 6, 11, 6, 11, 9, 11, 8, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, }; - - int codebook_sizes[] = { 16, 8, 256, 64, 128, 32, 96, 32, 96, 17, 32, 78, 17, 32, 78 }; - int * codebook_lens[] = { codebook0, codebook1, codebook2, codebook3, codebook4, codebook5, codebook6, codebook7, - codebook8, codebook9, codebook10, codebook11, codebook12, codebook13, codebook14 }; + int codebook15[] = { 5, 6, 11, 11, 11, 11, 10, 10, 12, 11, 5, 2, 11, 5, 6, 6, 7, 9, 11, 13, 13, 10, 7, 11, 6, 7, 8, 9, 10, 12, 11, 5, 11, 6, 8, 7, 9, 11, 14, 15, 11, 6, 6, 8, 4, 5, 7, 8, 10, 13, 10, 5, 7, 7, 5, 5, 6, 8, 10, 11, 10, 7, 7, 8, 6, 5, 5, 7, 9, 9, 11, 8, 8, 11, 8, 7, 6, 6, 7, 9, 12, 11, 10, 13, 9, 9, 7, 7, 7, 9, 11, 13, 12, 15, 12, 11, 9, 8, 8, 8, }; + int codebook16[] = { 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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0, 0, 0, 0, 0, 0, 0, 6, 6, 7, 9, 9, }; + int codebook19[] = { 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0, 9, 9, }; + int codebook20[] = { 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8, 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8, 8, 8, 10, 10, 0, 0, 0, 8, 8, 8, 8, 10, 10, 0, 0, 0, 9, 9, 9, 9, 10, 10, 0, 0, 0, 9, 9, 9, 9, 10, 10, 0, 0, 0, 10, 10, 10, 10, 11, 11, 0, 0, 0, 0, 0, 10, 10, 11, 11, }; + int codebook21[] = { 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 10, 10, 11, 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 11, 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 11, 12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 12, 12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 12, 12, 0, 0, 0, 9, 9, 9, 9, 10, 10, 10, 10, 11, 10, 11, 11, 12, 12, 0, 0, 0, 0, 0, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 0, 0, 0, 0, 0, 9, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 0, 0, 0, 0, 0, 8, 8, 9, 9, 10, 10, 11, 11, 12, 11, 12, 12, 0, 0, 0, 0, 0, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 13, 13, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 0, 0, 0, 0, 0, 0, 0, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12, 12, 13, 13, 13, 13, }; + int codebook22[] = { 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7, 10, 9, 9, 11, 9, 9, 4, 7, 7, 10, 9, 9, 11, 9, 9, 7, 10, 10, 11, 11, 10, 12, 11, 11, 6, 9, 9, 11, 10, 10, 11, 10, 10, 6, 9, 9, 11, 10, 10, 11, 10, 10, 7, 11, 11, 11, 11, 11, 12, 11, 11, 6, 9, 9, 11, 10, 10, 11, 10, 10, 6, 9, 9, 11, 10, 10, 11, 10, 10, }; + int codebook23[] = { 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 10, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 10, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 10, 10, 10, 7, 7, 8, 7, 8, 8, 8, 8, 10, 10, 10, 8, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 7, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 8, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10, 9, 9, 8, 8, 9, 8, 10, 10, 10, 10, 10, 8, 8, 8, 8, 8, 8, }; + int codebook24[] = { 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 6, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9, 10, 10, 7, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9, 11, 10, 0, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 0, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 0, 12, 12, 9, 9, 10, 10, 10, 10, 11, 11, 11, 12, 0, 13, 13, 9, 9, 10, 10, 10, 10, 11, 11, 12, 12, 0, 0, 0, 10, 10, 10, 10, 11, 11, 12, 12, 12, 12, 0, 0, 0, 10, 10, 10, 10, 11, 11, 12, 12, 12, 12, 0, 0, 0, 14, 14, 11, 11, 11, 11, 12, 12, 13, 13, 0, 0, 0, 14, 14, 11, 11, 11, 11, 12, 12, 13, 13, 0, 0, 0, 0, 0, 12, 12, 12, 12, 13, 13, 14, 13, 0, 0, 0, 0, 0, 13, 13, 12, 12, 13, 12, 14, 13, }; + int codebook25[] = { 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6, 5, 5, 5, 5, 6, 6, 6, 5, 5, }; + int codebook26[] = { 1, 4, 4, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 4, 9, 8, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 2, 9, 7, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, }; + int codebook27[] = { 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9, 10, 10, 10, 10, 6, 5, 5, 7, 7, 8, 8, 10, 8, 11, 10, 12, 12, 13, 13, 6, 5, 5, 7, 7, 8, 8, 10, 9, 11, 11, 12, 12, 13, 12, 18, 8, 8, 8, 8, 9, 9, 10, 9, 11, 10, 12, 12, 13, 13, 18, 8, 8, 8, 8, 9, 9, 10, 10, 11, 11, 13, 12, 14, 13, 18, 11, 11, 9, 9, 10, 10, 11, 11, 11, 12, 13, 12, 13, 14, 18, 11, 11, 9, 8, 11, 10, 11, 11, 11, 11, 12, 12, 14, 13, 18, 18, 18, 10, 11, 10, 11, 12, 12, 12, 12, 13, 12, 14, 13, 18, 18, 18, 10, 11, 11, 9, 12, 11, 12, 12, 12, 13, 13, 13, 18, 18, 17, 14, 14, 11, 11, 12, 12, 13, 12, 14, 12, 14, 13, 18, 18, 18, 14, 14, 11, 10, 12, 9, 12, 13, 13, 13, 13, 13, 18, 18, 17, 16, 18, 13, 13, 12, 12, 13, 11, 14, 12, 14, 14, 17, 18, 18, 17, 18, 13, 12, 13, 10, 12, 11, 14, 14, 14, 14, 17, 18, 18, 18, 18, 15, 16, 12, 12, 13, 10, 14, 12, 14, 15, 18, 18, 18, 16, 17, 16, 14, 12, 11, 13, 10, 13, 13, 14, 15, }; + int codebook28[] = { 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 9, 10, 10, 10, 11, 11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11, 10, 11, 11, 11, 9, 9, 9, 9, 9, 9, 10, 10, 9, 9, 10, 9, 11, 10, 11, 11, 11, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 9, 11, 11, 11, 11, 11, 9, 9, 9, 9, 10, 10, 9, 9, 9, 9, 10, 9, 11, 11, 11, 11, 11, 11, 11, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 10, 9, 10, 10, 9, 10, 9, 9, 10, 9, 11, 10, 10, 11, 11, 11, 11, 9, 10, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 10, 10, 10, 9, 9, 10, 9, 10, 9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 9, 9, 9, 9, 9, 10, 10, 10, }; + + int codebook_sizes[] = { 16, 8, 256, 64, 128, 32, 96, 32, 96, 17, 32, 78, 17, 32, 78, 100, 1641, 443, 105, 68, 81, 289, 81, 121, 169, 25, 169, 225, 289, }; + int * codebook_lens[] = { codebook0, codebook1, codebook2, codebook3, codebook4, codebook5, codebook6, codebook7, + codebook8, codebook9, codebook10, codebook11, codebook12, codebook13, codebook14, codebook15, + codebook16, codebook17, codebook18, codebook19, codebook20, codebook21, codebook22, codebook23, + codebook24, codebook25, codebook26, codebook27, codebook28, }; + + struct { + int lookup; + int dim; + float min; + float delta; + int * quant; + } cvectors[] = { + { 1, 8, -1.0, 1.0, (int[]){ 1, 0, 2, } }, + { 1, 4, -2.0, 1.0, (int[]){ 2, 1, 3, 0, 4, } }, + { 1, 4, -2.0, 1.0, (int[]){ 2, 1, 3, 0, 4, } }, + { 1, 2, -4.0, 1.0, (int[]){ 4, 3, 5, 2, 6, 1, 7, 0, 8, } }, + { 1, 2, -4.0, 1.0, (int[]){ 4, 3, 5, 2, 6, 1, 7, 0, 8, } }, + { 1, 2, -8.0, 1.0, (int[]){ 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15, 0, 16, } }, + { 1, 4, -11.0, 11.0, (int[]){ 1, 0, 2, } }, + { 1, 2, -5.0, 1.0, (int[]){ 5, 4, 6, 3, 7, 2, 8, 1, 9, 0, 10, } }, + { 1, 2, -30.0, 5.0, (int[]){ 6, 5, 7, 4, 8, 3, 9, 2, 10, 1, 11, 0, 12, } }, + { 1, 2, -2.0, 1.0, (int[]){ 2, 1, 3, 0, 4, } }, + { 1, 2, -1530.0, 255.0, (int[]){ 6, 5, 7, 4, 8, 3, 9, 2, 10, 1, 11, 0, 12, } }, + { 1, 2, -119.0, 17.0, (int[]){ 7, 6, 8, 5, 9, 4, 10, 3, 11, 2, 12, 1, 13, 0, 14, } }, + { 1, 2, -8.0, 1.0, (int[]){ 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15, 0, 16, } }, + }; // codebook 0..14 - floor1 book, values 0..255 - for (book = 0; book < 15; book++) { + // codebook 15 residue masterbook + // codebook 16..29 residue + for (book = 0; book < venc->ncodebooks; book++) { cb = &venc->codebooks[book]; cb->nentries = codebook_sizes[book]; cb->entries = av_malloc(sizeof(cb_entry_t) * cb->nentries); for (i = 0; i < cb->nentries; i++) cb->entries[i].len = codebook_lens[book][i]; - cb->ndimentions = 0; - cb->min = 0.; - cb->delta = 0.; - cb->seq_p = 0; - cb->lookup = 0; - cb->quantlist = NULL; - ready_codebook(cb); - } - - // codebook 15 - residue classbook, values 0..1, dimentions 4 - cb = &venc->codebooks[15]; - cb->nentries = 2; - cb->entries = av_malloc(sizeof(cb_entry_t) * cb->nentries); - for (i = 0; i < cb->nentries; i++) cb->entries[i].len = 1; - cb->ndimentions = 4; - cb->min = 0.; - cb->delta = 0.; - cb->seq_p = 0; - cb->lookup = 0; - cb->quantlist = NULL; - ready_codebook(cb); - - // codebook 16..23 - vector, for the residue, values -32767..32767, dimentions 1 - for (book = 0; book < 8; book++) { - cb = &venc->codebooks[16 + book]; - cb->nentries = 5; - cb->entries = av_malloc(sizeof(cb_entry_t) * cb->nentries); - for (i = 0; i < cb->nentries; i++) cb->entries[i].len = i == 2 ? 1 : 3; - cb->ndimentions = 1; - cb->delta = 1 << ((7 - book) * 2); - cb->min = -cb->delta*2; - cb->seq_p = 0; - cb->lookup = 1; - cb->quantlist = av_malloc(sizeof(int) * cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries)); - for (i = 0; i < cb->nentries; i++) cb->quantlist[i] = i; + if (book < 16) { + cb->ndimentions = 2; + cb->min = 0.; + cb->delta = 0.; + cb->seq_p = 0; + cb->lookup = 0; + cb->quantlist = NULL; + } else { + int vals; + cb->seq_p = 0; + cb->ndimentions = cvectors[book - 16].dim; + cb->min = cvectors[book - 16].min; + cb->delta = cvectors[book - 16].delta; + cb->lookup = cvectors[book - 16].lookup; + vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); + cb->quantlist = av_malloc(sizeof(int) * vals); + for (i = 0; i < vals; i++) cb->quantlist[i] = cvectors[book - 16].quant[i]; + } ready_codebook(cb); } @@ -403,17 +427,28 @@ static void create_vorbis_context(venc_context_t * venc, AVCodecContext * avccon // single residue rc = &venc->residues[0]; - rc->type = 0; + rc->type = 2; rc->begin = 0; - rc->end = 1 << (venc->blocksize[0] - 1); - rc->partition_size = 64; - rc->classifications = 2; + rc->end = 1600; + rc->partition_size = 32; + rc->classifications = 10; rc->classbook = 15; rc->books = av_malloc(sizeof(int[8]) * rc->classifications); for (i = 0; i < rc->classifications; i++) { + int a[][10] = { + { -1, -1, -1, -1, -1, -1, -1, -1, }, + { -1, -1, 16, -1, -1, -1, -1, -1, }, + { -1, -1, 17, -1, -1, -1, -1, -1, }, + { -1, -1, 18, -1, -1, -1, -1, -1, }, + { -1, -1, 19, -1, -1, -1, -1, -1, }, + { -1, -1, 20, -1, -1, -1, -1, -1, }, + { -1, -1, 21, -1, -1, -1, -1, -1, }, + { 22, 23, -1, -1, -1, -1, -1, -1, }, + { 24, 25, -1, -1, -1, -1, -1, -1, }, + { 26, 27, 28, -1, -1, -1, -1, -1, }, + }; int j; - for (j = 0; j < 8; j++) rc->books[i][j] = 16 + j; - rc->books[i][0] = rc->books[i][1] = rc->books[i][2] = rc->books[i][3] = -1; + for (j = 0; j < 8; j++) rc->books[i][j] = a[i][j]; } venc->nmappings = 1; @@ -872,7 +907,7 @@ static void residue_encode(venc_context_t * venc, residue_t * rc, PutBitContext while (p < partitions) { if (pass == 0) for (j = 0; j < channels; j++) { codebook_t * book = &venc->codebooks[rc->classbook]; - int entry = 0; + int entry = 99; put_bits(pb, book->entries[entry].len, book->entries[entry].codeword); for (i = classwords; i--; ) { classes[j][p + i] = entry % rc->classifications;