Mercurial > libavcodec.hg
comparison vorbis_enc.c @ 8306:ddecbc18fe94 libavcodec
Rename all vorbis encoder related typedefs to not use _t for POSIX compatibility
author | ods15 |
---|---|
date | Fri, 12 Dec 2008 05:12:51 +0000 |
parents | e70975d5ff80 |
children | e9d9d946f213 |
comparison
equal
deleted
inserted
replaced
8305:1408a8907da9 | 8306:ddecbc18fe94 |
---|---|
46 int seq_p; | 46 int seq_p; |
47 int lookup; | 47 int lookup; |
48 int * quantlist; | 48 int * quantlist; |
49 float * dimentions; | 49 float * dimentions; |
50 float * pow2; | 50 float * pow2; |
51 } codebook_t; | 51 } vorbis_enc_codebook; |
52 | 52 |
53 typedef struct { | 53 typedef struct { |
54 int dim; | 54 int dim; |
55 int subclass; | 55 int subclass; |
56 int masterbook; | 56 int masterbook; |
57 int * books; | 57 int * books; |
58 } floor_class_t; | 58 } vorbis_enc_floor_class; |
59 | 59 |
60 typedef struct { | 60 typedef struct { |
61 int partitions; | 61 int partitions; |
62 int * partition_to_class; | 62 int * partition_to_class; |
63 int nclasses; | 63 int nclasses; |
64 floor_class_t * classes; | 64 vorbis_enc_floor_class * classes; |
65 int multiplier; | 65 int multiplier; |
66 int rangebits; | 66 int rangebits; |
67 int values; | 67 int values; |
68 floor1_entry_t * list; | 68 vorbis_floor1_entry * list; |
69 } floor_t; | 69 } vorbis_enc_floor; |
70 | 70 |
71 typedef struct { | 71 typedef struct { |
72 int type; | 72 int type; |
73 int begin; | 73 int begin; |
74 int end; | 74 int end; |
75 int partition_size; | 75 int partition_size; |
76 int classifications; | 76 int classifications; |
77 int classbook; | 77 int classbook; |
78 int8_t (*books)[8]; | 78 int8_t (*books)[8]; |
79 float (*maxes)[2]; | 79 float (*maxes)[2]; |
80 } residue_t; | 80 } vorbis_enc_residue; |
81 | 81 |
82 typedef struct { | 82 typedef struct { |
83 int submaps; | 83 int submaps; |
84 int * mux; | 84 int * mux; |
85 int * floor; | 85 int * floor; |
86 int * residue; | 86 int * residue; |
87 int coupling_steps; | 87 int coupling_steps; |
88 int * magnitude; | 88 int * magnitude; |
89 int * angle; | 89 int * angle; |
90 } mapping_t; | 90 } vorbis_enc_mapping; |
91 | 91 |
92 typedef struct { | 92 typedef struct { |
93 int blockflag; | 93 int blockflag; |
94 int mapping; | 94 int mapping; |
95 } vorbis_mode_t; | 95 } vorbis_enc_mode; |
96 | 96 |
97 typedef struct { | 97 typedef struct { |
98 int channels; | 98 int channels; |
99 int sample_rate; | 99 int sample_rate; |
100 int log2_blocksize[2]; | 100 int log2_blocksize[2]; |
106 float * floor; // also used for tmp values for mdct | 106 float * floor; // also used for tmp values for mdct |
107 float * coeffs; // also used for residue after floor | 107 float * coeffs; // also used for residue after floor |
108 float quality; | 108 float quality; |
109 | 109 |
110 int ncodebooks; | 110 int ncodebooks; |
111 codebook_t * codebooks; | 111 vorbis_enc_codebook * codebooks; |
112 | 112 |
113 int nfloors; | 113 int nfloors; |
114 floor_t * floors; | 114 vorbis_enc_floor * floors; |
115 | 115 |
116 int nresidues; | 116 int nresidues; |
117 residue_t * residues; | 117 vorbis_enc_residue * residues; |
118 | 118 |
119 int nmappings; | 119 int nmappings; |
120 mapping_t * mappings; | 120 vorbis_enc_mapping * mappings; |
121 | 121 |
122 int nmodes; | 122 int nmodes; |
123 vorbis_mode_t * modes; | 123 vorbis_enc_mode * modes; |
124 | 124 |
125 int64_t sample_count; | 125 int64_t sample_count; |
126 } venc_context_t; | 126 } vorbis_enc_context; |
127 | 127 |
128 static inline void put_codeword(PutBitContext * pb, codebook_t * cb, int entry) { | 128 static inline void put_codeword(PutBitContext * pb, vorbis_enc_codebook * cb, int entry) { |
129 assert(entry >= 0); | 129 assert(entry >= 0); |
130 assert(entry < cb->nentries); | 130 assert(entry < cb->nentries); |
131 assert(cb->lens[entry]); | 131 assert(cb->lens[entry]); |
132 put_bits(pb, cb->lens[entry], cb->codewords[entry]); | 132 put_bits(pb, cb->lens[entry], cb->codewords[entry]); |
133 } | 133 } |
136 if (lookup == 1) return ff_vorbis_nth_root(entries, dimentions); | 136 if (lookup == 1) return ff_vorbis_nth_root(entries, dimentions); |
137 else if (lookup == 2) return dimentions * entries; | 137 else if (lookup == 2) return dimentions * entries; |
138 return 0; | 138 return 0; |
139 } | 139 } |
140 | 140 |
141 static void ready_codebook(codebook_t * cb) { | 141 static void ready_codebook(vorbis_enc_codebook * cb) { |
142 int i; | 142 int i; |
143 | 143 |
144 ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries); | 144 ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries); |
145 | 145 |
146 if (!cb->lookup) | 146 if (!cb->lookup) |
169 cb->pow2[i] /= 2.; | 169 cb->pow2[i] /= 2.; |
170 } | 170 } |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 static void ready_residue(residue_t * rc, venc_context_t * venc) { | 174 static void ready_residue(vorbis_enc_residue * rc, vorbis_enc_context * venc) { |
175 int i; | 175 int i; |
176 assert(rc->type == 2); | 176 assert(rc->type == 2); |
177 rc->maxes = av_mallocz(sizeof(float[2]) * rc->classifications); | 177 rc->maxes = av_mallocz(sizeof(float[2]) * rc->classifications); |
178 for (i = 0; i < rc->classifications; i++) { | 178 for (i = 0; i < rc->classifications; i++) { |
179 int j; | 179 int j; |
180 codebook_t * cb; | 180 vorbis_enc_codebook * cb; |
181 for (j = 0; j < 8; j++) | 181 for (j = 0; j < 8; j++) |
182 if (rc->books[i][j] != -1) break; | 182 if (rc->books[i][j] != -1) break; |
183 if (j == 8) continue; // zero | 183 if (j == 8) continue; // zero |
184 cb = &venc->codebooks[rc->books[i][j]]; | 184 cb = &venc->codebooks[rc->books[i][j]]; |
185 assert(cb->ndimentions >= 2); | 185 assert(cb->ndimentions >= 2); |
201 rc->maxes[i][0] += 0.8; | 201 rc->maxes[i][0] += 0.8; |
202 rc->maxes[i][1] += 0.8; | 202 rc->maxes[i][1] += 0.8; |
203 } | 203 } |
204 } | 204 } |
205 | 205 |
206 static void create_vorbis_context(venc_context_t * venc, AVCodecContext * avccontext) { | 206 static void create_vorbis_context(vorbis_enc_context * venc, AVCodecContext * avccontext) { |
207 floor_t * fc; | 207 vorbis_enc_floor * fc; |
208 residue_t * rc; | 208 vorbis_enc_residue * rc; |
209 mapping_t * mc; | 209 vorbis_enc_mapping * mc; |
210 int i, book; | 210 int i, book; |
211 | 211 |
212 venc->channels = avccontext->channels; | 212 venc->channels = avccontext->channels; |
213 venc->sample_rate = avccontext->sample_rate; | 213 venc->sample_rate = avccontext->sample_rate; |
214 venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11; | 214 venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11; |
215 | 215 |
216 venc->ncodebooks = FF_ARRAY_ELEMS(cvectors); | 216 venc->ncodebooks = FF_ARRAY_ELEMS(cvectors); |
217 venc->codebooks = av_malloc(sizeof(codebook_t) * venc->ncodebooks); | 217 venc->codebooks = av_malloc(sizeof(vorbis_enc_codebook) * venc->ncodebooks); |
218 | 218 |
219 // codebook 0..14 - floor1 book, values 0..255 | 219 // codebook 0..14 - floor1 book, values 0..255 |
220 // codebook 15 residue masterbook | 220 // codebook 15 residue masterbook |
221 // codebook 16..29 residue | 221 // codebook 16..29 residue |
222 for (book = 0; book < venc->ncodebooks; book++) { | 222 for (book = 0; book < venc->ncodebooks; book++) { |
223 codebook_t * cb = &venc->codebooks[book]; | 223 vorbis_enc_codebook * cb = &venc->codebooks[book]; |
224 int vals; | 224 int vals; |
225 cb->ndimentions = cvectors[book].dim; | 225 cb->ndimentions = cvectors[book].dim; |
226 cb->nentries = cvectors[book].real_len; | 226 cb->nentries = cvectors[book].real_len; |
227 cb->min = cvectors[book].min; | 227 cb->min = cvectors[book].min; |
228 cb->delta = cvectors[book].delta; | 228 cb->delta = cvectors[book].delta; |
244 } | 244 } |
245 ready_codebook(cb); | 245 ready_codebook(cb); |
246 } | 246 } |
247 | 247 |
248 venc->nfloors = 1; | 248 venc->nfloors = 1; |
249 venc->floors = av_malloc(sizeof(floor_t) * venc->nfloors); | 249 venc->floors = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors); |
250 | 250 |
251 // just 1 floor | 251 // just 1 floor |
252 fc = &venc->floors[0]; | 252 fc = &venc->floors[0]; |
253 fc->partitions = 8; | 253 fc->partitions = 8; |
254 fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions); | 254 fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions); |
257 static const int a[] = {0,1,2,2,3,3,4,4}; | 257 static const int a[] = {0,1,2,2,3,3,4,4}; |
258 fc->partition_to_class[i] = a[i]; | 258 fc->partition_to_class[i] = a[i]; |
259 fc->nclasses = FFMAX(fc->nclasses, fc->partition_to_class[i]); | 259 fc->nclasses = FFMAX(fc->nclasses, fc->partition_to_class[i]); |
260 } | 260 } |
261 fc->nclasses++; | 261 fc->nclasses++; |
262 fc->classes = av_malloc(sizeof(floor_class_t) * fc->nclasses); | 262 fc->classes = av_malloc(sizeof(vorbis_enc_floor_class) * fc->nclasses); |
263 for (i = 0; i < fc->nclasses; i++) { | 263 for (i = 0; i < fc->nclasses; i++) { |
264 floor_class_t * c = &fc->classes[i]; | 264 vorbis_enc_floor_class * c = &fc->classes[i]; |
265 int j, books; | 265 int j, books; |
266 c->dim = floor_classes[i].dim; | 266 c->dim = floor_classes[i].dim; |
267 c->subclass = floor_classes[i].subclass; | 267 c->subclass = floor_classes[i].subclass; |
268 c->masterbook = floor_classes[i].masterbook; | 268 c->masterbook = floor_classes[i].masterbook; |
269 books = (1 << c->subclass); | 269 books = (1 << c->subclass); |
276 | 276 |
277 fc->values = 2; | 277 fc->values = 2; |
278 for (i = 0; i < fc->partitions; i++) | 278 for (i = 0; i < fc->partitions; i++) |
279 fc->values += fc->classes[fc->partition_to_class[i]].dim; | 279 fc->values += fc->classes[fc->partition_to_class[i]].dim; |
280 | 280 |
281 fc->list = av_malloc(sizeof(floor1_entry_t) * fc->values); | 281 fc->list = av_malloc(sizeof(vorbis_floor1_entry) * fc->values); |
282 fc->list[0].x = 0; | 282 fc->list[0].x = 0; |
283 fc->list[1].x = 1 << fc->rangebits; | 283 fc->list[1].x = 1 << fc->rangebits; |
284 for (i = 2; i < fc->values; i++) { | 284 for (i = 2; i < fc->values; i++) { |
285 static const int a[] = { | 285 static const int a[] = { |
286 93, 23,372, 6, 46,186,750, 14, 33, 65, | 286 93, 23,372, 6, 46,186,750, 14, 33, 65, |
290 fc->list[i].x = a[i - 2]; | 290 fc->list[i].x = a[i - 2]; |
291 } | 291 } |
292 ff_vorbis_ready_floor1_list(fc->list, fc->values); | 292 ff_vorbis_ready_floor1_list(fc->list, fc->values); |
293 | 293 |
294 venc->nresidues = 1; | 294 venc->nresidues = 1; |
295 venc->residues = av_malloc(sizeof(residue_t) * venc->nresidues); | 295 venc->residues = av_malloc(sizeof(vorbis_enc_residue) * venc->nresidues); |
296 | 296 |
297 // single residue | 297 // single residue |
298 rc = &venc->residues[0]; | 298 rc = &venc->residues[0]; |
299 rc->type = 2; | 299 rc->type = 2; |
300 rc->begin = 0; | 300 rc->begin = 0; |
319 memcpy(rc->books, a, sizeof a); | 319 memcpy(rc->books, a, sizeof a); |
320 } | 320 } |
321 ready_residue(rc, venc); | 321 ready_residue(rc, venc); |
322 | 322 |
323 venc->nmappings = 1; | 323 venc->nmappings = 1; |
324 venc->mappings = av_malloc(sizeof(mapping_t) * venc->nmappings); | 324 venc->mappings = av_malloc(sizeof(vorbis_enc_mapping) * venc->nmappings); |
325 | 325 |
326 // single mapping | 326 // single mapping |
327 mc = &venc->mappings[0]; | 327 mc = &venc->mappings[0]; |
328 mc->submaps = 1; | 328 mc->submaps = 1; |
329 mc->mux = av_malloc(sizeof(int) * venc->channels); | 329 mc->mux = av_malloc(sizeof(int) * venc->channels); |
342 mc->magnitude[0] = 0; | 342 mc->magnitude[0] = 0; |
343 mc->angle[0] = 1; | 343 mc->angle[0] = 1; |
344 } | 344 } |
345 | 345 |
346 venc->nmodes = 1; | 346 venc->nmodes = 1; |
347 venc->modes = av_malloc(sizeof(vorbis_mode_t) * venc->nmodes); | 347 venc->modes = av_malloc(sizeof(vorbis_enc_mode) * venc->nmodes); |
348 | 348 |
349 // single mode | 349 // single mode |
350 venc->modes[0].blockflag = 0; | 350 venc->modes[0].blockflag = 0; |
351 venc->modes[0].mapping = 0; | 351 venc->modes[0].mapping = 0; |
352 | 352 |
371 if (mant < 0) { res |= (1 << 31); mant = -mant; } | 371 if (mant < 0) { res |= (1 << 31); mant = -mant; } |
372 res |= mant | (exp << 21); | 372 res |= mant | (exp << 21); |
373 put_bits(pb, 32, res); | 373 put_bits(pb, 32, res); |
374 } | 374 } |
375 | 375 |
376 static void put_codebook_header(PutBitContext * pb, codebook_t * cb) { | 376 static void put_codebook_header(PutBitContext * pb, vorbis_enc_codebook * cb) { |
377 int i; | 377 int i; |
378 int ordered = 0; | 378 int ordered = 0; |
379 | 379 |
380 put_bits(pb, 24, 0x564342); //magic | 380 put_bits(pb, 24, 0x564342); //magic |
381 put_bits(pb, 16, cb->ndimentions); | 381 put_bits(pb, 16, cb->ndimentions); |
430 for (i = 0; i < tmp; i++) | 430 for (i = 0; i < tmp; i++) |
431 put_bits(pb, bits, cb->quantlist[i]); | 431 put_bits(pb, bits, cb->quantlist[i]); |
432 } | 432 } |
433 } | 433 } |
434 | 434 |
435 static void put_floor_header(PutBitContext * pb, floor_t * fc) { | 435 static void put_floor_header(PutBitContext * pb, vorbis_enc_floor * fc) { |
436 int i; | 436 int i; |
437 | 437 |
438 put_bits(pb, 16, 1); // type, only floor1 is supported | 438 put_bits(pb, 16, 1); // type, only floor1 is supported |
439 | 439 |
440 put_bits(pb, 5, fc->partitions); | 440 put_bits(pb, 5, fc->partitions); |
462 | 462 |
463 for (i = 2; i < fc->values; i++) | 463 for (i = 2; i < fc->values; i++) |
464 put_bits(pb, fc->rangebits, fc->list[i].x); | 464 put_bits(pb, fc->rangebits, fc->list[i].x); |
465 } | 465 } |
466 | 466 |
467 static void put_residue_header(PutBitContext * pb, residue_t * rc) { | 467 static void put_residue_header(PutBitContext * pb, vorbis_enc_residue * rc) { |
468 int i; | 468 int i; |
469 | 469 |
470 put_bits(pb, 16, rc->type); | 470 put_bits(pb, 16, rc->type); |
471 | 471 |
472 put_bits(pb, 24, rc->begin); | 472 put_bits(pb, 24, rc->begin); |
493 if (rc->books[i][j] != -1) | 493 if (rc->books[i][j] != -1) |
494 put_bits(pb, 8, rc->books[i][j]); | 494 put_bits(pb, 8, rc->books[i][j]); |
495 } | 495 } |
496 } | 496 } |
497 | 497 |
498 static int put_main_header(venc_context_t * venc, uint8_t ** out) { | 498 static int put_main_header(vorbis_enc_context * venc, uint8_t ** out) { |
499 int i; | 499 int i; |
500 PutBitContext pb; | 500 PutBitContext pb; |
501 uint8_t buffer[50000] = {0}, * p = buffer; | 501 uint8_t buffer[50000] = {0}, * p = buffer; |
502 int buffer_len = sizeof buffer; | 502 int buffer_len = sizeof buffer; |
503 int len, hlens[3]; | 503 int len, hlens[3]; |
562 put_residue_header(&pb, &venc->residues[i]); | 562 put_residue_header(&pb, &venc->residues[i]); |
563 | 563 |
564 // mappings | 564 // mappings |
565 put_bits(&pb, 6, venc->nmappings - 1); | 565 put_bits(&pb, 6, venc->nmappings - 1); |
566 for (i = 0; i < venc->nmappings; i++) { | 566 for (i = 0; i < venc->nmappings; i++) { |
567 mapping_t * mc = &venc->mappings[i]; | 567 vorbis_enc_mapping * mc = &venc->mappings[i]; |
568 int j; | 568 int j; |
569 put_bits(&pb, 16, 0); // mapping type | 569 put_bits(&pb, 16, 0); // mapping type |
570 | 570 |
571 put_bits(&pb, 1, mc->submaps > 1); | 571 put_bits(&pb, 1, mc->submaps > 1); |
572 if (mc->submaps > 1) | 572 if (mc->submaps > 1) |
622 } | 622 } |
623 | 623 |
624 return p - *out; | 624 return p - *out; |
625 } | 625 } |
626 | 626 |
627 static float get_floor_average(floor_t * fc, float * coeffs, int i) { | 627 static float get_floor_average(vorbis_enc_floor * fc, float * coeffs, int i) { |
628 int begin = fc->list[fc->list[FFMAX(i-1, 0)].sort].x; | 628 int begin = fc->list[fc->list[FFMAX(i-1, 0)].sort].x; |
629 int end = fc->list[fc->list[FFMIN(i+1, fc->values - 1)].sort].x; | 629 int end = fc->list[fc->list[FFMIN(i+1, fc->values - 1)].sort].x; |
630 int j; | 630 int j; |
631 float average = 0; | 631 float average = 0; |
632 | 632 |
633 for (j = begin; j < end; j++) | 633 for (j = begin; j < end; j++) |
634 average += fabs(coeffs[j]); | 634 average += fabs(coeffs[j]); |
635 return average / (end - begin); | 635 return average / (end - begin); |
636 } | 636 } |
637 | 637 |
638 static void floor_fit(venc_context_t * venc, floor_t * fc, float * coeffs, uint_fast16_t * posts, int samples) { | 638 static void floor_fit(vorbis_enc_context * venc, vorbis_enc_floor * fc, float * coeffs, uint_fast16_t * posts, int samples) { |
639 int range = 255 / fc->multiplier + 1; | 639 int range = 255 / fc->multiplier + 1; |
640 int i; | 640 int i; |
641 float tot_average = 0.; | 641 float tot_average = 0.; |
642 float averages[fc->values]; | 642 float averages[fc->values]; |
643 for (i = 0; i < fc->values; i++){ | 643 for (i = 0; i < fc->values; i++){ |
661 | 661 |
662 static int render_point(int x0, int y0, int x1, int y1, int x) { | 662 static int render_point(int x0, int y0, int x1, int y1, int x) { |
663 return y0 + (x - x0) * (y1 - y0) / (x1 - x0); | 663 return y0 + (x - x0) * (y1 - y0) / (x1 - x0); |
664 } | 664 } |
665 | 665 |
666 static void floor_encode(venc_context_t * venc, floor_t * fc, PutBitContext * pb, uint_fast16_t * posts, float * floor, int samples) { | 666 static void floor_encode(vorbis_enc_context * venc, vorbis_enc_floor * fc, PutBitContext * pb, uint_fast16_t * posts, float * floor, int samples) { |
667 int range = 255 / fc->multiplier + 1; | 667 int range = 255 / fc->multiplier + 1; |
668 int coded[fc->values]; // first 2 values are unused | 668 int coded[fc->values]; // first 2 values are unused |
669 int i, counter; | 669 int i, counter; |
670 | 670 |
671 put_bits(pb, 1, 1); // non zero | 671 put_bits(pb, 1, 1); // non zero |
702 } | 702 } |
703 } | 703 } |
704 | 704 |
705 counter = 2; | 705 counter = 2; |
706 for (i = 0; i < fc->partitions; i++) { | 706 for (i = 0; i < fc->partitions; i++) { |
707 floor_class_t * c = &fc->classes[fc->partition_to_class[i]]; | 707 vorbis_enc_floor_class * c = &fc->classes[fc->partition_to_class[i]]; |
708 int k, cval = 0, csub = 1<<c->subclass; | 708 int k, cval = 0, csub = 1<<c->subclass; |
709 if (c->subclass) { | 709 if (c->subclass) { |
710 codebook_t * book = &venc->codebooks[c->masterbook]; | 710 vorbis_enc_codebook * book = &venc->codebooks[c->masterbook]; |
711 int cshift = 0; | 711 int cshift = 0; |
712 for (k = 0; k < c->dim; k++) { | 712 for (k = 0; k < c->dim; k++) { |
713 int l; | 713 int l; |
714 for (l = 0; l < csub; l++) { | 714 for (l = 0; l < csub; l++) { |
715 int maxval = 1; | 715 int maxval = 1; |
735 } | 735 } |
736 | 736 |
737 ff_vorbis_floor1_render_list(fc->list, fc->values, posts, coded, fc->multiplier, floor, samples); | 737 ff_vorbis_floor1_render_list(fc->list, fc->values, posts, coded, fc->multiplier, floor, samples); |
738 } | 738 } |
739 | 739 |
740 static float * put_vector(codebook_t * book, PutBitContext * pb, float * num) { | 740 static float * put_vector(vorbis_enc_codebook * book, PutBitContext * pb, float * num) { |
741 int i, entry = -1; | 741 int i, entry = -1; |
742 float distance = FLT_MAX; | 742 float distance = FLT_MAX; |
743 assert(book->dimentions); | 743 assert(book->dimentions); |
744 for (i = 0; i < book->nentries; i++) { | 744 for (i = 0; i < book->nentries; i++) { |
745 float * vec = book->dimentions + i * book->ndimentions, d = book->pow2[i]; | 745 float * vec = book->dimentions + i * book->ndimentions, d = book->pow2[i]; |
754 } | 754 } |
755 put_codeword(pb, book, entry); | 755 put_codeword(pb, book, entry); |
756 return &book->dimentions[entry * book->ndimentions]; | 756 return &book->dimentions[entry * book->ndimentions]; |
757 } | 757 } |
758 | 758 |
759 static void residue_encode(venc_context_t * venc, residue_t * rc, PutBitContext * pb, float * coeffs, int samples, int real_ch) { | 759 static void residue_encode(vorbis_enc_context * venc, vorbis_enc_residue * rc, PutBitContext * pb, float * coeffs, int samples, int real_ch) { |
760 int pass, i, j, p, k; | 760 int pass, i, j, p, k; |
761 int psize = rc->partition_size; | 761 int psize = rc->partition_size; |
762 int partitions = (rc->end - rc->begin) / psize; | 762 int partitions = (rc->end - rc->begin) / psize; |
763 int channels = (rc->type == 2) ? 1 : real_ch; | 763 int channels = (rc->type == 2) ? 1 : real_ch; |
764 int classes[channels][partitions]; | 764 int classes[channels][partitions]; |
783 for (pass = 0; pass < 8; pass++) { | 783 for (pass = 0; pass < 8; pass++) { |
784 p = 0; | 784 p = 0; |
785 while (p < partitions) { | 785 while (p < partitions) { |
786 if (pass == 0) | 786 if (pass == 0) |
787 for (j = 0; j < channels; j++) { | 787 for (j = 0; j < channels; j++) { |
788 codebook_t * book = &venc->codebooks[rc->classbook]; | 788 vorbis_enc_codebook * book = &venc->codebooks[rc->classbook]; |
789 int entry = 0; | 789 int entry = 0; |
790 for (i = 0; i < classwords; i++) { | 790 for (i = 0; i < classwords; i++) { |
791 entry *= rc->classifications; | 791 entry *= rc->classifications; |
792 entry += classes[j][p + i]; | 792 entry += classes[j][p + i]; |
793 } | 793 } |
794 put_codeword(pb, book, entry); | 794 put_codeword(pb, book, entry); |
795 } | 795 } |
796 for (i = 0; i < classwords && p < partitions; i++, p++) { | 796 for (i = 0; i < classwords && p < partitions; i++, p++) { |
797 for (j = 0; j < channels; j++) { | 797 for (j = 0; j < channels; j++) { |
798 int nbook = rc->books[classes[j][p]][pass]; | 798 int nbook = rc->books[classes[j][p]][pass]; |
799 codebook_t * book = &venc->codebooks[nbook]; | 799 vorbis_enc_codebook * book = &venc->codebooks[nbook]; |
800 float * buf = coeffs + samples*j + rc->begin + p*psize; | 800 float * buf = coeffs + samples*j + rc->begin + p*psize; |
801 if (nbook == -1) continue; | 801 if (nbook == -1) continue; |
802 | 802 |
803 assert(rc->type == 0 || rc->type == 2); | 803 assert(rc->type == 0 || rc->type == 2); |
804 assert(!(psize % book->ndimentions)); | 804 assert(!(psize % book->ndimentions)); |
839 } | 839 } |
840 } | 840 } |
841 } | 841 } |
842 } | 842 } |
843 | 843 |
844 static int apply_window_and_mdct(venc_context_t * venc, signed short * audio, int samples) { | 844 static int apply_window_and_mdct(vorbis_enc_context * venc, signed short * audio, int samples) { |
845 int i, j, channel; | 845 int i, j, channel; |
846 const float * win = venc->win[0]; | 846 const float * win = venc->win[0]; |
847 int window_len = 1 << (venc->log2_blocksize[0] - 1); | 847 int window_len = 1 << (venc->log2_blocksize[0] - 1); |
848 float n = (float)(1 << venc->log2_blocksize[0]) / 4.; | 848 float n = (float)(1 << venc->log2_blocksize[0]) / 4.; |
849 // FIXME use dsp | 849 // FIXME use dsp |
891 return 1; | 891 return 1; |
892 } | 892 } |
893 | 893 |
894 static av_cold int vorbis_encode_init(AVCodecContext * avccontext) | 894 static av_cold int vorbis_encode_init(AVCodecContext * avccontext) |
895 { | 895 { |
896 venc_context_t * venc = avccontext->priv_data; | 896 vorbis_enc_context * venc = avccontext->priv_data; |
897 | 897 |
898 if (avccontext->channels != 2) { | 898 if (avccontext->channels != 2) { |
899 av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n"); | 899 av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n"); |
900 return -1; | 900 return -1; |
901 } | 901 } |
918 return 0; | 918 return 0; |
919 } | 919 } |
920 | 920 |
921 static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * packets, int buf_size, void *data) | 921 static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * packets, int buf_size, void *data) |
922 { | 922 { |
923 venc_context_t * venc = avccontext->priv_data; | 923 vorbis_enc_context * venc = avccontext->priv_data; |
924 signed short * audio = data; | 924 signed short * audio = data; |
925 int samples = data ? avccontext->frame_size : 0; | 925 int samples = data ? avccontext->frame_size : 0; |
926 vorbis_mode_t * mode; | 926 vorbis_enc_mode * mode; |
927 mapping_t * mapping; | 927 vorbis_enc_mapping * mapping; |
928 PutBitContext pb; | 928 PutBitContext pb; |
929 int i; | 929 int i; |
930 | 930 |
931 if (!apply_window_and_mdct(venc, audio, samples)) return 0; | 931 if (!apply_window_and_mdct(venc, audio, samples)) return 0; |
932 samples = 1 << (venc->log2_blocksize[0] - 1); | 932 samples = 1 << (venc->log2_blocksize[0] - 1); |
943 put_bits(&pb, 1, 0); | 943 put_bits(&pb, 1, 0); |
944 put_bits(&pb, 1, 0); | 944 put_bits(&pb, 1, 0); |
945 } | 945 } |
946 | 946 |
947 for (i = 0; i < venc->channels; i++) { | 947 for (i = 0; i < venc->channels; i++) { |
948 floor_t * fc = &venc->floors[mapping->floor[mapping->mux[i]]]; | 948 vorbis_enc_floor * fc = &venc->floors[mapping->floor[mapping->mux[i]]]; |
949 uint_fast16_t posts[fc->values]; | 949 uint_fast16_t posts[fc->values]; |
950 floor_fit(venc, fc, &venc->coeffs[i * samples], posts, samples); | 950 floor_fit(venc, fc, &venc->coeffs[i * samples], posts, samples); |
951 floor_encode(venc, fc, &pb, posts, &venc->floor[i * samples], samples); | 951 floor_encode(venc, fc, &pb, posts, &venc->floor[i * samples], samples); |
952 } | 952 } |
953 | 953 |
976 } | 976 } |
977 | 977 |
978 | 978 |
979 static av_cold int vorbis_encode_close(AVCodecContext * avccontext) | 979 static av_cold int vorbis_encode_close(AVCodecContext * avccontext) |
980 { | 980 { |
981 venc_context_t * venc = avccontext->priv_data; | 981 vorbis_enc_context * venc = avccontext->priv_data; |
982 int i; | 982 int i; |
983 | 983 |
984 if (venc->codebooks) | 984 if (venc->codebooks) |
985 for (i = 0; i < venc->ncodebooks; i++) { | 985 for (i = 0; i < venc->ncodebooks; i++) { |
986 av_freep(&venc->codebooks[i].lens); | 986 av_freep(&venc->codebooks[i].lens); |
1038 | 1038 |
1039 AVCodec vorbis_encoder = { | 1039 AVCodec vorbis_encoder = { |
1040 "vorbis", | 1040 "vorbis", |
1041 CODEC_TYPE_AUDIO, | 1041 CODEC_TYPE_AUDIO, |
1042 CODEC_ID_VORBIS, | 1042 CODEC_ID_VORBIS, |
1043 sizeof(venc_context_t), | 1043 sizeof(vorbis_enc_context), |
1044 vorbis_encode_init, | 1044 vorbis_encode_init, |
1045 vorbis_encode_frame, | 1045 vorbis_encode_frame, |
1046 vorbis_encode_close, | 1046 vorbis_encode_close, |
1047 .capabilities= CODEC_CAP_DELAY, | 1047 .capabilities= CODEC_CAP_DELAY, |
1048 .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, | 1048 .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, |