Mercurial > libavcodec.hg
comparison vorbis_enc.c @ 3881:b272797e8149 libavcodec
Original Commit: r81 | ods15 | 2006-09-29 21:02:09 +0300 (Fri, 29 Sep 2006) | 2 lines
make residue_encode decide good classification per partition
author | ods15 |
---|---|
date | Mon, 02 Oct 2006 06:08:36 +0000 |
parents | 3d5920649c39 |
children | 6c03e983f866 |
comparison
equal
deleted
inserted
replaced
3880:3d5920649c39 | 3881:b272797e8149 |
---|---|
83 int end; | 83 int end; |
84 int partition_size; | 84 int partition_size; |
85 int classifications; | 85 int classifications; |
86 int classbook; | 86 int classbook; |
87 int (*books)[8]; | 87 int (*books)[8]; |
88 float (*maxes)[2]; | |
88 } residue_t; | 89 } residue_t; |
89 | 90 |
90 typedef struct { | 91 typedef struct { |
91 int submaps; | 92 int submaps; |
92 int * mux; | 93 int * mux; |
258 int tmp = fc->list[i].sort; | 259 int tmp = fc->list[i].sort; |
259 fc->list[i].sort = fc->list[j].sort; | 260 fc->list[i].sort = fc->list[j].sort; |
260 fc->list[j].sort = tmp; | 261 fc->list[j].sort = tmp; |
261 } | 262 } |
262 } | 263 } |
264 } | |
265 } | |
266 | |
267 static void ready_residue(residue_t * rc, venc_context_t * venc) { | |
268 int i; | |
269 assert(rc->type == 2); | |
270 rc->maxes = av_mallocz(sizeof(float[2]) * rc->classifications); | |
271 for (i = 0; i < rc->classifications; i++) { | |
272 int j; | |
273 codebook_t * cb; | |
274 for (j = 0; j < 8; j++) if (rc->books[i][j] != -1) break; | |
275 if (j == 8) continue; // zero | |
276 cb = &venc->codebooks[rc->books[i][j]]; | |
277 assert(cb->ndimentions >= 2); | |
278 assert(cb->lookup); | |
279 | |
280 for (j = 0; j < cb->nentries; j++) { | |
281 float a; | |
282 if (!cb->entries[j].len) continue; | |
283 a = fabs(cb->dimentions[j * cb->ndimentions]); | |
284 if (a > rc->maxes[i][0]) rc->maxes[i][0] = a; | |
285 a = fabs(cb->dimentions[j * cb->ndimentions + 1]); | |
286 if (a > rc->maxes[i][1]) rc->maxes[i][1] = a; | |
287 } | |
288 } | |
289 // small bias | |
290 for (i = 0; i < rc->classifications; i++) { | |
291 rc->maxes[i][0] += 0.8; | |
292 rc->maxes[i][1] += 0.8; | |
263 } | 293 } |
264 } | 294 } |
265 | 295 |
266 static void create_vorbis_context(venc_context_t * venc, AVCodecContext * avccontext) { | 296 static void create_vorbis_context(venc_context_t * venc, AVCodecContext * avccontext) { |
267 codebook_t * cb; | 297 codebook_t * cb; |
448 { 26, 27, 28, -1, -1, -1, -1, -1, }, | 478 { 26, 27, 28, -1, -1, -1, -1, -1, }, |
449 }; | 479 }; |
450 int j; | 480 int j; |
451 for (j = 0; j < 8; j++) rc->books[i][j] = a[i][j]; | 481 for (j = 0; j < 8; j++) rc->books[i][j] = a[i][j]; |
452 } | 482 } |
483 ready_residue(rc, venc); | |
453 | 484 |
454 venc->nmappings = 1; | 485 venc->nmappings = 1; |
455 venc->mappings = av_malloc(sizeof(mapping_t) * venc->nmappings); | 486 venc->mappings = av_malloc(sizeof(mapping_t) * venc->nmappings); |
456 | 487 |
457 // single mapping | 488 // single mapping |
900 int classwords = venc->codebooks[rc->classbook].ndimentions; | 931 int classwords = venc->codebooks[rc->classbook].ndimentions; |
901 int real_ch = channels; | 932 int real_ch = channels; |
902 | 933 |
903 if (rc->type == 2) channels = 1; | 934 if (rc->type == 2) channels = 1; |
904 | 935 |
936 assert(rc->type == 2); | |
937 assert(real_ch == 2); | |
938 for (p = 0; p < partitions; p++) { | |
939 float max1 = 0., max2 = 0.; | |
940 int s = rc->begin + p * psize; | |
941 for (k = s; k < s + psize; k += 2) { | |
942 if (fabs(coeffs[k / real_ch]) > max1) max1 = fabs(coeffs[k / real_ch]); | |
943 if (fabs(coeffs[samples + k / real_ch]) > max2) max2 = fabs(coeffs[samples + k / real_ch]); | |
944 } | |
945 | |
946 for (i = 0; i < rc->classifications - 1; i++) { | |
947 if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1]) break; | |
948 } | |
949 classes[0][p] = i; | |
950 } | |
951 | |
905 for (pass = 0; pass < 8; pass++) { | 952 for (pass = 0; pass < 8; pass++) { |
906 p = 0; | 953 p = 0; |
907 while (p < partitions) { | 954 while (p < partitions) { |
908 if (pass == 0) for (j = 0; j < channels; j++) { | 955 if (pass == 0) for (j = 0; j < channels; j++) { |
909 codebook_t * book = &venc->codebooks[rc->classbook]; | 956 codebook_t * book = &venc->codebooks[rc->classbook]; |
910 int entry = 99; | 957 int entry = 0; |
958 for (i = 0; i < classwords; i++) { | |
959 entry *= rc->classifications; | |
960 entry += classes[j][p + i]; | |
961 } | |
962 assert(entry < book->nentries); | |
963 assert(entry >= 0); | |
911 put_bits(pb, book->entries[entry].len, book->entries[entry].codeword); | 964 put_bits(pb, book->entries[entry].len, book->entries[entry].codeword); |
912 for (i = classwords; i--; ) { | |
913 classes[j][p + i] = entry % rc->classifications; | |
914 entry /= rc->classifications; | |
915 } | |
916 } | 965 } |
917 for (i = 0; i < classwords && p < partitions; i++, p++) { | 966 for (i = 0; i < classwords && p < partitions; i++, p++) { |
918 for (j = 0; j < channels; j++) { | 967 for (j = 0; j < channels; j++) { |
919 int nbook = rc->books[classes[j][p]][pass]; | 968 int nbook = rc->books[classes[j][p]][pass]; |
920 codebook_t * book = &venc->codebooks[nbook]; | 969 codebook_t * book = &venc->codebooks[nbook]; |
1104 } | 1153 } |
1105 av_freep(&venc->floors); | 1154 av_freep(&venc->floors); |
1106 | 1155 |
1107 if (venc->residues) for (i = 0; i < venc->nresidues; i++) { | 1156 if (venc->residues) for (i = 0; i < venc->nresidues; i++) { |
1108 av_freep(&venc->residues[i].books); | 1157 av_freep(&venc->residues[i].books); |
1158 av_freep(&venc->residues[i].maxes); | |
1109 } | 1159 } |
1110 av_freep(&venc->residues); | 1160 av_freep(&venc->residues); |
1111 | 1161 |
1112 if (venc->mappings) for (i = 0; i < venc->nmappings; i++) { | 1162 if (venc->mappings) for (i = 0; i < venc->nmappings; i++) { |
1113 av_freep(&venc->mappings[i].mux); | 1163 av_freep(&venc->mappings[i].mux); |