static void floor_encode(venc_context_t * venc, floor_t * fc, PutBitContext * pb, uint_fast16_t * posts, float * floor, int samples) {
    int range = 255 / fc->multiplier + 1;
    int coded[fc->values];
    int i, counter;
    put_bits(pb, 1, 1);
    put_bits(pb, ilog(range - 1), posts[0]);
    put_bits(pb, ilog(range - 1), posts[1]);
    coded[0] = coded[1] = 1;
    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);
        int highroom = range - predicted;
        int lowroom = predicted;
        int room = FFMIN(highroom, lowroom);
        if (predicted == posts[i]) {
            coded[i] = 0;
            continue;
        } else {
            if (!coded[fc->list[i].low ]) coded[fc->list[i].low ] = -1;
            if (!coded[fc->list[i].high]) coded[fc->list[i].high] = -1;
        }
        if (posts[i] > predicted) {
            if (posts[i] - predicted > room)
                coded[i] = posts[i] - predicted + lowroom;
            else
                coded[i] = (posts[i] - predicted) << 1;
        } else {
            if (predicted - posts[i] > room)
                coded[i] = predicted - posts[i] + highroom - 1;
            else
                coded[i] = ((predicted - posts[i]) << 1) - 1;
        }
    }
    counter = 2;
    for (i = 0; i < fc->partitions; i++) {
        floor_class_t * c = &fc->classes[fc->partition_to_class[i]];
        int k, cval = 0, csub = 1<<c->subclass;
        if (c->subclass) {
            codebook_t * book = &venc->codebooks[c->masterbook];
            int cshift = 0;
            for (k = 0; k < c->dim; k++) {
                int l;
                for (l = 0; l < csub; l++) {
                    int maxval = 1;
                    if (c->books[l] != -1)
                        maxval = venc->codebooks[c->books[l]].nentries;
                    if (coded[counter + k] < maxval) break;
                }
                assert(l != csub);
                cval |= l << cshift;
                cshift += c->subclass;
            }
            put_codeword(pb, book, cval);
        }
        for (k = 0; k < c->dim; k++) {
            int book = c->books[cval & (csub-1)];
            int entry = coded[counter++];
            cval >>= c->subclass;
            if (book == -1) continue;
            if (entry == -1) entry = 0;
            put_codeword(pb, &venc->codebooks[book], entry);
        }
    }
    ff_vorbis_floor1_render_list(fc->list, fc->values, posts, coded, fc->multiplier, floor, samples);
}
['static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * packets, int buf_size, void *data)\n{\n    venc_context_t * venc = avccontext->priv_data;\n    signed short * audio = data;\n    int samples = data ? avccontext->frame_size : 0;\n    vorbis_mode_t * mode;\n    mapping_t * mapping;\n    PutBitContext pb;\n    int i;\n    if (!apply_window_and_mdct(venc, audio, samples)) return 0;\n    samples = 1 << (venc->log2_blocksize[0] - 1);\n    init_put_bits(&pb, packets, buf_size);\n    put_bits(&pb, 1, 0);\n    put_bits(&pb, ilog(venc->nmodes - 1), 0);\n    mode = &venc->modes[0];\n    mapping = &venc->mappings[mode->mapping];\n    if (mode->blockflag) {\n        put_bits(&pb, 1, 0);\n        put_bits(&pb, 1, 0);\n    }\n    for (i = 0; i < venc->channels; i++) {\n        floor_t * fc = &venc->floors[mapping->floor[mapping->mux[i]]];\n        uint_fast16_t posts[fc->values];\n        floor_fit(venc, fc, &venc->coeffs[i * samples], posts, samples);\n        floor_encode(venc, fc, &pb, posts, &venc->floor[i * samples], samples);\n    }\n    for (i = 0; i < venc->channels * samples; i++) {\n        venc->coeffs[i] /= venc->floor[i];\n    }\n    for (i = 0; i < mapping->coupling_steps; i++) {\n        float * mag = venc->coeffs + mapping->magnitude[i] * samples;\n        float * ang = venc->coeffs + mapping->angle[i] * samples;\n        int j;\n        for (j = 0; j < samples; j++) {\n            float a = ang[j];\n            ang[j] -= mag[j];\n            if (mag[j] > 0) ang[j] = -ang[j];\n            if (ang[j] < 0) mag[j] = a;\n        }\n    }\n    residue_encode(venc, &venc->residues[mapping->residue[mapping->mux[0]]], &pb, venc->coeffs, samples, venc->channels);\n    flush_put_bits(&pb);\n    return (put_bits_count(&pb) + 7) / 8;\n}', 'static void floor_fit(venc_context_t * venc, floor_t * fc, float * coeffs, uint_fast16_t * posts, int samples) {\n    int range = 255 / fc->multiplier + 1;\n    int i;\n    float tot_average = 0.;\n    float averages[fc->values];\n    for (i = 0; i < fc->values; i++){\n        averages[i] = get_floor_average(fc, coeffs, i);\n        tot_average += averages[i];\n    }\n    tot_average /= fc->values;\n    tot_average /= venc->quality;\n    for (i = 0; i < fc->values; i++) {\n        int position = fc->list[fc->list[i].sort].x;\n        float average = averages[i];\n        int j;\n        average *= pow(tot_average / average, 0.5) * pow(1.25, position/200.);\n        for (j = 0; j < range - 1; j++)\n            if (ff_vorbis_floor1_inverse_db_table[j * fc->multiplier] > average) break;\n        posts[fc->list[i].sort] = j;\n    }\n}', 'static void floor_encode(venc_context_t * venc, floor_t * fc, PutBitContext * pb, uint_fast16_t * posts, float * floor, int samples) {\n    int range = 255 / fc->multiplier + 1;\n    int coded[fc->values];\n    int i, counter;\n    put_bits(pb, 1, 1);\n    put_bits(pb, ilog(range - 1), posts[0]);\n    put_bits(pb, ilog(range - 1), posts[1]);\n    coded[0] = coded[1] = 1;\n    for (i = 2; i < fc->values; i++) {\n        int predicted = render_point(fc->list[fc->list[i].low].x,\n                                     posts[fc->list[i].low],\n                                     fc->list[fc->list[i].high].x,\n                                     posts[fc->list[i].high],\n                                     fc->list[i].x);\n        int highroom = range - predicted;\n        int lowroom = predicted;\n        int room = FFMIN(highroom, lowroom);\n        if (predicted == posts[i]) {\n            coded[i] = 0;\n            continue;\n        } else {\n            if (!coded[fc->list[i].low ]) coded[fc->list[i].low ] = -1;\n            if (!coded[fc->list[i].high]) coded[fc->list[i].high] = -1;\n        }\n        if (posts[i] > predicted) {\n            if (posts[i] - predicted > room)\n                coded[i] = posts[i] - predicted + lowroom;\n            else\n                coded[i] = (posts[i] - predicted) << 1;\n        } else {\n            if (predicted - posts[i] > room)\n                coded[i] = predicted - posts[i] + highroom - 1;\n            else\n                coded[i] = ((predicted - posts[i]) << 1) - 1;\n        }\n    }\n    counter = 2;\n    for (i = 0; i < fc->partitions; i++) {\n        floor_class_t * c = &fc->classes[fc->partition_to_class[i]];\n        int k, cval = 0, csub = 1<<c->subclass;\n        if (c->subclass) {\n            codebook_t * book = &venc->codebooks[c->masterbook];\n            int cshift = 0;\n            for (k = 0; k < c->dim; k++) {\n                int l;\n                for (l = 0; l < csub; l++) {\n                    int maxval = 1;\n                    if (c->books[l] != -1)\n                        maxval = venc->codebooks[c->books[l]].nentries;\n                    if (coded[counter + k] < maxval) break;\n                }\n                assert(l != csub);\n                cval |= l << cshift;\n                cshift += c->subclass;\n            }\n            put_codeword(pb, book, cval);\n        }\n        for (k = 0; k < c->dim; k++) {\n            int book = c->books[cval & (csub-1)];\n            int entry = coded[counter++];\n            cval >>= c->subclass;\n            if (book == -1) continue;\n            if (entry == -1) entry = 0;\n            put_codeword(pb, &venc->codebooks[book], entry);\n        }\n    }\n    ff_vorbis_floor1_render_list(fc->list, fc->values, posts, coded, fc->multiplier, floor, samples);\n}']