private void vorbis_encode_floor_setup( float s, int block, static_codebook[][] books, vorbis_info_floor1[] in, int[] x) { int i, k; int is = new Float(s).intValue(); codec_setup_info ci = vi.codec_setup; // _ogg_calloc(1,sizeof(*f)) // memcpy(f,in+x[is],sizeof(*f)); vorbis_info_floor1 f = new vorbis_info_floor1(in[x[is]]); // fill in the lowpass field, even if it's temporary f.n = ci.blocksizes[block] >> 1; // books { int partitions = f.partitions; int maxclass = -1; int maxbook = -1; for (i = 0; i < partitions; i++) if (f.partitionclass[i] > maxclass) maxclass = f.partitionclass[i]; for (i = 0; i <= maxclass; i++) { if (f.class_book[i] > maxbook) maxbook = f.class_book[i]; f.class_book[i] += ci.books; for (k = 0; k < (1 << f.class_subs[i]); k++) { if (f.class_subbook[i][k] > maxbook) maxbook = f.class_subbook[i][k]; if (f.class_subbook[i][k] >= 0) f.class_subbook[i][k] += ci.books; } } for (i = 0; i <= maxbook; i++) { ci.book_param[ci.books++] = books[x[is]][i]; } } // for now, we're only using floor 1 ci.floor_type[ci.floors] = 1; ci.floor_param[ci.floors] = f; ci.floors++; }
private void vorbis_encode_residue_setup(int number, int block, vorbis_residue_template res) { codec_setup_info ci = vi.codec_setup; int i; // vorbis_info_residue0 *r = ci.residue_param[number] = _ogg_malloc(sizeof(*r)); // memcpy(r,res.res,sizeof(*r)); ci.residue_param[number] = new vorbis_info_residue0(res.res); vorbis_info_residue0 r = ci.residue_param[number]; if (ci.residues <= number) ci.residues = number + 1; switch (ci.blocksizes[block]) { case 64: case 128: case 256: r.grouping = 16; break; default: r.grouping = 32; break; } ci.residue_type[number] = res.res_type; // to be adjusted by lowpass/pointlimit later r.end = ci.blocksizes[block] >> 1; if (res.res_type == 2) { r.end *= vi.channels; } // fill in all the books { int booklist = 0, k; if (ci.hi.managed != 0) { for (i = 0; i < r.partitions; i++) for (k = 0; k < 3; k++) if (res.books_base_managed.books[i][k] != null) r.secondstages[i] |= (1 << k); r.groupbook = book_dup_or_new(ci, res.book_aux_managed); ci.book_param[r.groupbook] = res.book_aux_managed; for (i = 0; i < r.partitions; i++) { for (k = 0; k < 3; k++) { if (res.books_base_managed.books[i][k] != null) { int bookid = book_dup_or_new(ci, res.books_base_managed.books[i][k]); r.booklist[booklist++] = bookid; ci.book_param[bookid] = res.books_base_managed.books[i][k]; } } } } else { for (i = 0; i < r.partitions; i++) for (k = 0; k < 3; k++) if (res.books_base.books[i][k] != null) r.secondstages[i] |= (1 << k); r.groupbook = book_dup_or_new(ci, res.book_aux); ci.book_param[r.groupbook] = res.book_aux; for (i = 0; i < r.partitions; i++) { for (k = 0; k < 3; k++) { if (res.books_base.books[i][k] != null) { int bookid = book_dup_or_new(ci, res.books_base.books[i][k]); r.booklist[booklist++] = bookid; ci.book_param[bookid] = res.books_base.books[i][k]; } } } } } // lowpass setup/pointlimit { float freq = ci.hi.lowpass_kHz * 1000.0f; vorbis_info_floor1 f = ci.floor_param[block]; // by convention float nyq = vi.rate / 2.0f; int blocksize = ci.blocksizes[block] >> 1; // lowpass needs to be set in the floor and the residue. if (freq > nyq) freq = nyq; // in the floor, the granularity can be very fine; it doesn't alter the // encoding structure, only the samples used to fit the floor approximation f.n = new Double(freq / nyq * blocksize).intValue(); // this res may by limited by the maximum pointlimit of the mode, // not the lowpass. the floor is always lowpass limited. if (res.limit_type != 0) { if (ci.hi.managed != 0) freq = ci.psy_g_param.coupling_pkHz[PACKETBLOBS - 1] * 1000.0f; else freq = ci.psy_g_param.coupling_pkHz[PACKETBLOBS / 2] * 1000.0f; if (freq > nyq) freq = nyq; } // in the residue, we're constrained, physically, by partition // boundaries. We still lowpass 'wherever', but we have to round up // here to next boundary, or the vorbis spec will round it *down* to // previous boundary in encode/decode if (ci.residue_type[block] == 2) r.end = new Double((freq / nyq * blocksize * 2) / r.grouping + .9).intValue() * r.grouping; // round up only if we're well past else r.end = new Double((freq / nyq * blocksize) / r.grouping + .9).intValue() * r.grouping; // round up only if we're well past } }