vorbisenc.c 37.4 KB
Newer Older
Oded Shimon's avatar
Oded Shimon committed
1 2 3
/*
 * copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
 *
4 5 6
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
Oded Shimon's avatar
Oded Shimon committed
7 8
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
Oded Shimon's avatar
Oded Shimon committed
10
 *
11
 * FFmpeg is distributed in the hope that it will be useful,
Oded Shimon's avatar
Oded Shimon committed
12 13 14 15 16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with FFmpeg; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Oded Shimon's avatar
Oded Shimon committed
19 20 21
 */

/**
22
 * @file
Oded Shimon's avatar
Oded Shimon committed
23 24 25 26
 * Native Vorbis encoder.
 * @author Oded Shimon <ods15@ods15.dyndns.org>
 */

27
#include <float.h>
Oded Shimon's avatar
Oded Shimon committed
28
#include "avcodec.h"
29
#include "internal.h"
30
#include "fft.h"
31
#include "vorbis.h"
32
#include "vorbis_enc_data.h"
33

34
#define BITSTREAM_WRITER_LE
35
#include "put_bits.h"
36

Oded Shimon's avatar
Oded Shimon committed
37 38 39
#undef NDEBUG
#include <assert.h>

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

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

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

typedef struct {
73 74 75 76 77 78
    int type;
    int begin;
    int end;
    int partition_size;
    int classifications;
    int classbook;
79
    int8_t (*books)[8];
80
    float (*maxes)[2];
81
} vorbis_enc_residue;
82 83

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

93 94 95
typedef struct {
    int blockflag;
    int mapping;
96
} vorbis_enc_mode;
97

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

111
    int ncodebooks;
112
    vorbis_enc_codebook *codebooks;
113 114

    int nfloors;
115
    vorbis_enc_floor *floors;
116 117

    int nresidues;
118
    vorbis_enc_residue *residues;
119 120

    int nmappings;
121
    vorbis_enc_mapping *mappings;
122 123

    int nmodes;
124
    vorbis_enc_mode *modes;
125

126
    int64_t next_pts;
127
} vorbis_enc_context;
Oded Shimon's avatar
Oded Shimon committed
128

Måns Rullgård's avatar
Måns Rullgård committed
129 130 131 132 133 134 135 136 137 138 139
#define MAX_CHANNELS     2
#define MAX_CODEBOOK_DIM 8

#define MAX_FLOOR_CLASS_DIM  4
#define NUM_FLOOR_PARTITIONS 8
#define MAX_FLOOR_VALUES     (MAX_FLOOR_CLASS_DIM*NUM_FLOOR_PARTITIONS+2)

#define RESIDUE_SIZE           1600
#define RESIDUE_PART_SIZE      32
#define NUM_RESIDUE_PARTITIONS (RESIDUE_SIZE/RESIDUE_PART_SIZE)

140 141
static inline int put_codeword(PutBitContext *pb, vorbis_enc_codebook *cb,
                               int entry)
142
{
143 144 145
    assert(entry >= 0);
    assert(entry < cb->nentries);
    assert(cb->lens[entry]);
146 147
    if (pb->size_in_bits - put_bits_count(pb) < cb->lens[entry])
        return AVERROR(EINVAL);
148
    put_bits(pb, cb->lens[entry], cb->codewords[entry]);
149
    return 0;
150 151
}

152
static int cb_lookup_vals(int lookup, int dimensions, int entries)
153 154
{
    if (lookup == 1)
155
        return ff_vorbis_nth_root(entries, dimensions);
156
    else if (lookup == 2)
157
        return dimensions *entries;
158 159 160
    return 0;
}

161
static int ready_codebook(vorbis_enc_codebook *cb)
162
{
163 164
    int i;

165
    ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries);
166

167
    if (!cb->lookup) {
168
        cb->pow2 = cb->dimensions = NULL;
169
    } else {
170 171
        int vals = cb_lookup_vals(cb->lookup, cb->ndimensions, cb->nentries);
        cb->dimensions = av_malloc(sizeof(float) * cb->nentries * cb->ndimensions);
172
        cb->pow2 = av_mallocz(sizeof(float) * cb->nentries);
173
        if (!cb->dimensions || !cb->pow2)
174
            return AVERROR(ENOMEM);
175 176 177 178
        for (i = 0; i < cb->nentries; i++) {
            float last = 0;
            int j;
            int div = 1;
179
            for (j = 0; j < cb->ndimensions; j++) {
180
                int off;
181 182 183
                if (cb->lookup == 1)
                    off = (i / div) % vals; // lookup type 1
                else
184
                    off = i * cb->ndimensions + j; // lookup type 2
185

186
                cb->dimensions[i * cb->ndimensions + j] = last + cb->min + cb->quantlist[off] * cb->delta;
187
                if (cb->seq_p)
188 189
                    last = cb->dimensions[i * cb->ndimensions + j];
                cb->pow2[i] += cb->dimensions[i * cb->ndimensions + j] * cb->dimensions[i * cb->ndimensions + j];
190 191
                div *= vals;
            }
192
            cb->pow2[i] /= 2.;
193 194
        }
    }
195
    return 0;
196 197
}

198
static int ready_residue(vorbis_enc_residue *rc, vorbis_enc_context *venc)
199
{
200 201 202
    int i;
    assert(rc->type == 2);
    rc->maxes = av_mallocz(sizeof(float[2]) * rc->classifications);
203 204
    if (!rc->maxes)
        return AVERROR(ENOMEM);
205 206
    for (i = 0; i < rc->classifications; i++) {
        int j;
207
        vorbis_enc_codebook * cb;
208
        for (j = 0; j < 8; j++)
209 210
            if (rc->books[i][j] != -1)
                break;
211 212
        if (j == 8) // zero
            continue;
213
        cb = &venc->codebooks[rc->books[i][j]];
214
        assert(cb->ndimensions >= 2);
215 216 217 218
        assert(cb->lookup);

        for (j = 0; j < cb->nentries; j++) {
            float a;
219 220
            if (!cb->lens[j])
                continue;
221
            a = fabs(cb->dimensions[j * cb->ndimensions]);
222 223
            if (a > rc->maxes[i][0])
                rc->maxes[i][0] = a;
224
            a = fabs(cb->dimensions[j * cb->ndimensions + 1]);
225 226
            if (a > rc->maxes[i][1])
                rc->maxes[i][1] = a;
227 228 229 230 231 232 233
        }
    }
    // small bias
    for (i = 0; i < rc->classifications; i++) {
        rc->maxes[i][0] += 0.8;
        rc->maxes[i][1] += 0.8;
    }
234
    return 0;
235 236
}

237
static int create_vorbis_context(vorbis_enc_context *venc,
238
                                 AVCodecContext *avctx)
239
{
240 241 242
    vorbis_enc_floor   *fc;
    vorbis_enc_residue *rc;
    vorbis_enc_mapping *mc;
243
    int i, book, ret;
244

245 246
    venc->channels    = avctx->channels;
    venc->sample_rate = avctx->sample_rate;
247
    venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11;
248

249
    venc->ncodebooks = FF_ARRAY_ELEMS(cvectors);
250
    venc->codebooks  = av_malloc(sizeof(vorbis_enc_codebook) * venc->ncodebooks);
251 252
    if (!venc->codebooks)
        return AVERROR(ENOMEM);
253

254
    // codebook 0..14 - floor1 book, values 0..255
255 256 257
    // codebook 15 residue masterbook
    // codebook 16..29 residue
    for (book = 0; book < venc->ncodebooks; book++) {
258
        vorbis_enc_codebook *cb = &venc->codebooks[book];
259
        int vals;
260
        cb->ndimensions = cvectors[book].dim;
261 262 263 264 265
        cb->nentries    = cvectors[book].real_len;
        cb->min         = cvectors[book].min;
        cb->delta       = cvectors[book].delta;
        cb->lookup      = cvectors[book].lookup;
        cb->seq_p       = 0;
266

267
        cb->lens      = av_malloc(sizeof(uint8_t)  * cb->nentries);
268
        cb->codewords = av_malloc(sizeof(uint32_t) * cb->nentries);
269 270
        if (!cb->lens || !cb->codewords)
            return AVERROR(ENOMEM);
271 272 273
        memcpy(cb->lens, cvectors[book].clens, cvectors[book].len);
        memset(cb->lens + cvectors[book].len, 0, cb->nentries - cvectors[book].len);

274
        if (cb->lookup) {
275
            vals = cb_lookup_vals(cb->lookup, cb->ndimensions, cb->nentries);
276
            cb->quantlist = av_malloc(sizeof(int) * vals);
277 278
            if (!cb->quantlist)
                return AVERROR(ENOMEM);
279 280
            for (i = 0; i < vals; i++)
                cb->quantlist[i] = cvectors[book].quant[i];
281 282 283
        } else {
            cb->quantlist = NULL;
        }
284 285
        if ((ret = ready_codebook(cb)) < 0)
            return ret;
286
    }
287

288
    venc->nfloors = 1;
289
    venc->floors  = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors);
290 291
    if (!venc->floors)
        return AVERROR(ENOMEM);
292

293 294
    // just 1 floor
    fc = &venc->floors[0];
Måns Rullgård's avatar
Måns Rullgård committed
295
    fc->partitions         = NUM_FLOOR_PARTITIONS;
296
    fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions);
297 298
    if (!fc->partition_to_class)
        return AVERROR(ENOMEM);
299
    fc->nclasses           = 0;
300
    for (i = 0; i < fc->partitions; i++) {
301
        static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4};
302 303 304 305
        fc->partition_to_class[i] = a[i];
        fc->nclasses = FFMAX(fc->nclasses, fc->partition_to_class[i]);
    }
    fc->nclasses++;
306
    fc->classes = av_malloc(sizeof(vorbis_enc_floor_class) * fc->nclasses);
307 308
    if (!fc->classes)
        return AVERROR(ENOMEM);
309
    for (i = 0; i < fc->nclasses; i++) {
310
        vorbis_enc_floor_class * c = &fc->classes[i];
311
        int j, books;
312 313
        c->dim        = floor_classes[i].dim;
        c->subclass   = floor_classes[i].subclass;
314
        c->masterbook = floor_classes[i].masterbook;
315 316
        books         = (1 << c->subclass);
        c->books      = av_malloc(sizeof(int) * books);
317 318
        if (!c->books)
            return AVERROR(ENOMEM);
319 320
        for (j = 0; j < books; j++)
            c->books[j] = floor_classes[i].nbooks[j];
321
    }
322
    fc->multiplier = 2;
323
    fc->rangebits  = venc->log2_blocksize[0] - 1;
324 325 326 327 328

    fc->values = 2;
    for (i = 0; i < fc->partitions; i++)
        fc->values += fc->classes[fc->partition_to_class[i]].dim;

329
    fc->list = av_malloc(sizeof(vorbis_floor1_entry) * fc->values);
330 331
    if (!fc->list)
        return AVERROR(ENOMEM);
332 333
    fc->list[0].x = 0;
    fc->list[1].x = 1 << fc->rangebits;
334
    for (i = 2; i < fc->values; i++) {
335 336 337 338 339
        static const int a[] = {
             93, 23,372,  6, 46,186,750, 14, 33, 65,
            130,260,556,  3, 10, 18, 28, 39, 55, 79,
            111,158,220,312,464,650,850
        };
340
        fc->list[i].x = a[i - 2];
341
    }
342
    if (ff_vorbis_ready_floor1_list(avctx, fc->list, fc->values))
343
        return AVERROR_BUG;
344 345

    venc->nresidues = 1;
346
    venc->residues  = av_malloc(sizeof(vorbis_enc_residue) * venc->nresidues);
347 348
    if (!venc->residues)
        return AVERROR(ENOMEM);
349

350 351
    // single residue
    rc = &venc->residues[0];
352 353 354 355
    rc->type            = 2;
    rc->begin           = 0;
    rc->end             = 1600;
    rc->partition_size  = 32;
356
    rc->classifications = 10;
357 358
    rc->classbook       = 15;
    rc->books           = av_malloc(sizeof(*rc->books) * rc->classifications);
359 360
    if (!rc->books)
        return AVERROR(ENOMEM);
361 362
    {
        static const int8_t a[10][8] = {
363 364 365 366 367 368 369 370 371 372 373
            { -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, },
        };
374
        memcpy(rc->books, a, sizeof a);
375
    }
376 377
    if ((ret = ready_residue(rc, venc)) < 0)
        return ret;
378

379
    venc->nmappings = 1;
380
    venc->mappings  = av_malloc(sizeof(vorbis_enc_mapping) * venc->nmappings);
381 382
    if (!venc->mappings)
        return AVERROR(ENOMEM);
383

384 385 386
    // single mapping
    mc = &venc->mappings[0];
    mc->submaps = 1;
387
    mc->mux     = av_malloc(sizeof(int) * venc->channels);
388 389
    if (!mc->mux)
        return AVERROR(ENOMEM);
390 391
    for (i = 0; i < venc->channels; i++)
        mc->mux[i] = 0;
392
    mc->floor   = av_malloc(sizeof(int) * mc->submaps);
393
    mc->residue = av_malloc(sizeof(int) * mc->submaps);
394 395
    if (!mc->floor || !mc->residue)
        return AVERROR(ENOMEM);
396
    for (i = 0; i < mc->submaps; i++) {
397
        mc->floor[i]   = 0;
398 399
        mc->residue[i] = 0;
    }
400
    mc->coupling_steps = venc->channels == 2 ? 1 : 0;
401 402
    mc->magnitude      = av_malloc(sizeof(int) * mc->coupling_steps);
    mc->angle          = av_malloc(sizeof(int) * mc->coupling_steps);
403 404
    if (!mc->magnitude || !mc->angle)
        return AVERROR(ENOMEM);
405 406
    if (mc->coupling_steps) {
        mc->magnitude[0] = 0;
407
        mc->angle[0]     = 1;
408
    }
409

410
    venc->nmodes = 1;
411
    venc->modes  = av_malloc(sizeof(vorbis_enc_mode) * venc->nmodes);
412 413
    if (!venc->modes)
        return AVERROR(ENOMEM);
414 415 416

    // single mode
    venc->modes[0].blockflag = 0;
417
    venc->modes[0].mapping   = 0;
418

419
    venc->have_saved = 0;
420 421 422 423
    venc->saved      = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);
    venc->samples    = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]));
    venc->floor      = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);
    venc->coeffs     = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);
424 425
    if (!venc->saved || !venc->samples || !venc->floor || !venc->coeffs)
        return AVERROR(ENOMEM);
426

427 428
    venc->win[0] = ff_vorbis_vwin[venc->log2_blocksize[0] - 6];
    venc->win[1] = ff_vorbis_vwin[venc->log2_blocksize[1] - 6];
429

430 431 432 433 434 435
    if ((ret = ff_mdct_init(&venc->mdct[0], venc->log2_blocksize[0], 0, 1.0)) < 0)
        return ret;
    if ((ret = ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0, 1.0)) < 0)
        return ret;

    return 0;
436 437
}

438
static void put_float(PutBitContext *pb, float f)
439
{
440 441 442 443
    int exp, mant;
    uint32_t res = 0;
    mant = (int)ldexp(frexp(f, &exp), 20);
    exp += 788 - 20;
444
    if (mant < 0) {
445
        res |= (1U << 31);
446 447
        mant = -mant;
    }
448
    res |= mant | (exp << 21);
449
    put_bits32(pb, res);
450 451
}

452
static void put_codebook_header(PutBitContext *pb, vorbis_enc_codebook *cb)
453
{
454 455 456 457
    int i;
    int ordered = 0;

    put_bits(pb, 24, 0x564342); //magic
458
    put_bits(pb, 16, cb->ndimensions);
459 460
    put_bits(pb, 24, cb->nentries);

461
    for (i = 1; i < cb->nentries; i++)
462 463
        if (cb->lens[i] < cb->lens[i-1])
            break;
464 465
    if (i == cb->nentries)
        ordered = 1;
466 467 468

    put_bits(pb, 1, ordered);
    if (ordered) {
469
        int len = cb->lens[0];
470
        put_bits(pb, 5, len - 1);
471 472
        i = 0;
        while (i < cb->nentries) {
473
            int j;
474
            for (j = 0; j+i < cb->nentries; j++)
475 476
                if (cb->lens[j+i] != len)
                    break;
477
            put_bits(pb, ilog(cb->nentries - i), j);
478 479 480 481 482
            i += j;
            len++;
        }
    } else {
        int sparse = 0;
483
        for (i = 0; i < cb->nentries; i++)
484 485
            if (!cb->lens[i])
                break;
486 487
        if (i != cb->nentries)
            sparse = 1;
488 489 490
        put_bits(pb, 1, sparse);

        for (i = 0; i < cb->nentries; i++) {
491 492 493 494
            if (sparse)
                put_bits(pb, 1, !!cb->lens[i]);
            if (cb->lens[i])
                put_bits(pb, 5, cb->lens[i] - 1);
495 496 497 498 499
        }
    }

    put_bits(pb, 4, cb->lookup);
    if (cb->lookup) {
500
        int tmp  = cb_lookup_vals(cb->lookup, cb->ndimensions, cb->nentries);
501
        int bits = ilog(cb->quantlist[0]);
502

503 504
        for (i = 1; i < tmp; i++)
            bits = FFMAX(bits, ilog(cb->quantlist[i]));
505

506 507
        put_float(pb, cb->min);
        put_float(pb, cb->delta);
508

509 510
        put_bits(pb, 4, bits - 1);
        put_bits(pb, 1, cb->seq_p);
511

512 513
        for (i = 0; i < tmp; i++)
            put_bits(pb, bits, cb->quantlist[i]);
514 515 516
    }
}

517
static void put_floor_header(PutBitContext *pb, vorbis_enc_floor *fc)
518
{
519 520 521 522 523 524
    int i;

    put_bits(pb, 16, 1); // type, only floor1 is supported

    put_bits(pb, 5, fc->partitions);

525 526
    for (i = 0; i < fc->partitions; i++)
        put_bits(pb, 4, fc->partition_to_class[i]);
527 528 529 530 531 532 533

    for (i = 0; i < fc->nclasses; i++) {
        int j, books;

        put_bits(pb, 3, fc->classes[i].dim - 1);
        put_bits(pb, 2, fc->classes[i].subclass);

534 535
        if (fc->classes[i].subclass)
            put_bits(pb, 8, fc->classes[i].masterbook);
536 537 538

        books = (1 << fc->classes[i].subclass);

539 540
        for (j = 0; j < books; j++)
            put_bits(pb, 8, fc->classes[i].books[j] + 1);
541 542 543 544 545
    }

    put_bits(pb, 2, fc->multiplier - 1);
    put_bits(pb, 4, fc->rangebits);

546 547
    for (i = 2; i < fc->values; i++)
        put_bits(pb, fc->rangebits, fc->list[i].x);
548 549
}

550
static void put_residue_header(PutBitContext *pb, vorbis_enc_residue *rc)
551
{
552 553 554 555 556 557 558
    int i;

    put_bits(pb, 16, rc->type);

    put_bits(pb, 24, rc->begin);
    put_bits(pb, 24, rc->end);
    put_bits(pb, 24, rc->partition_size - 1);
559
    put_bits(pb, 6, rc->classifications - 1);
560 561 562 563
    put_bits(pb, 8, rc->classbook);

    for (i = 0; i < rc->classifications; i++) {
        int j, tmp = 0;
564 565
        for (j = 0; j < 8; j++)
            tmp |= (rc->books[i][j] != -1) << j;
566 567 568 569

        put_bits(pb, 3, tmp & 7);
        put_bits(pb, 1, tmp > 7);

570 571
        if (tmp > 7)
            put_bits(pb, 5, tmp >> 3);
572 573 574 575 576
    }

    for (i = 0; i < rc->classifications; i++) {
        int j;
        for (j = 0; j < 8; j++)
577
            if (rc->books[i][j] != -1)
578 579
                put_bits(pb, 8, rc->books[i][j]);
    }
580 581
}

582
static int put_main_header(vorbis_enc_context *venc, uint8_t **out)
583
{
584
    int i;
585
    PutBitContext pb;
586
    uint8_t buffer[50000] = {0}, *p = buffer;
587 588 589 590 591 592
    int buffer_len = sizeof buffer;
    int len, hlens[3];

    // identification header
    init_put_bits(&pb, p, buffer_len);
    put_bits(&pb, 8, 1); //magic
593 594
    for (i = 0; "vorbis"[i]; i++)
        put_bits(&pb, 8, "vorbis"[i]);
595
    put_bits32(&pb, 0); // version
596
    put_bits(&pb,  8, venc->channels);
597 598 599 600
    put_bits32(&pb, venc->sample_rate);
    put_bits32(&pb, 0); // bitrate
    put_bits32(&pb, 0); // bitrate
    put_bits32(&pb, 0); // bitrate
601 602 603
    put_bits(&pb,  4, venc->log2_blocksize[0]);
    put_bits(&pb,  4, venc->log2_blocksize[1]);
    put_bits(&pb,  1, 1); // framing
604 605

    flush_put_bits(&pb);
606
    hlens[0] = put_bits_count(&pb) >> 3;
607 608 609 610 611 612
    buffer_len -= hlens[0];
    p += hlens[0];

    // comment header
    init_put_bits(&pb, p, buffer_len);
    put_bits(&pb, 8, 3); //magic
613 614
    for (i = 0; "vorbis"[i]; i++)
        put_bits(&pb, 8, "vorbis"[i]);
615 616
    put_bits32(&pb, 0); // vendor length TODO
    put_bits32(&pb, 0); // amount of comments
617
    put_bits(&pb,  1, 1); // framing
618 619

    flush_put_bits(&pb);
620
    hlens[1] = put_bits_count(&pb) >> 3;
621 622 623 624 625 626
    buffer_len -= hlens[1];
    p += hlens[1];

    // setup header
    init_put_bits(&pb, p, buffer_len);
    put_bits(&pb, 8, 5); //magic
627 628
    for (i = 0; "vorbis"[i]; i++)
        put_bits(&pb, 8, "vorbis"[i]);
629 630 631

    // codebooks
    put_bits(&pb, 8, venc->ncodebooks - 1);
632 633
    for (i = 0; i < venc->ncodebooks; i++)
        put_codebook_header(&pb, &venc->codebooks[i]);
634

635
    // time domain, reserved, zero
636
    put_bits(&pb,  6, 0);
637 638 639 640
    put_bits(&pb, 16, 0);

    // floors
    put_bits(&pb, 6, venc->nfloors - 1);
641 642
    for (i = 0; i < venc->nfloors; i++)
        put_floor_header(&pb, &venc->floors[i]);
643 644 645

    // residues
    put_bits(&pb, 6, venc->nresidues - 1);
646 647
    for (i = 0; i < venc->nresidues; i++)
        put_residue_header(&pb, &venc->residues[i]);
648 649 650 651

    // mappings
    put_bits(&pb, 6, venc->nmappings - 1);
    for (i = 0; i < venc->nmappings; i++) {
652
        vorbis_enc_mapping *mc = &venc->mappings[i];
653 654 655 656
        int j;
        put_bits(&pb, 16, 0); // mapping type

        put_bits(&pb, 1, mc->submaps > 1);
657 658
        if (mc->submaps > 1)
            put_bits(&pb, 4, mc->submaps - 1);
659

660 661 662 663 664 665 666 667
        put_bits(&pb, 1, !!mc->coupling_steps);
        if (mc->coupling_steps) {
            put_bits(&pb, 8, mc->coupling_steps - 1);
            for (j = 0; j < mc->coupling_steps; j++) {
                put_bits(&pb, ilog(venc->channels - 1), mc->magnitude[j]);
                put_bits(&pb, ilog(venc->channels - 1), mc->angle[j]);
            }
        }
668 669 670

        put_bits(&pb, 2, 0); // reserved

671 672 673
        if (mc->submaps > 1)
            for (j = 0; j < venc->channels; j++)
                put_bits(&pb, 4, mc->mux[j]);
674 675 676 677 678 679

        for (j = 0; j < mc->submaps; j++) {
            put_bits(&pb, 8, 0); // reserved time configuration
            put_bits(&pb, 8, mc->floor[j]);
            put_bits(&pb, 8, mc->residue[j]);
        }
680
    }
681

682 683 684 685 686 687 688 689 690
    // modes
    put_bits(&pb, 6, venc->nmodes - 1);
    for (i = 0; i < venc->nmodes; i++) {
        put_bits(&pb, 1, venc->modes[i].blockflag);
        put_bits(&pb, 16, 0); // reserved window type
        put_bits(&pb, 16, 0); // reserved transform type
        put_bits(&pb, 8, venc->modes[i].mapping);
    }

691 692
    put_bits(&pb, 1, 1); // framing

693
    flush_put_bits(&pb);
694
    hlens[2] = put_bits_count(&pb) >> 3;
695 696 697

    len = hlens[0] + hlens[1] + hlens[2];
    p = *out = av_mallocz(64 + len + len/255);
698 699
    if (!p)
        return AVERROR(ENOMEM);
700 701 702 703 704 705 706 707 708 709

    *p++ = 2;
    p += av_xiphlacing(p, hlens[0]);
    p += av_xiphlacing(p, hlens[1]);
    buffer_len = 0;
    for (i = 0; i < 3; i++) {
        memcpy(p, buffer + buffer_len, hlens[i]);
        p += hlens[i];
        buffer_len += hlens[i];
    }
710

711
    return p - *out;
712 713
}

714
static float get_floor_average(vorbis_enc_floor * fc, float *coeffs, int i)
715
{
716 717 718 719 720
    int begin = fc->list[fc->list[FFMAX(i-1, 0)].sort].x;
    int end   = fc->list[fc->list[FFMIN(i+1, fc->values - 1)].sort].x;
    int j;
    float average = 0;

721 722
    for (j = begin; j < end; j++)
        average += fabs(coeffs[j]);
723 724 725
    return average / (end - begin);
}

726
static void floor_fit(vorbis_enc_context *venc, vorbis_enc_floor *fc,
727
                      float *coeffs, uint16_t *posts, int samples)
728
{
729 730
    int range = 255 / fc->multiplier + 1;
    int i;
731
    float tot_average = 0.;
Måns Rullgård's avatar
Måns Rullgård committed
732
    float averages[MAX_FLOOR_VALUES];
733
    for (i = 0; i < fc->values; i++) {
734 735 736
        averages[i] = get_floor_average(fc, coeffs, i);
        tot_average += averages[i];
    }
737
    tot_average /= fc->values;
738
    tot_average /= venc->quality;
739

740
    for (i = 0; i < fc->values; i++) {
741
        int position  = fc->list[fc->list[i].sort].x;
742
        float average = averages[i];
743 744
        int j;

745
        average = sqrt(tot_average * average) * pow(1.25f, position*0.005f); // MAGIC!
746
        for (j = 0; j < range - 1; j++)
747 748
            if (ff_vorbis_floor1_inverse_db_table[j * fc->multiplier] > average)
                break;
749 750 751 752
        posts[fc->list[i].sort] = j;
    }
}

753 754
static int render_point(int x0, int y0, int x1, int y1, int x)
{
755 756 757
    return y0 +  (x - x0) * (y1 - y0) / (x1 - x0);
}

758 759 760
static int floor_encode(vorbis_enc_context *venc, vorbis_enc_floor *fc,
                        PutBitContext *pb, uint16_t *posts,
                        float *floor, int samples)
761
{
762
    int range = 255 / fc->multiplier + 1;
Måns Rullgård's avatar
Måns Rullgård committed
763
    int coded[MAX_FLOOR_VALUES]; // first 2 values are unused
764 765
    int i, counter;

766 767
    if (pb->size_in_bits - put_bits_count(pb) < 1 + 2 * ilog(range - 1))
        return AVERROR(EINVAL);
768
    put_bits(pb, 1, 1); // non zero
769 770
    put_bits(pb, ilog(range - 1), posts[0]);
    put_bits(pb, ilog(range - 1), posts[1]);
771
    coded[0] = coded[1] = 1;
772 773 774 775 776 777 778

    for (i = 2; i < fc->values; i++) {
        int predicted = render_point(fc->list[fc->list[i].low].x,
                                     posts[fc->list[i].low],
                                     fc->list[fc->list[i].high].x,
                                     posts[fc->list[i].high],
                                     fc->list[i].x);
779
        int highroom = range - predicted;
780 781 782 783 784
        int lowroom = predicted;
        int room = FFMIN(highroom, lowroom);
        if (predicted == posts[i]) {
            coded[i] = 0; // must be used later as flag!
            continue;
785
        } else {
786 787 788 789
            if (!coded[fc->list[i].low ])
                coded[fc->list[i].low ] = -1;
            if (!coded[fc->list[i].high])
                coded[fc->list[i].high] = -1;
790 791
        }
        if (posts[i] > predicted) {
792 793 794 795
            if (posts[i] - predicted > room)
                coded[i] = posts[i] - predicted + lowroom;
            else
                coded[i] = (posts[i] - predicted) << 1;
796
        } else {
797 798 799 800
            if (predicted - posts[i] > room)
                coded[i] = predicted - posts[i] + highroom - 1;
            else
                coded[i] = ((predicted - posts[i]) << 1) - 1;
801 802 803 804 805
        }
    }

    counter = 2;
    for (i = 0; i < fc->partitions; i++) {
806
        vorbis_enc_floor_class * c = &fc->classes[fc->partition_to_class[i]];
807 808
        int k, cval = 0, csub = 1<<c->subclass;
        if (c->subclass) {
809
            vorbis_enc_codebook * book = &venc->codebooks[c->masterbook];
810 811 812 813 814
            int cshift = 0;
            for (k = 0; k < c->dim; k++) {
                int l;
                for (l = 0; l < csub; l++) {
                    int maxval = 1;
815 816
                    if (c->books[l] != -1)
                        maxval = venc->codebooks[c->books[l]].nentries;
Diego Biurrun's avatar
Diego Biurrun committed
817
                    // coded could be -1, but this still works, cause that is 0
818 819
                    if (coded[counter + k] < maxval)
                        break;
820 821
                }
                assert(l != csub);
822
                cval   |= l << cshift;
823 824
                cshift += c->subclass;
            }
825 826
            if (put_codeword(pb, book, cval))
                return AVERROR(EINVAL);
827
        }
828
        for (k = 0; k < c->dim; k++) {
829
            int book  = c->books[cval & (csub-1)];
830
            int entry = coded[counter++];
831
            cval >>= c->subclass;
832 833 834 835
            if (book == -1)
                continue;
            if (entry == -1)
                entry = 0;
836 837
            if (put_codeword(pb, &venc->codebooks[book], entry))
                return AVERROR(EINVAL);
838 839 840
        }
    }

841 842
    ff_vorbis_floor1_render_list(fc->list, fc->values, posts, coded,
                                 fc->multiplier, floor, samples);
843 844

    return 0;
845 846
}

847 848
static float *put_vector(vorbis_enc_codebook *book, PutBitContext *pb,
                         float *num)
849
{
850 851
    int i, entry = -1;
    float distance = FLT_MAX;
852
    assert(book->dimensions);
853
    for (i = 0; i < book->nentries; i++) {
854
        float * vec = book->dimensions + i * book->ndimensions, d = book->pow2[i];
855
        int j;
856 857
        if (!book->lens[i])
            continue;
858
        for (j = 0; j < book->ndimensions; j++)
859
            d -= vec[j] * num[j];
860
        if (distance > d) {
861
            entry    = i;
862 863 864
            distance = d;
        }
    }
865 866
    if (put_codeword(pb, book, entry))
        return NULL;
867
    return &book->dimensions[entry * book->ndimensions];
868
}
Oded Shimon's avatar
Oded Shimon committed
869

870 871 872
static int residue_encode(vorbis_enc_context *venc, vorbis_enc_residue *rc,
                          PutBitContext *pb, float *coeffs, int samples,
                          int real_ch)
873
{
874
    int pass, i, j, p, k;
875
    int psize      = rc->partition_size;
876
    int partitions = (rc->end - rc->begin) / psize;
877
    int channels   = (rc->type == 2) ? 1 : real_ch;
Måns Rullgård's avatar
Måns Rullgård committed
878
    int classes[MAX_CHANNELS][NUM_RESIDUE_PARTITIONS];
879
    int classwords = venc->codebooks[rc->classbook].ndimensions;
880

881 882 883 884 885 886
    assert(rc->type == 2);
    assert(real_ch == 2);
    for (p = 0; p < partitions; p++) {
        float max1 = 0., max2 = 0.;
        int s = rc->begin + p * psize;
        for (k = s; k < s + psize; k += 2) {
887 888
            max1 = FFMAX(max1, fabs(coeffs[          k / real_ch]));
            max2 = FFMAX(max2, fabs(coeffs[samples + k / real_ch]));
889 890
        }

891 892 893
        for (i = 0; i < rc->classifications - 1; i++)
            if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1])
                break;
894 895 896
        classes[0][p] = i;
    }

897 898 899
    for (pass = 0; pass < 8; pass++) {
        p = 0;
        while (p < partitions) {
900 901
            if (pass == 0)
                for (j = 0; j < channels; j++) {
902
                    vorbis_enc_codebook * book = &venc->codebooks[rc->classbook];
903 904 905 906 907
                    int entry = 0;
                    for (i = 0; i < classwords; i++) {
                        entry *= rc->classifications;
                        entry += classes[j][p + i];
                    }
908 909
                    if (put_codeword(pb, book, entry))
                        return AVERROR(EINVAL);
910 911 912 913
                }
            for (i = 0; i < classwords && p < partitions; i++, p++) {
                for (j = 0; j < channels; j++) {
                    int nbook = rc->books[classes[j][p]][pass];
914
                    vorbis_enc_codebook * book = &venc->codebooks[nbook];
915
                    float *buf = coeffs + samples*j + rc->begin + p*psize;
916 917
                    if (nbook == -1)
                        continue;
Oded Shimon's avatar
Oded Shimon committed
918

919
                    assert(rc->type == 0 || rc->type == 2);
920
                    assert(!(psize % book->ndimensions));
Oded Shimon's avatar
Oded Shimon committed
921

922
                    if (rc->type == 0) {
923
                        for (k = 0; k < psize; k += book->ndimensions) {
924
                            int l;
925 926 927
                            float *a = put_vector(book, pb, &buf[k]);
                            if (!a)
                                return AVERROR(EINVAL);
928
                            for (l = 0; l < book->ndimensions; l++)
929
                                buf[k + l] -= a[l];
930
                        }
931
                    } else {
932 933 934
                        int s = rc->begin + p * psize, a1, b1;
                        a1 = (s % real_ch) * samples;
                        b1 =  s / real_ch;
935
                        s  = real_ch * samples;
936
                        for (k = 0; k < psize; k += book->ndimensions) {
937
                            int dim, a2 = a1, b2 = b1;
Måns Rullgård's avatar
Måns Rullgård committed
938
                            float vec[MAX_CODEBOOK_DIM], *pv = vec;
939
                            for (dim = book->ndimensions; dim--; ) {
940
                                *pv++ = coeffs[a2 + b2];
941
                                if ((a2 += samples) == s) {
942
                                    a2 = 0;
943 944
                                    b2++;
                                }
945 946
                            }
                            pv = put_vector(book, pb, vec);
947 948
                            if (!pv)
                                return AVERROR(EINVAL);
949
                            for (dim = book->ndimensions; dim--; ) {
950
                                coeffs[a1 + b1] -= *pv++;
951
                                if ((a1 += samples) == s) {
952
                                    a1 = 0;
953 954
                                    b1++;
                                }
955
                            }
956 957
                        }
                    }
958 959 960 961
                }
            }
        }
    }
962
    return 0;
Oded Shimon's avatar
Oded Shimon committed
963 964
}

965 966
static int apply_window_and_mdct(vorbis_enc_context *venc,
                                 float **audio, int samples)
967
{
968
    int i, channel;
969
    const float * win = venc->win[0];
970 971
    int window_len = 1 << (venc->log2_blocksize[0] - 1);
    float n = (float)(1 << venc->log2_blocksize[0]) / 4.;
972 973
    // FIXME use dsp

974 975
    if (!venc->have_saved && !samples)
        return 0;
976

977
    if (venc->have_saved) {
978
        for (channel = 0; channel < venc->channels; channel++)
979 980 981
            memcpy(venc->samples + channel * window_len * 2,
                   venc->saved + channel * window_len, sizeof(float) * window_len);
    } else {
982
        for (channel = 0; channel < venc->channels; channel++)
983 984 985
            memset(venc->samples + channel * window_len * 2, 0,
                   sizeof(float) * window_len);
    }
986 987 988

    if (samples) {
        for (channel = 0; channel < venc->channels; channel++) {
989
            float * offset = venc->samples + channel*window_len*2 + window_len;
990 991
            for (i = 0; i < samples; i++)
                offset[i] = audio[channel][i] / n * win[window_len - i - 1];
992 993
        }
    } else {
994
        for (channel = 0; channel < venc->channels; channel++)
995 996
            memset(venc->samples + channel * window_len * 2 + window_len,
                   0, sizeof(float) * window_len);
997 998
    }

999
    for (channel = 0; channel < venc->channels; channel++)
1000
        venc->mdct[0].mdct_calc(&venc->mdct[0], venc->coeffs + channel * window_len,
1001
                     venc->samples + channel * window_len * 2);
1002 1003 1004

    if (samples) {
        for (channel = 0; channel < venc->channels; channel++) {
1005
            float *offset = venc->saved + channel * window_len;
1006 1007
            for (i = 0; i < samples; i++)
                offset[i] = audio[channel][i] / n * win[i];
1008 1009 1010 1011 1012 1013 1014
        }
        venc->have_saved = 1;
    } else {
        venc->have_saved = 0;
    }
    return 1;
}
Oded Shimon's avatar
Oded Shimon committed
1015

1016
static int vorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
1017
                               const AVFrame *frame, int *got_packet_ptr)
Oded Shimon's avatar
Oded Shimon committed
1018
{
1019
    vorbis_enc_context *venc = avctx->priv_data;
1020
    float **audio = frame ? (float **)frame->extended_data : NULL;
1021
    int samples = frame ? frame->nb_samples : 0;
1022 1023
    vorbis_enc_mode *mode;
    vorbis_enc_mapping *mapping;
1024
    PutBitContext pb;
1025
    int i, ret;
1026

1027 1028
    if (!apply_window_and_mdct(venc, audio, samples))
        return 0;
1029
    samples = 1 << (venc->log2_blocksize[0] - 1);
1030

1031
    if ((ret = ff_alloc_packet2(avctx, avpkt, 8192)) < 0)
1032 1033 1034
        return ret;

    init_put_bits(&pb, avpkt->data, avpkt->size);
1035

1036
    if (pb.size_in_bits - put_bits_count(&pb) < 1 + ilog(venc->nmodes - 1)) {
1037
        av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n");
1038 1039 1040
        return AVERROR(EINVAL);
    }

1041 1042 1043 1044
    put_bits(&pb, 1, 0); // magic bit

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

1045
    mode    = &venc->modes[0];
1046 1047 1048 1049 1050 1051 1052
    mapping = &venc->mappings[mode->mapping];
    if (mode->blockflag) {
        put_bits(&pb, 1, 0);
        put_bits(&pb, 1, 0);
    }

    for (i = 0; i < venc->channels; i++) {
1053
        vorbis_enc_floor *fc = &venc->floors[mapping->floor[mapping->mux[i]]];
1054
        uint16_t posts[MAX_FLOOR_VALUES];
1055
        floor_fit(venc, fc, &venc->coeffs[i * samples], posts, samples);
1056
        if (floor_encode(venc, fc, &pb, posts, &venc->floor[i * samples], samples)) {
1057
            av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n");
1058 1059
            return AVERROR(EINVAL);
        }
1060
    }
Oded Shimon's avatar
Oded Shimon committed
1061

1062
    for (i = 0; i < venc->channels * samples; i++)
1063
        venc->coeffs[i] /= venc->floor[i];
1064

1065
    for (i = 0; i < mapping->coupling_steps; i++) {
1066 1067
        float *mag = venc->coeffs + mapping->magnitude[i] * samples;
        float *ang = venc->coeffs + mapping->angle[i]     * samples;
1068 1069 1070
        int j;
        for (j = 0; j < samples; j++) {
            float a = ang[j];
1071
            ang[j] -= mag[j];
1072 1073 1074 1075
            if (mag[j] > 0)
                ang[j] = -ang[j];
            if (ang[j] < 0)
                mag[j] = a;
1076 1077 1078
        }
    }

1079 1080
    if (residue_encode(venc, &venc->residues[mapping->residue[mapping->mux[0]]],
                       &pb, venc->coeffs, samples, venc->channels)) {
1081
        av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n");
1082 1083
        return AVERROR(EINVAL);
    }
1084

1085
    flush_put_bits(&pb);
1086 1087
    avpkt->size = put_bits_count(&pb) >> 3;

1088
    avpkt->duration = ff_samples_to_time_base(avctx, avctx->frame_size);
1089
    if (frame) {
1090
        if (frame->pts != AV_NOPTS_VALUE)
1091
            avpkt->pts = ff_samples_to_time_base(avctx, frame->pts);
1092
    } else
1093 1094 1095 1096 1097 1098
        avpkt->pts = venc->next_pts;
    if (avpkt->pts != AV_NOPTS_VALUE)
        venc->next_pts = avpkt->pts + avpkt->duration;

    *got_packet_ptr = 1;
    return 0;
Oded Shimon's avatar
Oded Shimon committed
1099 1100 1101
}


1102
static av_cold int vorbis_encode_close(AVCodecContext *avctx)
Oded Shimon's avatar
Oded Shimon committed
1103
{
1104
    vorbis_enc_context *venc = avctx->priv_data;
1105 1106
    int i;

1107 1108 1109 1110 1111
    if (venc->codebooks)
        for (i = 0; i < venc->ncodebooks; i++) {
            av_freep(&venc->codebooks[i].lens);
            av_freep(&venc->codebooks[i].codewords);
            av_freep(&venc->codebooks[i].quantlist);
1112
            av_freep(&venc->codebooks[i].dimensions);
1113 1114
            av_freep(&venc->codebooks[i].pow2);
        }
1115 1116
    av_freep(&venc->codebooks);

1117 1118 1119 1120 1121 1122
    if (venc->floors)
        for (i = 0; i < venc->nfloors; i++) {
            int j;
            if (venc->floors[i].classes)
                for (j = 0; j < venc->floors[i].nclasses; j++)
                    av_freep(&venc->floors[i].classes[j].books);
1123
            av_freep(&venc->floors[i].classes);
1124 1125 1126
            av_freep(&venc->floors[i].partition_to_class);
            av_freep(&venc->floors[i].list);
        }
1127 1128
    av_freep(&venc->floors);

1129 1130 1131 1132 1133
    if (venc->residues)
        for (i = 0; i < venc->nresidues; i++) {
            av_freep(&venc->residues[i].books);
            av_freep(&venc->residues[i].maxes);
        }
1134 1135
    av_freep(&venc->residues);

1136 1137 1138 1139 1140
    if (venc->mappings)
        for (i = 0; i < venc->nmappings; i++) {
            av_freep(&venc->mappings[i].mux);
            av_freep(&venc->mappings[i].floor);
            av_freep(&venc->mappings[i].residue);
Oded Shimon's avatar
Oded Shimon committed
1141 1142
            av_freep(&venc->mappings[i].magnitude);
            av_freep(&venc->mappings[i].angle);
1143
        }
1144 1145 1146
    av_freep(&venc->mappings);

    av_freep(&venc->modes);
Oded Shimon's avatar
Oded Shimon committed
1147

1148 1149 1150 1151 1152 1153 1154 1155
    av_freep(&venc->saved);
    av_freep(&venc->samples);
    av_freep(&venc->floor);
    av_freep(&venc->coeffs);

    ff_mdct_end(&venc->mdct[0]);
    ff_mdct_end(&venc->mdct[1]);

1156
    av_freep(&avctx->extradata);
Oded Shimon's avatar
Oded Shimon committed
1157 1158 1159 1160

    return 0 ;
}

1161
static av_cold int vorbis_encode_init(AVCodecContext *avctx)
1162
{
1163
    vorbis_enc_context *venc = avctx->priv_data;
1164 1165
    int ret;

1166
    if (avctx->channels != 2) {
1167
        av_log(avctx, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n");
1168 1169 1170
        return -1;
    }

1171
    if ((ret = create_vorbis_context(venc, avctx)) < 0)
1172 1173
        goto error;

1174 1175 1176
    avctx->bit_rate = 0;
    if (avctx->flags & CODEC_FLAG_QSCALE)
        venc->quality = avctx->global_quality / (float)FF_QP2LAMBDA;
1177
    else
1178
        venc->quality = 8;
1179 1180
    venc->quality *= venc->quality;

1181
    if ((ret = put_main_header(venc, (uint8_t**)&avctx->extradata)) < 0)
1182
        goto error;
1183
    avctx->extradata_size = ret;
1184

1185
    avctx->frame_size = 1 << (venc->log2_blocksize[0] - 1);
1186 1187 1188

    return 0;
error:
1189
    vorbis_encode_close(avctx);
1190 1191 1192
    return ret;
}

1193
AVCodec ff_vorbis_encoder = {
1194 1195
    .name           = "vorbis",
    .type           = AVMEDIA_TYPE_AUDIO,
1196
    .id             = AV_CODEC_ID_VORBIS,
1197 1198
    .priv_data_size = sizeof(vorbis_enc_context),
    .init           = vorbis_encode_init,
1199
    .encode2        = vorbis_encode_frame,
1200
    .close          = vorbis_encode_close,
1201
    .capabilities   = CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
1202
    .sample_fmts    = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP,
1203 1204
                                                     AV_SAMPLE_FMT_NONE },
    .long_name      = NULL_IF_CONFIG_SMALL("Vorbis"),
Oded Shimon's avatar
Oded Shimon committed
1205
};