Revision a7adcf29 libavcodec/vorbis_enc.c

View differences:

libavcodec/vorbis_enc.c
38 38

  
39 39
typedef struct {
40 40
    int nentries;
41
    uint8_t * lens;
42
    uint32_t * codewords;
41
    uint8_t *lens;
42
    uint32_t *codewords;
43 43
    int ndimentions;
44 44
    float min;
45 45
    float delta;
46 46
    int seq_p;
47 47
    int lookup;
48
    int * quantlist;
49
    float * dimentions;
50
    float * pow2;
48
    int *quantlist;
49
    float *dimentions;
50
    float *pow2;
51 51
} vorbis_enc_codebook;
52 52

  
53 53
typedef struct {
54 54
    int dim;
55 55
    int subclass;
56 56
    int masterbook;
57
    int * books;
57
    int *books;
58 58
} vorbis_enc_floor_class;
59 59

  
60 60
typedef struct {
61 61
    int partitions;
62
    int * partition_to_class;
62
    int *partition_to_class;
63 63
    int nclasses;
64
    vorbis_enc_floor_class * classes;
64
    vorbis_enc_floor_class *classes;
65 65
    int multiplier;
66 66
    int rangebits;
67 67
    int values;
68
    vorbis_floor1_entry * list;
68
    vorbis_floor1_entry *list;
69 69
} vorbis_enc_floor;
70 70

  
71 71
typedef struct {
......
81 81

  
82 82
typedef struct {
83 83
    int submaps;
84
    int * mux;
85
    int * floor;
86
    int * residue;
84
    int *mux;
85
    int *floor;
86
    int *residue;
87 87
    int coupling_steps;
88
    int * magnitude;
89
    int * angle;
88
    int *magnitude;
89
    int *angle;
90 90
} vorbis_enc_mapping;
91 91

  
92 92
typedef struct {
......
99 99
    int sample_rate;
100 100
    int log2_blocksize[2];
101 101
    FFTContext mdct[2];
102
    const float * win[2];
102
    const float *win[2];
103 103
    int have_saved;
104
    float * saved;
105
    float * samples;
106
    float * floor; // also used for tmp values for mdct
107
    float * coeffs; // also used for residue after floor
104
    float *saved;
105
    float *samples;
106
    float *floor;  // also used for tmp values for mdct
107
    float *coeffs; // also used for residue after floor
108 108
    float quality;
109 109

  
110 110
    int ncodebooks;
111
    vorbis_enc_codebook * codebooks;
111
    vorbis_enc_codebook *codebooks;
112 112

  
113 113
    int nfloors;
114
    vorbis_enc_floor * floors;
114
    vorbis_enc_floor *floors;
115 115

  
116 116
    int nresidues;
117
    vorbis_enc_residue * residues;
117
    vorbis_enc_residue *residues;
118 118

  
119 119
    int nmappings;
120
    vorbis_enc_mapping * mappings;
120
    vorbis_enc_mapping *mappings;
121 121

  
122 122
    int nmodes;
123
    vorbis_enc_mode * modes;
123
    vorbis_enc_mode *modes;
124 124

  
125 125
    int64_t sample_count;
126 126
} vorbis_enc_context;
127 127

  
128
static inline void put_codeword(PutBitContext * pb, vorbis_enc_codebook * cb,
128
static inline void put_codeword(PutBitContext *pb, vorbis_enc_codebook *cb,
129 129
                                int entry)
130 130
{
131 131
    assert(entry >= 0);
......
139 139
    if (lookup == 1)
140 140
        return ff_vorbis_nth_root(entries, dimentions);
141 141
    else if (lookup == 2)
142
        return dimentions * entries;
142
        return dimentions *entries;
143 143
    return 0;
144 144
}
145 145

  
146
static void ready_codebook(vorbis_enc_codebook * cb)
146
static void ready_codebook(vorbis_enc_codebook *cb)
147 147
{
148 148
    int i;
149 149

  
150 150
    ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries);
151 151

  
152
    if (!cb->lookup)
152
    if (!cb->lookup) {
153 153
        cb->pow2 = cb->dimentions = NULL;
154
    else {
154
    } else {
155 155
        int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);
156 156
        cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions);
157 157
        cb->pow2 = av_mallocz(sizeof(float) * cb->nentries);
......
169 169
                cb->dimentions[i * cb->ndimentions + j] = last + cb->min + cb->quantlist[off] * cb->delta;
170 170
                if (cb->seq_p)
171 171
                    last = cb->dimentions[i * cb->ndimentions + j];
172
                cb->pow2[i] += cb->dimentions[i * cb->ndimentions + j]*cb->dimentions[i * cb->ndimentions + j];
172
                cb->pow2[i] += cb->dimentions[i * cb->ndimentions + j] * cb->dimentions[i * cb->ndimentions + j];
173 173
                div *= vals;
174 174
            }
175 175
            cb->pow2[i] /= 2.;
......
177 177
    }
178 178
}
179 179

  
180
static void ready_residue(vorbis_enc_residue * rc, vorbis_enc_context * venc)
180
static void ready_residue(vorbis_enc_residue *rc, vorbis_enc_context *venc)
181 181
{
182 182
    int i;
183 183
    assert(rc->type == 2);
......
188 188
        for (j = 0; j < 8; j++)
189 189
            if (rc->books[i][j] != -1)
190 190
                break;
191
        if (j == 8)
192
            continue; // zero
191
        if (j == 8) // zero
192
            continue;
193 193
        cb = &venc->codebooks[rc->books[i][j]];
194 194
        assert(cb->ndimentions >= 2);
195 195
        assert(cb->lookup);
......
213 213
    }
214 214
}
215 215

  
216
static void create_vorbis_context(vorbis_enc_context * venc,
217
                                  AVCodecContext * avccontext)
216
static void create_vorbis_context(vorbis_enc_context *venc,
217
                                  AVCodecContext *avccontext)
218 218
{
219
    vorbis_enc_floor * fc;
220
    vorbis_enc_residue * rc;
221
    vorbis_enc_mapping * mc;
219
    vorbis_enc_floor   *fc;
220
    vorbis_enc_residue *rc;
221
    vorbis_enc_mapping *mc;
222 222
    int i, book;
223 223

  
224
    venc->channels = avccontext->channels;
224
    venc->channels    = avccontext->channels;
225 225
    venc->sample_rate = avccontext->sample_rate;
226 226
    venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11;
227 227

  
228 228
    venc->ncodebooks = FF_ARRAY_ELEMS(cvectors);
229
    venc->codebooks = av_malloc(sizeof(vorbis_enc_codebook) * venc->ncodebooks);
229
    venc->codebooks  = av_malloc(sizeof(vorbis_enc_codebook) * venc->ncodebooks);
230 230

  
231 231
    // codebook 0..14 - floor1 book, values 0..255
232 232
    // codebook 15 residue masterbook
233 233
    // codebook 16..29 residue
234 234
    for (book = 0; book < venc->ncodebooks; book++) {
235
        vorbis_enc_codebook * cb = &venc->codebooks[book];
235
        vorbis_enc_codebook *cb = &venc->codebooks[book];
236 236
        int vals;
237 237
        cb->ndimentions = cvectors[book].dim;
238
        cb->nentries = cvectors[book].real_len;
239
        cb->min = cvectors[book].min;
240
        cb->delta = cvectors[book].delta;
241
        cb->lookup = cvectors[book].lookup;
242
        cb->seq_p = 0;
238
        cb->nentries    = cvectors[book].real_len;
239
        cb->min         = cvectors[book].min;
240
        cb->delta       = cvectors[book].delta;
241
        cb->lookup      = cvectors[book].lookup;
242
        cb->seq_p       = 0;
243 243

  
244
        cb->lens = av_malloc(sizeof(uint8_t) * cb->nentries);
244
        cb->lens      = av_malloc(sizeof(uint8_t)  * cb->nentries);
245 245
        cb->codewords = av_malloc(sizeof(uint32_t) * cb->nentries);
246 246
        memcpy(cb->lens, cvectors[book].clens, cvectors[book].len);
247 247
        memset(cb->lens + cvectors[book].len, 0, cb->nentries - cvectors[book].len);
......
258 258
    }
259 259

  
260 260
    venc->nfloors = 1;
261
    venc->floors = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors);
261
    venc->floors  = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors);
262 262

  
263 263
    // just 1 floor
264 264
    fc = &venc->floors[0];
265
    fc->partitions = 8;
265
    fc->partitions         = 8;
266 266
    fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions);
267
    fc->nclasses = 0;
267
    fc->nclasses           = 0;
268 268
    for (i = 0; i < fc->partitions; i++) {
269
        static const int a[] = {0,1,2,2,3,3,4,4};
269
        static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4};
270 270
        fc->partition_to_class[i] = a[i];
271 271
        fc->nclasses = FFMAX(fc->nclasses, fc->partition_to_class[i]);
272 272
    }
......
275 275
    for (i = 0; i < fc->nclasses; i++) {
276 276
        vorbis_enc_floor_class * c = &fc->classes[i];
277 277
        int j, books;
278
        c->dim = floor_classes[i].dim;
279
        c->subclass = floor_classes[i].subclass;
278
        c->dim        = floor_classes[i].dim;
279
        c->subclass   = floor_classes[i].subclass;
280 280
        c->masterbook = floor_classes[i].masterbook;
281
        books = (1 << c->subclass);
282
        c->books = av_malloc(sizeof(int) * books);
281
        books         = (1 << c->subclass);
282
        c->books      = av_malloc(sizeof(int) * books);
283 283
        for (j = 0; j < books; j++)
284 284
            c->books[j] = floor_classes[i].nbooks[j];
285 285
    }
286 286
    fc->multiplier = 2;
287
    fc->rangebits = venc->log2_blocksize[0] - 1;
287
    fc->rangebits  = venc->log2_blocksize[0] - 1;
288 288

  
289 289
    fc->values = 2;
290 290
    for (i = 0; i < fc->partitions; i++)
......
304 304
    ff_vorbis_ready_floor1_list(fc->list, fc->values);
305 305

  
306 306
    venc->nresidues = 1;
307
    venc->residues = av_malloc(sizeof(vorbis_enc_residue) * venc->nresidues);
307
    venc->residues  = av_malloc(sizeof(vorbis_enc_residue) * venc->nresidues);
308 308

  
309 309
    // single residue
310 310
    rc = &venc->residues[0];
311
    rc->type = 2;
312
    rc->begin = 0;
313
    rc->end = 1600;
314
    rc->partition_size = 32;
311
    rc->type            = 2;
312
    rc->begin           = 0;
313
    rc->end             = 1600;
314
    rc->partition_size  = 32;
315 315
    rc->classifications = 10;
316
    rc->classbook = 15;
317
    rc->books = av_malloc(sizeof(*rc->books) * rc->classifications);
316
    rc->classbook       = 15;
317
    rc->books           = av_malloc(sizeof(*rc->books) * rc->classifications);
318 318
    {
319 319
        static const int8_t a[10][8] = {
320 320
            { -1, -1, -1, -1, -1, -1, -1, -1, },
......
333 333
    ready_residue(rc, venc);
334 334

  
335 335
    venc->nmappings = 1;
336
    venc->mappings = av_malloc(sizeof(vorbis_enc_mapping) * venc->nmappings);
336
    venc->mappings  = av_malloc(sizeof(vorbis_enc_mapping) * venc->nmappings);
337 337

  
338 338
    // single mapping
339 339
    mc = &venc->mappings[0];
340 340
    mc->submaps = 1;
341
    mc->mux = av_malloc(sizeof(int) * venc->channels);
341
    mc->mux     = av_malloc(sizeof(int) * venc->channels);
342 342
    for (i = 0; i < venc->channels; i++)
343 343
        mc->mux[i] = 0;
344
    mc->floor = av_malloc(sizeof(int) * mc->submaps);
344
    mc->floor   = av_malloc(sizeof(int) * mc->submaps);
345 345
    mc->residue = av_malloc(sizeof(int) * mc->submaps);
346 346
    for (i = 0; i < mc->submaps; i++) {
347
        mc->floor[i] = 0;
347
        mc->floor[i]   = 0;
348 348
        mc->residue[i] = 0;
349 349
    }
350 350
    mc->coupling_steps = venc->channels == 2 ? 1 : 0;
351
    mc->magnitude = av_malloc(sizeof(int) * mc->coupling_steps);
352
    mc->angle = av_malloc(sizeof(int) * mc->coupling_steps);
351
    mc->magnitude      = av_malloc(sizeof(int) * mc->coupling_steps);
352
    mc->angle          = av_malloc(sizeof(int) * mc->coupling_steps);
353 353
    if (mc->coupling_steps) {
354 354
        mc->magnitude[0] = 0;
355
        mc->angle[0] = 1;
355
        mc->angle[0]     = 1;
356 356
    }
357 357

  
358 358
    venc->nmodes = 1;
359
    venc->modes = av_malloc(sizeof(vorbis_enc_mode) * venc->nmodes);
359
    venc->modes  = av_malloc(sizeof(vorbis_enc_mode) * venc->nmodes);
360 360

  
361 361
    // single mode
362 362
    venc->modes[0].blockflag = 0;
363
    venc->modes[0].mapping = 0;
363
    venc->modes[0].mapping   = 0;
364 364

  
365 365
    venc->have_saved = 0;
366
    venc->saved = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);
367
    venc->samples = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]));
368
    venc->floor = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);
369
    venc->coeffs = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);
366
    venc->saved      = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);
367
    venc->samples    = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]));
368
    venc->floor      = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);
369
    venc->coeffs     = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);
370 370

  
371 371
    venc->win[0] = ff_vorbis_vwin[venc->log2_blocksize[0] - 6];
372 372
    venc->win[1] = ff_vorbis_vwin[venc->log2_blocksize[1] - 6];
......
375 375
    ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0, 1.0);
376 376
}
377 377

  
378
static void put_float(PutBitContext * pb, float f)
378
static void put_float(PutBitContext *pb, float f)
379 379
{
380 380
    int exp, mant;
381 381
    uint32_t res = 0;
......
389 389
    put_bits(pb, 32, res);
390 390
}
391 391

  
392
static void put_codebook_header(PutBitContext * pb, vorbis_enc_codebook * cb)
392
static void put_codebook_header(PutBitContext *pb, vorbis_enc_codebook *cb)
393 393
{
394 394
    int i;
395 395
    int ordered = 0;
......
437 437

  
438 438
    put_bits(pb, 4, cb->lookup);
439 439
    if (cb->lookup) {
440
        int tmp = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);
440
        int tmp  = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);
441 441
        int bits = ilog(cb->quantlist[0]);
442 442

  
443 443
        for (i = 1; i < tmp; i++)
......
454 454
    }
455 455
}
456 456

  
457
static void put_floor_header(PutBitContext * pb, vorbis_enc_floor * fc)
457
static void put_floor_header(PutBitContext *pb, vorbis_enc_floor *fc)
458 458
{
459 459
    int i;
460 460

  
......
487 487
        put_bits(pb, fc->rangebits, fc->list[i].x);
488 488
}
489 489

  
490
static void put_residue_header(PutBitContext * pb, vorbis_enc_residue * rc)
490
static void put_residue_header(PutBitContext *pb, vorbis_enc_residue *rc)
491 491
{
492 492
    int i;
493 493

  
......
519 519
    }
520 520
}
521 521

  
522
static int put_main_header(vorbis_enc_context * venc, uint8_t ** out)
522
static int put_main_header(vorbis_enc_context *venc, uint8_t **out)
523 523
{
524 524
    int i;
525 525
    PutBitContext pb;
526
    uint8_t buffer[50000] = {0}, * p = buffer;
526
    uint8_t buffer[50000] = {0}, *p = buffer;
527 527
    int buffer_len = sizeof buffer;
528 528
    int len, hlens[3];
529 529

  
......
533 533
    for (i = 0; "vorbis"[i]; i++)
534 534
        put_bits(&pb, 8, "vorbis"[i]);
535 535
    put_bits(&pb, 32, 0); // version
536
    put_bits(&pb, 8, venc->channels);
536
    put_bits(&pb,  8, venc->channels);
537 537
    put_bits(&pb, 32, venc->sample_rate);
538 538
    put_bits(&pb, 32, 0); // bitrate
539 539
    put_bits(&pb, 32, 0); // bitrate
540 540
    put_bits(&pb, 32, 0); // bitrate
541
    put_bits(&pb, 4, venc->log2_blocksize[0]);
542
    put_bits(&pb, 4, venc->log2_blocksize[1]);
543
    put_bits(&pb, 1, 1); // framing
541
    put_bits(&pb,  4, venc->log2_blocksize[0]);
542
    put_bits(&pb,  4, venc->log2_blocksize[1]);
543
    put_bits(&pb,  1, 1); // framing
544 544

  
545 545
    flush_put_bits(&pb);
546 546
    hlens[0] = (put_bits_count(&pb) + 7) / 8;
......
554 554
        put_bits(&pb, 8, "vorbis"[i]);
555 555
    put_bits(&pb, 32, 0); // vendor length TODO
556 556
    put_bits(&pb, 32, 0); // amount of comments
557
    put_bits(&pb, 1, 1); // framing
557
    put_bits(&pb,  1, 1); // framing
558 558

  
559 559
    flush_put_bits(&pb);
560 560
    hlens[1] = (put_bits_count(&pb) + 7) / 8;
......
573 573
        put_codebook_header(&pb, &venc->codebooks[i]);
574 574

  
575 575
    // time domain, reserved, zero
576
    put_bits(&pb, 6, 0);
576
    put_bits(&pb,  6, 0);
577 577
    put_bits(&pb, 16, 0);
578 578

  
579 579
    // floors
......
589 589
    // mappings
590 590
    put_bits(&pb, 6, venc->nmappings - 1);
591 591
    for (i = 0; i < venc->nmappings; i++) {
592
        vorbis_enc_mapping * mc = &venc->mappings[i];
592
        vorbis_enc_mapping *mc = &venc->mappings[i];
593 593
        int j;
594 594
        put_bits(&pb, 16, 0); // mapping type
595 595

  
......
649 649
    return p - *out;
650 650
}
651 651

  
652
static float get_floor_average(vorbis_enc_floor * fc, float * coeffs, int i)
652
static float get_floor_average(vorbis_enc_floor * fc, float *coeffs, int i)
653 653
{
654 654
    int begin = fc->list[fc->list[FFMAX(i-1, 0)].sort].x;
655 655
    int end   = fc->list[fc->list[FFMIN(i+1, fc->values - 1)].sort].x;
......
661 661
    return average / (end - begin);
662 662
}
663 663

  
664
static void floor_fit(vorbis_enc_context * venc, vorbis_enc_floor * fc,
665
                      float * coeffs, uint_fast16_t * posts, int samples)
664
static void floor_fit(vorbis_enc_context *venc, vorbis_enc_floor *fc,
665
                      float *coeffs, uint_fast16_t *posts, int samples)
666 666
{
667 667
    int range = 255 / fc->multiplier + 1;
668 668
    int i;
669 669
    float tot_average = 0.;
670 670
    float averages[fc->values];
671
    for (i = 0; i < fc->values; i++){
671
    for (i = 0; i < fc->values; i++) {
672 672
        averages[i] = get_floor_average(fc, coeffs, i);
673 673
        tot_average += averages[i];
674 674
    }
......
676 676
    tot_average /= venc->quality;
677 677

  
678 678
    for (i = 0; i < fc->values; i++) {
679
        int position = fc->list[fc->list[i].sort].x;
679
        int position  = fc->list[fc->list[i].sort].x;
680 680
        float average = averages[i];
681 681
        int j;
682 682

  
......
693 693
    return y0 +  (x - x0) * (y1 - y0) / (x1 - x0);
694 694
}
695 695

  
696
static void floor_encode(vorbis_enc_context * venc, vorbis_enc_floor * fc,
697
                         PutBitContext * pb, uint_fast16_t * posts,
698
                         float * floor, int samples)
696
static void floor_encode(vorbis_enc_context *venc, vorbis_enc_floor *fc,
697
                         PutBitContext *pb, uint_fast16_t *posts,
698
                         float *floor, int samples)
699 699
{
700 700
    int range = 255 / fc->multiplier + 1;
701 701
    int coded[fc->values]; // first 2 values are unused
......
755 755
                        break;
756 756
                }
757 757
                assert(l != csub);
758
                cval |= l << cshift;
758
                cval   |= l << cshift;
759 759
                cshift += c->subclass;
760 760
            }
761 761
            put_codeword(pb, book, cval);
762 762
        }
763 763
        for (k = 0; k < c->dim; k++) {
764
            int book = c->books[cval & (csub-1)];
764
            int book  = c->books[cval & (csub-1)];
765 765
            int entry = coded[counter++];
766 766
            cval >>= c->subclass;
767 767
            if (book == -1)
......
772 772
        }
773 773
    }
774 774

  
775
    ff_vorbis_floor1_render_list(fc->list, fc->values, posts, coded, fc->multiplier, floor, samples);
775
    ff_vorbis_floor1_render_list(fc->list, fc->values, posts, coded,
776
                                 fc->multiplier, floor, samples);
776 777
}
777 778

  
778
static float * put_vector(vorbis_enc_codebook * book, PutBitContext * pb, float * num)
779
static float *put_vector(vorbis_enc_codebook *book, PutBitContext *pb,
780
                         float *num)
779 781
{
780 782
    int i, entry = -1;
781 783
    float distance = FLT_MAX;
......
788 790
        for (j = 0; j < book->ndimentions; j++)
789 791
            d -= vec[j] * num[j];
790 792
        if (distance > d) {
791
            entry = i;
793
            entry    = i;
792 794
            distance = d;
793 795
        }
794 796
    }
......
796 798
    return &book->dimentions[entry * book->ndimentions];
797 799
}
798 800

  
799
static void residue_encode(vorbis_enc_context * venc, vorbis_enc_residue * rc,
800
                           PutBitContext * pb, float * coeffs, int samples,
801
static void residue_encode(vorbis_enc_context *venc, vorbis_enc_residue *rc,
802
                           PutBitContext *pb, float *coeffs, int samples,
801 803
                           int real_ch)
802 804
{
803 805
    int pass, i, j, p, k;
804
    int psize = rc->partition_size;
806
    int psize      = rc->partition_size;
805 807
    int partitions = (rc->end - rc->begin) / psize;
806
    int channels = (rc->type == 2) ? 1 : real_ch;
808
    int channels   = (rc->type == 2) ? 1 : real_ch;
807 809
    int classes[channels][partitions];
808 810
    int classwords = venc->codebooks[rc->classbook].ndimentions;
809 811

  
......
840 842
                for (j = 0; j < channels; j++) {
841 843
                    int nbook = rc->books[classes[j][p]][pass];
842 844
                    vorbis_enc_codebook * book = &venc->codebooks[nbook];
843
                    float * buf = coeffs + samples*j + rc->begin + p*psize;
845
                    float *buf = coeffs + samples*j + rc->begin + p*psize;
844 846
                    if (nbook == -1)
845 847
                        continue;
846 848

  
......
849 851

  
850 852
                    if (rc->type == 0) {
851 853
                        for (k = 0; k < psize; k += book->ndimentions) {
852
                            float * a = put_vector(book, pb, &buf[k]);
854
                            float *a = put_vector(book, pb, &buf[k]);
853 855
                            int l;
854 856
                            for (l = 0; l < book->ndimentions; l++)
855 857
                                buf[k + l] -= a[l];
......
858 860
                        int s = rc->begin + p * psize, a1, b1;
859 861
                        a1 = (s % real_ch) * samples;
860 862
                        b1 =  s / real_ch;
861
                        s = real_ch * samples;
863
                        s  = real_ch * samples;
862 864
                        for (k = 0; k < psize; k += book->ndimentions) {
863 865
                            int dim, a2 = a1, b2 = b1;
864
                            float vec[book->ndimentions], * pv = vec;
866
                            float vec[book->ndimentions], *pv = vec;
865 867
                            for (dim = book->ndimentions; dim--; ) {
866 868
                                *pv++ = coeffs[a2 + b2];
867 869
                                if ((a2 += samples) == s) {
868
                                    a2=0;
870
                                    a2 = 0;
869 871
                                    b2++;
870 872
                                }
871 873
                            }
......
873 875
                            for (dim = book->ndimentions; dim--; ) {
874 876
                                coeffs[a1 + b1] -= *pv++;
875 877
                                if ((a1 += samples) == s) {
876
                                    a1=0;
878
                                    a1 = 0;
877 879
                                    b1++;
878 880
                                }
879 881
                            }
......
885 887
    }
886 888
}
887 889

  
888
static int apply_window_and_mdct(vorbis_enc_context * venc,
889
                                 signed short * audio, int samples)
890
static int apply_window_and_mdct(vorbis_enc_context *venc, signed short *audio,
891
                                 int samples)
890 892
{
891 893
    int i, j, channel;
892 894
    const float * win = venc->win[0];
......
897 899
    if (!venc->have_saved && !samples)
898 900
        return 0;
899 901

  
900
    if (venc->have_saved)
902
    if (venc->have_saved) {
901 903
        for (channel = 0; channel < venc->channels; channel++)
902
            memcpy(venc->samples + channel*window_len*2, venc->saved + channel*window_len, sizeof(float)*window_len);
903
    else
904
            memcpy(venc->samples + channel * window_len * 2,
905
                   venc->saved + channel * window_len, sizeof(float) * window_len);
906
    } else {
904 907
        for (channel = 0; channel < venc->channels; channel++)
905
            memset(venc->samples + channel*window_len*2, 0, sizeof(float)*window_len);
908
            memset(venc->samples + channel * window_len * 2, 0,
909
                   sizeof(float) * window_len);
910
    }
906 911

  
907 912
    if (samples) {
908 913
        for (channel = 0; channel < venc->channels; channel++) {
......
913 918
        }
914 919
    } else {
915 920
        for (channel = 0; channel < venc->channels; channel++)
916
            memset(venc->samples + channel*window_len*2 + window_len, 0, sizeof(float)*window_len);
921
            memset(venc->samples + channel * window_len * 2 + window_len,
922
                   0, sizeof(float) * window_len);
917 923
    }
918 924

  
919 925
    for (channel = 0; channel < venc->channels; channel++)
920
        ff_mdct_calc(&venc->mdct[0], venc->coeffs + channel*window_len, venc->samples + channel*window_len*2);
926
        ff_mdct_calc(&venc->mdct[0], venc->coeffs + channel * window_len,
927
                     venc->samples + channel * window_len * 2);
921 928

  
922 929
    if (samples) {
923 930
        for (channel = 0; channel < venc->channels; channel++) {
924
            float * offset = venc->saved + channel*window_len;
931
            float *offset = venc->saved + channel * window_len;
925 932
            j = channel;
926 933
            for (i = 0; i < samples; i++, j += venc->channels)
927 934
                offset[i] = -audio[j] / 32768. / n * win[i]; //FIXME find out why the sign has to be fliped
......
933 940
    return 1;
934 941
}
935 942

  
936
static av_cold int vorbis_encode_init(AVCodecContext * avccontext)
943
static av_cold int vorbis_encode_init(AVCodecContext *avccontext)
937 944
{
938
    vorbis_enc_context * venc = avccontext->priv_data;
945
    vorbis_enc_context *venc = avccontext->priv_data;
939 946

  
940 947
    if (avccontext->channels != 2) {
941 948
        av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n");
......
952 959

  
953 960
    avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata);
954 961

  
955
    avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1);
962
    avccontext->frame_size     = 1 << (venc->log2_blocksize[0] - 1);
956 963

  
957
    avccontext->coded_frame = avcodec_alloc_frame();
964
    avccontext->coded_frame            = avcodec_alloc_frame();
958 965
    avccontext->coded_frame->key_frame = 1;
959 966

  
960 967
    return 0;
961 968
}
962 969

  
963
static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * packets, int buf_size, void *data)
970
static int vorbis_encode_frame(AVCodecContext *avccontext,
971
                               unsigned char *packets,
972
                               int buf_size, void *data)
964 973
{
965
    vorbis_enc_context * venc = avccontext->priv_data;
966
    signed short * audio = data;
974
    vorbis_enc_context *venc = avccontext->priv_data;
975
    signed short *audio = data;
967 976
    int samples = data ? avccontext->frame_size : 0;
968
    vorbis_enc_mode * mode;
969
    vorbis_enc_mapping * mapping;
977
    vorbis_enc_mode *mode;
978
    vorbis_enc_mapping *mapping;
970 979
    PutBitContext pb;
971 980
    int i;
972 981

  
......
980 989

  
981 990
    put_bits(&pb, ilog(venc->nmodes - 1), 0); // 0 bits, the mode
982 991

  
983
    mode = &venc->modes[0];
992
    mode    = &venc->modes[0];
984 993
    mapping = &venc->mappings[mode->mapping];
985 994
    if (mode->blockflag) {
986 995
        put_bits(&pb, 1, 0);
......
988 997
    }
989 998

  
990 999
    for (i = 0; i < venc->channels; i++) {
991
        vorbis_enc_floor * fc = &venc->floors[mapping->floor[mapping->mux[i]]];
1000
        vorbis_enc_floor *fc = &venc->floors[mapping->floor[mapping->mux[i]]];
992 1001
        uint_fast16_t posts[fc->values];
993 1002
        floor_fit(venc, fc, &venc->coeffs[i * samples], posts, samples);
994 1003
        floor_encode(venc, fc, &pb, posts, &venc->floor[i * samples], samples);
......
998 1007
        venc->coeffs[i] /= venc->floor[i];
999 1008

  
1000 1009
    for (i = 0; i < mapping->coupling_steps; i++) {
1001
        float * mag = venc->coeffs + mapping->magnitude[i] * samples;
1002
        float * ang = venc->coeffs + mapping->angle[i] * samples;
1010
        float *mag = venc->coeffs + mapping->magnitude[i] * samples;
1011
        float *ang = venc->coeffs + mapping->angle[i]     * samples;
1003 1012
        int j;
1004 1013
        for (j = 0; j < samples; j++) {
1005 1014
            float a = ang[j];
......
1011 1020
        }
1012 1021
    }
1013 1022

  
1014
    residue_encode(venc, &venc->residues[mapping->residue[mapping->mux[0]]], &pb, venc->coeffs, samples, venc->channels);
1023
    residue_encode(venc, &venc->residues[mapping->residue[mapping->mux[0]]],
1024
                   &pb, venc->coeffs, samples, venc->channels);
1015 1025

  
1016 1026
    avccontext->coded_frame->pts = venc->sample_count;
1017 1027
    venc->sample_count += avccontext->frame_size;
......
1020 1030
}
1021 1031

  
1022 1032

  
1023
static av_cold int vorbis_encode_close(AVCodecContext * avccontext)
1033
static av_cold int vorbis_encode_close(AVCodecContext *avccontext)
1024 1034
{
1025
    vorbis_enc_context * venc = avccontext->priv_data;
1035
    vorbis_enc_context *venc = avccontext->priv_data;
1026 1036
    int i;
1027 1037

  
1028 1038
    if (venc->codebooks)

Also available in: Unified diff