unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n) {
    unsigned int ret=0, i, j;
    do {
        ++ret;
        for(i=0,j=ret;i<n-1;i++) j*=ret;
    } while (j<=x);
    return (ret-1);
}
['static av_cold int vorbis_encode_init(AVCodecContext * avccontext)\n{\n    venc_context_t * venc = avccontext->priv_data;\n    if (avccontext->channels != 2) {\n        av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\\n");\n        return -1;\n    }\n    create_vorbis_context(venc, avccontext);\n    if (avccontext->flags & CODEC_FLAG_QSCALE)\n        venc->quality = avccontext->global_quality / (float)FF_QP2LAMBDA / 10.;\n    else\n        venc->quality = 1.;\n    venc->quality *= venc->quality;\n    avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata);\n    avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1);\n    avccontext->coded_frame = avcodec_alloc_frame();\n    avccontext->coded_frame->key_frame = 1;\n    return 0;\n}', 'static void create_vorbis_context(venc_context_t * venc, AVCodecContext * avccontext) {\n    floor_t * fc;\n    residue_t * rc;\n    mapping_t * mc;\n    int i, book;\n    venc->channels = avccontext->channels;\n    venc->sample_rate = avccontext->sample_rate;\n    venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11;\n    venc->ncodebooks = sizeof(cvectors)/sizeof(cvectors[0]);\n    venc->codebooks = av_malloc(sizeof(codebook_t) * venc->ncodebooks);\n    for (book = 0; book < venc->ncodebooks; book++) {\n        codebook_t * cb = &venc->codebooks[book];\n        int vals;\n        cb->ndimentions = cvectors[book].dim;\n        cb->nentries = cvectors[book].real_len;\n        cb->min = cvectors[book].min;\n        cb->delta = cvectors[book].delta;\n        cb->lookup = cvectors[book].lookup;\n        cb->seq_p = 0;\n        cb->lens = av_malloc(sizeof(uint8_t) * cb->nentries);\n        cb->codewords = av_malloc(sizeof(uint32_t) * cb->nentries);\n        memcpy(cb->lens, cvectors[book].clens, cvectors[book].len);\n        memset(cb->lens + cvectors[book].len, 0, cb->nentries - cvectors[book].len);\n        if (cb->lookup) {\n            vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);\n            cb->quantlist = av_malloc(sizeof(int) * vals);\n            for (i = 0; i < vals; i++)\n                cb->quantlist[i] = cvectors[book].quant[i];\n        } else {\n            cb->quantlist = NULL;\n        }\n        ready_codebook(cb);\n    }\n    venc->nfloors = 1;\n    venc->floors = av_malloc(sizeof(floor_t) * venc->nfloors);\n    fc = &venc->floors[0];\n    fc->partitions = 8;\n    fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions);\n    fc->nclasses = 0;\n    for (i = 0; i < fc->partitions; i++) {\n        static const int a[] = {0,1,2,2,3,3,4,4};\n        fc->partition_to_class[i] = a[i];\n        fc->nclasses = FFMAX(fc->nclasses, fc->partition_to_class[i]);\n    }\n    fc->nclasses++;\n    fc->classes = av_malloc(sizeof(floor_class_t) * fc->nclasses);\n    for (i = 0; i < fc->nclasses; i++) {\n        floor_class_t * c = &fc->classes[i];\n        int j, books;\n        c->dim = floor_classes[i].dim;\n        c->subclass = floor_classes[i].subclass;\n        c->masterbook = floor_classes[i].masterbook;\n        books = (1 << c->subclass);\n        c->books = av_malloc(sizeof(int) * books);\n        for (j = 0; j < books; j++)\n            c->books[j] = floor_classes[i].nbooks[j];\n    }\n    fc->multiplier = 2;\n    fc->rangebits = venc->log2_blocksize[0] - 1;\n    fc->values = 2;\n    for (i = 0; i < fc->partitions; i++)\n        fc->values += fc->classes[fc->partition_to_class[i]].dim;\n    fc->list = av_malloc(sizeof(floor1_entry_t) * fc->values);\n    fc->list[0].x = 0;\n    fc->list[1].x = 1 << fc->rangebits;\n    for (i = 2; i < fc->values; i++) {\n        static const int a[] = {\n             93, 23,372,  6, 46,186,750, 14, 33, 65,\n            130,260,556,  3, 10, 18, 28, 39, 55, 79,\n            111,158,220,312,464,650,850\n        };\n        fc->list[i].x = a[i - 2];\n    }\n    ff_vorbis_ready_floor1_list(fc->list, fc->values);\n    venc->nresidues = 1;\n    venc->residues = av_malloc(sizeof(residue_t) * venc->nresidues);\n    rc = &venc->residues[0];\n    rc->type = 2;\n    rc->begin = 0;\n    rc->end = 1600;\n    rc->partition_size = 32;\n    rc->classifications = 10;\n    rc->classbook = 15;\n    rc->books = av_malloc(sizeof(*rc->books) * rc->classifications);\n    {\n        static const int8_t a[10][8] = {\n            { -1, -1, -1, -1, -1, -1, -1, -1, },\n            { -1, -1, 16, -1, -1, -1, -1, -1, },\n            { -1, -1, 17, -1, -1, -1, -1, -1, },\n            { -1, -1, 18, -1, -1, -1, -1, -1, },\n            { -1, -1, 19, -1, -1, -1, -1, -1, },\n            { -1, -1, 20, -1, -1, -1, -1, -1, },\n            { -1, -1, 21, -1, -1, -1, -1, -1, },\n            { 22, 23, -1, -1, -1, -1, -1, -1, },\n            { 24, 25, -1, -1, -1, -1, -1, -1, },\n            { 26, 27, 28, -1, -1, -1, -1, -1, },\n        };\n        memcpy(rc->books, a, sizeof a);\n    }\n    ready_residue(rc, venc);\n    venc->nmappings = 1;\n    venc->mappings = av_malloc(sizeof(mapping_t) * venc->nmappings);\n    mc = &venc->mappings[0];\n    mc->submaps = 1;\n    mc->mux = av_malloc(sizeof(int) * venc->channels);\n    for (i = 0; i < venc->channels; i++)\n        mc->mux[i] = 0;\n    mc->floor = av_malloc(sizeof(int) * mc->submaps);\n    mc->residue = av_malloc(sizeof(int) * mc->submaps);\n    for (i = 0; i < mc->submaps; i++) {\n        mc->floor[i] = 0;\n        mc->residue[i] = 0;\n    }\n    mc->coupling_steps = venc->channels == 2 ? 1 : 0;\n    mc->magnitude = av_malloc(sizeof(int) * mc->coupling_steps);\n    mc->angle = av_malloc(sizeof(int) * mc->coupling_steps);\n    if (mc->coupling_steps) {\n        mc->magnitude[0] = 0;\n        mc->angle[0] = 1;\n    }\n    venc->nmodes = 1;\n    venc->modes = av_malloc(sizeof(vorbis_mode_t) * venc->nmodes);\n    venc->modes[0].blockflag = 0;\n    venc->modes[0].mapping = 0;\n    venc->have_saved = 0;\n    venc->saved = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);\n    venc->samples = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]));\n    venc->floor = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);\n    venc->coeffs = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);\n    venc->win[0] = ff_vorbis_vwin[venc->log2_blocksize[0] - 6];\n    venc->win[1] = ff_vorbis_vwin[venc->log2_blocksize[1] - 6];\n    ff_mdct_init(&venc->mdct[0], venc->log2_blocksize[0], 0);\n    ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0);\n}', 'int ff_mdct_init(MDCTContext *s, int nbits, int inverse)\n{\n    int n, n4, i;\n    double alpha;\n    memset(s, 0, sizeof(*s));\n    n = 1 << nbits;\n    s->nbits = nbits;\n    s->n = n;\n    n4 = n >> 2;\n    s->tcos = av_malloc(n4 * sizeof(FFTSample));\n    if (!s->tcos)\n        goto fail;\n    s->tsin = av_malloc(n4 * sizeof(FFTSample));\n    if (!s->tsin)\n        goto fail;\n    for(i=0;i<n4;i++) {\n        alpha = 2 * M_PI * (i + 1.0 / 8.0) / n;\n        s->tcos[i] = -cos(alpha);\n        s->tsin[i] = -sin(alpha);\n    }\n    if (ff_fft_init(&s->fft, s->nbits - 2, inverse) < 0)\n        goto fail;\n    return 0;\n fail:\n    av_freep(&s->tcos);\n    av_freep(&s->tsin);\n    return -1;\n}', 'static int put_main_header(venc_context_t * venc, uint8_t ** out) {\n    int i;\n    PutBitContext pb;\n    uint8_t buffer[50000] = {0}, * p = buffer;\n    int buffer_len = sizeof buffer;\n    int len, hlens[3];\n    init_put_bits(&pb, p, buffer_len);\n    put_bits(&pb, 8, 1);\n    for (i = 0; "vorbis"[i]; i++)\n        put_bits(&pb, 8, "vorbis"[i]);\n    put_bits(&pb, 32, 0);\n    put_bits(&pb, 8, venc->channels);\n    put_bits(&pb, 32, venc->sample_rate);\n    put_bits(&pb, 32, 0);\n    put_bits(&pb, 32, 0);\n    put_bits(&pb, 32, 0);\n    put_bits(&pb, 4, venc->log2_blocksize[0]);\n    put_bits(&pb, 4, venc->log2_blocksize[1]);\n    put_bits(&pb, 1, 1);\n    flush_put_bits(&pb);\n    hlens[0] = (put_bits_count(&pb) + 7) / 8;\n    buffer_len -= hlens[0];\n    p += hlens[0];\n    init_put_bits(&pb, p, buffer_len);\n    put_bits(&pb, 8, 3);\n    for (i = 0; "vorbis"[i]; i++)\n        put_bits(&pb, 8, "vorbis"[i]);\n    put_bits(&pb, 32, 0);\n    put_bits(&pb, 32, 0);\n    put_bits(&pb, 1, 1);\n    flush_put_bits(&pb);\n    hlens[1] = (put_bits_count(&pb) + 7) / 8;\n    buffer_len -= hlens[1];\n    p += hlens[1];\n    init_put_bits(&pb, p, buffer_len);\n    put_bits(&pb, 8, 5);\n    for (i = 0; "vorbis"[i]; i++)\n        put_bits(&pb, 8, "vorbis"[i]);\n    put_bits(&pb, 8, venc->ncodebooks - 1);\n    for (i = 0; i < venc->ncodebooks; i++)\n        put_codebook_header(&pb, &venc->codebooks[i]);\n    put_bits(&pb, 6, 0);\n    put_bits(&pb, 16, 0);\n    put_bits(&pb, 6, venc->nfloors - 1);\n    for (i = 0; i < venc->nfloors; i++)\n        put_floor_header(&pb, &venc->floors[i]);\n    put_bits(&pb, 6, venc->nresidues - 1);\n    for (i = 0; i < venc->nresidues; i++)\n        put_residue_header(&pb, &venc->residues[i]);\n    put_bits(&pb, 6, venc->nmappings - 1);\n    for (i = 0; i < venc->nmappings; i++) {\n        mapping_t * mc = &venc->mappings[i];\n        int j;\n        put_bits(&pb, 16, 0);\n        put_bits(&pb, 1, mc->submaps > 1);\n        if (mc->submaps > 1)\n            put_bits(&pb, 4, mc->submaps - 1);\n        put_bits(&pb, 1, !!mc->coupling_steps);\n        if (mc->coupling_steps) {\n            put_bits(&pb, 8, mc->coupling_steps - 1);\n            for (j = 0; j < mc->coupling_steps; j++) {\n                put_bits(&pb, ilog(venc->channels - 1), mc->magnitude[j]);\n                put_bits(&pb, ilog(venc->channels - 1), mc->angle[j]);\n            }\n        }\n        put_bits(&pb, 2, 0);\n        if (mc->submaps > 1)\n            for (j = 0; j < venc->channels; j++)\n                put_bits(&pb, 4, mc->mux[j]);\n        for (j = 0; j < mc->submaps; j++) {\n            put_bits(&pb, 8, 0);\n            put_bits(&pb, 8, mc->floor[j]);\n            put_bits(&pb, 8, mc->residue[j]);\n        }\n    }\n    put_bits(&pb, 6, venc->nmodes - 1);\n    for (i = 0; i < venc->nmodes; i++) {\n        put_bits(&pb, 1, venc->modes[i].blockflag);\n        put_bits(&pb, 16, 0);\n        put_bits(&pb, 16, 0);\n        put_bits(&pb, 8, venc->modes[i].mapping);\n    }\n    put_bits(&pb, 1, 1);\n    flush_put_bits(&pb);\n    hlens[2] = (put_bits_count(&pb) + 7) / 8;\n    len = hlens[0] + hlens[1] + hlens[2];\n    p = *out = av_mallocz(64 + len + len/255);\n    *p++ = 2;\n    p += av_xiphlacing(p, hlens[0]);\n    p += av_xiphlacing(p, hlens[1]);\n    buffer_len = 0;\n    for (i = 0; i < 3; i++) {\n        memcpy(p, buffer + buffer_len, hlens[i]);\n        p += hlens[i];\n        buffer_len += hlens[i];\n    }\n    return p - *out;\n}', 'static void put_codebook_header(PutBitContext * pb, codebook_t * cb) {\n    int i;\n    int ordered = 0;\n    put_bits(pb, 24, 0x564342);\n    put_bits(pb, 16, cb->ndimentions);\n    put_bits(pb, 24, cb->nentries);\n    for (i = 1; i < cb->nentries; i++)\n        if (cb->lens[i] < cb->lens[i-1]) break;\n    if (i == cb->nentries)\n        ordered = 1;\n    put_bits(pb, 1, ordered);\n    if (ordered) {\n        int len = cb->lens[0];\n        put_bits(pb, 5, len - 1);\n        i = 0;\n        while (i < cb->nentries) {\n            int j;\n            for (j = 0; j+i < cb->nentries; j++)\n                if (cb->lens[j+i] != len) break;\n            put_bits(pb, ilog(cb->nentries - i), j);\n            i += j;\n            len++;\n        }\n    } else {\n        int sparse = 0;\n        for (i = 0; i < cb->nentries; i++)\n            if (!cb->lens[i]) break;\n        if (i != cb->nentries)\n            sparse = 1;\n        put_bits(pb, 1, sparse);\n        for (i = 0; i < cb->nentries; i++) {\n            if (sparse) put_bits(pb, 1, !!cb->lens[i]);\n            if (cb->lens[i]) put_bits(pb, 5, cb->lens[i] - 1);\n        }\n    }\n    put_bits(pb, 4, cb->lookup);\n    if (cb->lookup) {\n        int tmp = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);\n        int bits = ilog(cb->quantlist[0]);\n        for (i = 1; i < tmp; i++)\n            bits = FFMAX(bits, ilog(cb->quantlist[i]));\n        put_float(pb, cb->min);\n        put_float(pb, cb->delta);\n        put_bits(pb, 4, bits - 1);\n        put_bits(pb, 1, cb->seq_p);\n        for (i = 0; i < tmp; i++)\n            put_bits(pb, bits, cb->quantlist[i]);\n    }\n}', 'static int cb_lookup_vals(int lookup, int dimentions, int entries) {\n    if      (lookup == 1) return ff_vorbis_nth_root(entries, dimentions);\n    else if (lookup == 2) return dimentions * entries;\n    return 0;\n}', 'unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n) {\n    unsigned int ret=0, i, j;\n    do {\n        ++ret;\n        for(i=0,j=ret;i<n-1;i++) j*=ret;\n    } while (j<=x);\n    return (ret-1);\n}']