comparison vorbis_enc.c @ 12513:66c6184769af libavcodec

vorbisenc: remove VLAs
author mru
date Fri, 24 Sep 2010 20:42:08 +0000
parents dde20597f15e
children
comparison
equal deleted inserted replaced
12512:58bd8cb86f5d 12513:66c6184769af
124 vorbis_enc_mode *modes; 124 vorbis_enc_mode *modes;
125 125
126 int64_t sample_count; 126 int64_t sample_count;
127 } vorbis_enc_context; 127 } vorbis_enc_context;
128 128
129 #define MAX_CHANNELS 2
130 #define MAX_CODEBOOK_DIM 8
131
132 #define MAX_FLOOR_CLASS_DIM 4
133 #define NUM_FLOOR_PARTITIONS 8
134 #define MAX_FLOOR_VALUES (MAX_FLOOR_CLASS_DIM*NUM_FLOOR_PARTITIONS+2)
135
136 #define RESIDUE_SIZE 1600
137 #define RESIDUE_PART_SIZE 32
138 #define NUM_RESIDUE_PARTITIONS (RESIDUE_SIZE/RESIDUE_PART_SIZE)
139
129 static inline void put_codeword(PutBitContext *pb, vorbis_enc_codebook *cb, 140 static inline void put_codeword(PutBitContext *pb, vorbis_enc_codebook *cb,
130 int entry) 141 int entry)
131 { 142 {
132 assert(entry >= 0); 143 assert(entry >= 0);
133 assert(entry < cb->nentries); 144 assert(entry < cb->nentries);
261 venc->nfloors = 1; 272 venc->nfloors = 1;
262 venc->floors = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors); 273 venc->floors = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors);
263 274
264 // just 1 floor 275 // just 1 floor
265 fc = &venc->floors[0]; 276 fc = &venc->floors[0];
266 fc->partitions = 8; 277 fc->partitions = NUM_FLOOR_PARTITIONS;
267 fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions); 278 fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions);
268 fc->nclasses = 0; 279 fc->nclasses = 0;
269 for (i = 0; i < fc->partitions; i++) { 280 for (i = 0; i < fc->partitions; i++) {
270 static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4}; 281 static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4};
271 fc->partition_to_class[i] = a[i]; 282 fc->partition_to_class[i] = a[i];
666 float *coeffs, uint_fast16_t *posts, int samples) 677 float *coeffs, uint_fast16_t *posts, int samples)
667 { 678 {
668 int range = 255 / fc->multiplier + 1; 679 int range = 255 / fc->multiplier + 1;
669 int i; 680 int i;
670 float tot_average = 0.; 681 float tot_average = 0.;
671 float averages[fc->values]; 682 float averages[MAX_FLOOR_VALUES];
672 for (i = 0; i < fc->values; i++) { 683 for (i = 0; i < fc->values; i++) {
673 averages[i] = get_floor_average(fc, coeffs, i); 684 averages[i] = get_floor_average(fc, coeffs, i);
674 tot_average += averages[i]; 685 tot_average += averages[i];
675 } 686 }
676 tot_average /= fc->values; 687 tot_average /= fc->values;
697 static void floor_encode(vorbis_enc_context *venc, vorbis_enc_floor *fc, 708 static void floor_encode(vorbis_enc_context *venc, vorbis_enc_floor *fc,
698 PutBitContext *pb, uint_fast16_t *posts, 709 PutBitContext *pb, uint_fast16_t *posts,
699 float *floor, int samples) 710 float *floor, int samples)
700 { 711 {
701 int range = 255 / fc->multiplier + 1; 712 int range = 255 / fc->multiplier + 1;
702 int coded[fc->values]; // first 2 values are unused 713 int coded[MAX_FLOOR_VALUES]; // first 2 values are unused
703 int i, counter; 714 int i, counter;
704 715
705 put_bits(pb, 1, 1); // non zero 716 put_bits(pb, 1, 1); // non zero
706 put_bits(pb, ilog(range - 1), posts[0]); 717 put_bits(pb, ilog(range - 1), posts[0]);
707 put_bits(pb, ilog(range - 1), posts[1]); 718 put_bits(pb, ilog(range - 1), posts[1]);
805 { 816 {
806 int pass, i, j, p, k; 817 int pass, i, j, p, k;
807 int psize = rc->partition_size; 818 int psize = rc->partition_size;
808 int partitions = (rc->end - rc->begin) / psize; 819 int partitions = (rc->end - rc->begin) / psize;
809 int channels = (rc->type == 2) ? 1 : real_ch; 820 int channels = (rc->type == 2) ? 1 : real_ch;
810 int classes[channels][partitions]; 821 int classes[MAX_CHANNELS][NUM_RESIDUE_PARTITIONS];
811 int classwords = venc->codebooks[rc->classbook].ndimentions; 822 int classwords = venc->codebooks[rc->classbook].ndimentions;
812 823
813 assert(rc->type == 2); 824 assert(rc->type == 2);
814 assert(real_ch == 2); 825 assert(real_ch == 2);
815 for (p = 0; p < partitions; p++) { 826 for (p = 0; p < partitions; p++) {
862 a1 = (s % real_ch) * samples; 873 a1 = (s % real_ch) * samples;
863 b1 = s / real_ch; 874 b1 = s / real_ch;
864 s = real_ch * samples; 875 s = real_ch * samples;
865 for (k = 0; k < psize; k += book->ndimentions) { 876 for (k = 0; k < psize; k += book->ndimentions) {
866 int dim, a2 = a1, b2 = b1; 877 int dim, a2 = a1, b2 = b1;
867 float vec[book->ndimentions], *pv = vec; 878 float vec[MAX_CODEBOOK_DIM], *pv = vec;
868 for (dim = book->ndimentions; dim--; ) { 879 for (dim = book->ndimentions; dim--; ) {
869 *pv++ = coeffs[a2 + b2]; 880 *pv++ = coeffs[a2 + b2];
870 if ((a2 += samples) == s) { 881 if ((a2 += samples) == s) {
871 a2 = 0; 882 a2 = 0;
872 b2++; 883 b2++;
997 put_bits(&pb, 1, 0); 1008 put_bits(&pb, 1, 0);
998 } 1009 }
999 1010
1000 for (i = 0; i < venc->channels; i++) { 1011 for (i = 0; i < venc->channels; i++) {
1001 vorbis_enc_floor *fc = &venc->floors[mapping->floor[mapping->mux[i]]]; 1012 vorbis_enc_floor *fc = &venc->floors[mapping->floor[mapping->mux[i]]];
1002 uint_fast16_t posts[fc->values]; 1013 uint_fast16_t posts[MAX_FLOOR_VALUES];
1003 floor_fit(venc, fc, &venc->coeffs[i * samples], posts, samples); 1014 floor_fit(venc, fc, &venc->coeffs[i * samples], posts, samples);
1004 floor_encode(venc, fc, &pb, posts, &venc->floor[i * samples], samples); 1015 floor_encode(venc, fc, &pb, posts, &venc->floor[i * samples], samples);
1005 } 1016 }
1006 1017
1007 for (i = 0; i < venc->channels * samples; i++) 1018 for (i = 0; i < venc->channels * samples; i++)