37 #define BITSTREAM_READER_LE
50 #define V_MAX_VLCS (1 << 16)
51 #define V_MAX_PARTITIONS (1 << 20)
166 (13.1f * atan(0.00074f * (x)) + 2.24f * atan(1.85e-8f * (x) * (x)) + 1e-4f * (x))
168 static const char idx_err_str[] =
"Index value %d out of range (0 - %d) for %s at %s:%i\n";
169 #define VALIDATE_INDEX(idx, limit) \
171 av_log(vc->avctx, AV_LOG_ERROR,\
173 (int)(idx), (int)(limit - 1), #idx, __FILE__, __LINE__);\
174 return AVERROR_INVALIDDATA;\
176 #define GET_VALIDATED_INDEX(idx, bits, limit) \
178 idx = get_bits(gb, bits);\
179 VALIDATE_INDEX(idx, limit)\
184 float mant =
val & 0x1fffff;
185 int exp = (
val & 0x7fe00000) >> 21;
186 if (
val & 0x80000000)
203 for (
i = 0;
i < vc->residue_count;
i++)
212 for (
i = 0;
i < vc->codebook_count; ++
i) {
219 for (
i = 0;
i < vc->floor_count; ++
i) {
220 if (vc->floors[
i].floor_type == 0) {
223 av_freep(&vc->floors[
i].data.t0.book_list);
232 for (
i = 0;
i < vc->mapping_count; ++
i) {
247 uint8_t *tmp_vlc_bits =
NULL;
248 uint32_t *tmp_vlc_codes =
NULL;
250 uint16_t *codebook_multiplicands =
NULL;
253 vc->codebook_count =
get_bits(gb, 8) + 1;
255 ff_dlog(
NULL,
" Codebooks: %d \n", vc->codebook_count);
257 vc->codebooks =
av_mallocz(vc->codebook_count *
sizeof(*vc->codebooks));
261 if (!vc->codebooks ||
262 !tmp_vlc_bits || !tmp_vlc_codes || !codebook_multiplicands) {
267 for (
cb = 0;
cb < vc->codebook_count; ++
cb) {
269 unsigned ordered, t, entries, used_entries = 0;
275 " %u. Codebook setup data corrupt.\n",
cb);
283 " %u. Codebook's dimension is invalid (%d).\n",
291 " %u. Codebook has too many entries (%u).\n",
299 ff_dlog(
NULL,
" codebook_dimensions %d, codebook_entries %u\n",
312 for (ce = 0; ce < entries; ++ce) {
315 tmp_vlc_bits[ce] =
get_bits(gb, 5) + 1;
318 tmp_vlc_bits[ce] = 0;
323 used_entries = entries;
324 for (ce = 0; ce < entries; ++ce)
325 tmp_vlc_bits[ce] =
get_bits(gb, 5) + 1;
328 unsigned current_entry = 0;
329 unsigned current_length =
get_bits(gb, 5) + 1;
331 ff_dlog(
NULL,
" ordered, current length: %u\n", current_length);
333 used_entries = entries;
334 for (; current_entry < used_entries && current_length <= 32; ++current_length) {
343 for (
i = current_entry;
i < number+current_entry; ++
i)
344 if (
i < used_entries)
345 tmp_vlc_bits[
i] = current_length;
347 current_entry+=number;
349 if (current_entry>used_entries) {
369 unsigned codebook_value_bits =
get_bits(gb, 4) + 1;
370 unsigned codebook_sequence_p =
get_bits1(gb);
376 ff_dlog(
NULL,
" We expect %d numbers for building the codevectors. \n",
377 codebook_lookup_values);
379 codebook_delta_value, codebook_minimum_value);
381 for (
i = 0;
i < codebook_lookup_values; ++
i) {
382 codebook_multiplicands[
i] =
get_bits(gb, codebook_value_bits);
384 ff_dlog(
NULL,
" multiplicands*delta+minmum : %e \n",
385 (
float)codebook_multiplicands[
i] * codebook_delta_value + codebook_minimum_value);
386 ff_dlog(
NULL,
" multiplicand %u\n", codebook_multiplicands[
i]);
401 for (j = 0,
i = 0;
i < entries; ++
i) {
404 if (tmp_vlc_bits[
i]) {
406 unsigned lookup_offset =
i;
408 ff_dlog(vc->avctx,
"Lookup offset %u ,",
i);
410 for (k = 0; k <
dim; ++k) {
411 unsigned multiplicand_offset = lookup_offset % codebook_lookup_values;
412 codebook_setup->
codevectors[j *
dim + k] = codebook_multiplicands[multiplicand_offset] * codebook_delta_value + codebook_minimum_value + last;
413 if (codebook_sequence_p)
415 lookup_offset/=codebook_lookup_values;
417 tmp_vlc_bits[j] = tmp_vlc_bits[
i];
419 ff_dlog(vc->avctx,
"real lookup offset %u, vector: ", j);
420 for (k = 0; k <
dim; ++k)
428 if (j != used_entries) {
433 entries = used_entries;
447 for (t = 0; t < entries; ++t)
448 if (tmp_vlc_bits[t] >= codebook_setup->
maxdepth)
449 codebook_setup->
maxdepth = tmp_vlc_bits[t];
459 entries, tmp_vlc_bits,
sizeof(*tmp_vlc_bits),
460 sizeof(*tmp_vlc_bits), tmp_vlc_codes,
461 sizeof(*tmp_vlc_codes),
sizeof(*tmp_vlc_codes),
470 av_free(codebook_multiplicands);
477 av_free(codebook_multiplicands);
486 unsigned i, vorbis_time_count =
get_bits(gb, 6) + 1;
488 for (
i = 0;
i < vorbis_time_count; ++
i) {
489 unsigned vorbis_tdtransform =
get_bits(gb, 16);
491 ff_dlog(
NULL,
" Vorbis time domain transform %u: %u\n",
492 vorbis_time_count, vorbis_tdtransform);
494 if (vorbis_tdtransform) {
506 static int create_map(vorbis_context *vc,
unsigned floor_number);
514 vc->floor_count =
get_bits(gb, 6) + 1;
516 vc->floors =
av_mallocz(vc->floor_count *
sizeof(*vc->floors));
520 for (
i = 0;
i < vc->floor_count; ++
i) {
528 int maximum_class = -1;
529 unsigned rangebits, rangemax, floor1_values = 2;
543 ff_dlog(
NULL,
" %d. floor %d partition class %d \n",
548 ff_dlog(
NULL,
" maximum class %d \n", maximum_class);
550 for (j = 0; j <= maximum_class; ++j) {
554 ff_dlog(
NULL,
" %d floor %d class dim: %d subclasses %d \n",
i, j,
588 "A rangebits value of 0 is not compliant with the Vorbis I specification.\n");
591 rangemax = (1 << rangebits);
592 if (rangemax > vc->blocksize[1] / 2) {
594 "Floor value is too large for blocksize: %u (%"PRIu32
")\n",
595 rangemax, vc->blocksize[1] / 2);
605 ff_dlog(
NULL,
" %u. floor1 Y coord. %d\n", floor1_values,
617 unsigned max_codebook_dim = 0;
634 "Floor 0 bark map size is 0.\n");
653 if (vc->codebooks[book_idx].dimensions > max_codebook_dim)
654 max_codebook_dim = vc->codebooks[book_idx].dimensions;
704 vc->residue_count =
get_bits(gb, 6)+1;
705 vc->residues =
av_mallocz(vc->residue_count *
sizeof(*vc->residues));
709 ff_dlog(
NULL,
" There are %d residues. \n", vc->residue_count);
711 for (
i = 0;
i < vc->residue_count; ++
i) {
714 unsigned high_bits, low_bits;
724 if (res_setup->
begin>res_setup->
end ||
727 "partition out of bounds: type, begin, end, size, blocksize: %"PRIu16
", %"PRIu32
", %"PRIu32
", %u, %"PRIu32
"\n",
744 ff_dlog(
NULL,
" begin %"PRIu32
" end %"PRIu32
" part.size %u classif.s %"PRIu8
" classbook %"PRIu8
"\n",
753 cascade[j] = (high_bits << 3) + low_bits;
760 for (k = 0; k < 8; ++k) {
761 if (cascade[j]&(1 << k)) {
764 ff_dlog(
NULL,
" %u class cascade depth %u book: %d\n",
765 j, k, res_setup->
books[j][k]);
770 res_setup->
books[j][k] = -1;
785 vc->mapping_count =
get_bits(gb, 6)+1;
786 vc->mappings =
av_mallocz(vc->mapping_count *
sizeof(*vc->mappings));
790 ff_dlog(
NULL,
" There are %d mappings. \n", vc->mapping_count);
792 for (
i = 0;
i < vc->mapping_count; ++
i) {
796 av_log(vc->avctx,
AV_LOG_ERROR,
"Other mappings than type 0 are not compliant with the Vorbis I specification. \n");
807 if (vc->audio_channels < 2) {
809 "Square polar channel mapping with less than two channels is not compliant with the Vorbis I specification.\n");
815 sizeof(*mapping_setup->
angle));
835 if (mapping_setup->
submaps>1) {
837 sizeof(*mapping_setup->
mux));
838 if (!mapping_setup->
mux)
841 for (j = 0; j < vc->audio_channels; ++j)
845 for (j = 0; j < mapping_setup->
submaps; ++j) {
850 ff_dlog(
NULL,
" %u mapping %u submap : floor %d, residue %d\n",
i, j,
860 static int create_map(vorbis_context *vc,
unsigned floor_number)
868 for (blockflag = 0; blockflag < 2; ++blockflag) {
869 n = vc->blocksize[blockflag] / 2;
870 floors[floor_number].
data.
t0.
map[blockflag] =
872 if (!floors[floor_number].
data.t0.map[blockflag])
878 for (idx = 0; idx < n; ++idx) {
880 (
vf->bark_map_size /
BARK(
vf->rate / 2.0f)));
881 if (
vf->bark_map_size-1 <
map[idx])
882 map[idx] =
vf->bark_map_size - 1;
885 vf->map_size[blockflag] = n;
888 for (idx = 0; idx <= n; ++idx) {
889 ff_dlog(
NULL,
"floor0 map: map at pos %d is %"PRId32
"\n", idx,
map[idx]);
900 vc->mode_count =
get_bits(gb, 6) + 1;
901 vc->modes =
av_mallocz(vc->mode_count *
sizeof(*vc->modes));
905 ff_dlog(
NULL,
" There are %d modes.\n", vc->mode_count);
907 for (
i = 0;
i < vc->mode_count; ++
i) {
915 ff_dlog(
NULL,
" %u mode: blockflag %d, windowtype %d, transformtype %d, mapping %d\n",
932 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis setup header packet corrupt (no vorbis signature). \n");
937 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis setup header packet corrupt (codebooks). \n");
941 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis setup header packet corrupt (time domain transforms). \n");
949 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis setup header packet corrupt (residues). \n");
953 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis setup header packet corrupt (mappings). \n");
961 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis setup header packet corrupt (framing flag). \n");
980 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis id header packet corrupt (no vorbis signature). \n");
985 vc->audio_channels =
get_bits(gb, 8);
986 if (vc->audio_channels <= 0) {
991 if (vc->audio_samplerate <= 0) {
1000 if (bl0 > 13 || bl0 < 6 || bl1 > 13 || bl1 < 6 || bl1 < bl0) {
1001 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis id header packet corrupt (illegal blocksize). \n");
1004 vc->blocksize[0] = (1 << bl0);
1005 vc->blocksize[1] = (1 << bl1);
1010 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis id header packet corrupt (framing flag not set). \n");
1014 vc->channel_residues =
av_malloc_array(vc->blocksize[1] / 2, vc->audio_channels *
sizeof(*vc->channel_residues));
1015 vc->saved =
av_calloc(vc->blocksize[1] / 4, vc->audio_channels *
sizeof(*vc->saved));
1016 if (!vc->channel_residues || !vc->saved)
1019 vc->previous_window = -1;
1022 vc->blocksize[0] >> 1, &
scale, 0);
1027 vc->blocksize[1] >> 1, &
scale, 0);
1035 ff_dlog(
NULL,
" vorbis version %"PRIu32
" \n audio_channels %"PRIu8
" \n audio_samplerate %"PRIu32
" \n bitrate_max %"PRIu32
" \n bitrate_nom %"PRIu32
" \n bitrate_min %"PRIu32
" \n blk_0 %"PRIu32
" blk_1 %"PRIu32
" \n ",
1036 vc->version, vc->audio_channels, vc->audio_samplerate, vc->bitrate_maximum, vc->bitrate_nominal, vc->bitrate_minimum, vc->blocksize[0], vc->blocksize[1]);
1055 const uint8_t *header_start[3];
1077 if (hdr_type != 1) {
1089 if (hdr_type != 5) {
1101 if (vc->audio_channels > 8) {
1121 float *lsp =
vf->lsp;
1124 unsigned blockflag = vc->modes[vc->mode_number].blockflag;
1126 if (!
vf->amplitude_bits)
1130 if (amplitude > 0) {
1132 unsigned idx, lsp_len = 0;
1136 if (book_idx >=
vf->num_books) {
1140 ff_dlog(
NULL,
"floor0 dec: booknumber: %u\n", book_idx);
1141 codebook = vc->codebooks[
vf->book_list[book_idx]];
1146 while (lsp_len<vf->order) {
1157 ff_dlog(
NULL,
"floor0 dec: vector offset: %d\n", vec_off);
1159 for (idx = 0; idx <
codebook.dimensions; ++idx)
1160 lsp[lsp_len+idx] =
codebook.codevectors[vec_off+idx] + last;
1161 last = lsp[lsp_len+idx-1];
1168 for (idx = 0; idx < lsp_len; ++idx)
1169 ff_dlog(
NULL,
"floor0 dec: coeff at %d is %f\n", idx, lsp[idx]);
1175 int order =
vf->order;
1176 float wstep =
M_PI /
vf->bark_map_size;
1178 for (
i = 0;
i < order;
i++)
1179 lsp[
i] = 2.0
f * cos(lsp[
i]);
1181 ff_dlog(
NULL,
"floor0 synth: map_size = %"PRIu32
"; m = %d; wstep = %f\n",
1182 vf->map_size[blockflag], order, wstep);
1185 while (i < vf->map_size[blockflag]) {
1186 int j, iter_cond =
vf->map[blockflag][
i];
1189 float two_cos_w = 2.0f * cos(wstep * iter_cond);
1192 for (j = 0; j + 1 < order; j += 2) {
1193 q *= lsp[j] - two_cos_w;
1194 p *= lsp[j + 1] - two_cos_w;
1197 p *= p * (2.0f - two_cos_w);
1198 q *= q * (2.0f + two_cos_w);
1200 q *= two_cos_w-lsp[j];
1203 p *= p * (4.f - two_cos_w * two_cos_w);
1211 q =
exp((((amplitude*
vf->amplitude_offset) /
1212 (((1ULL <<
vf->amplitude_bits) - 1) * sqrt(p + q)))
1213 -
vf->amplitude_offset) * .11512925f);
1218 }
while (
vf->map[blockflag][
i] == iter_cond);
1236 uint16_t range_v[4] = { 256, 128, 86, 64 };
1237 unsigned range = range_v[
vf->multiplier - 1];
1238 uint16_t floor1_Y[258];
1239 uint16_t floor1_Y_final[258];
1240 int floor1_flag[258];
1241 unsigned partition_class, cdim, cbits, csub, cval,
offset,
i, j;
1242 int book, adx, ady, dy, off, predicted, err;
1253 ff_dlog(
NULL,
"floor 0 Y %d floor 1 Y %d \n", floor1_Y[0], floor1_Y[1]);
1256 for (
i = 0;
i <
vf->partitions; ++
i) {
1257 partition_class =
vf->partition_class[
i];
1258 cdim =
vf->class_dimensions[partition_class];
1259 cbits =
vf->class_subclasses[partition_class];
1260 csub = (1 << cbits) - 1;
1266 cval =
get_vlc2(gb, vc->codebooks[
vf->class_masterbook[partition_class]].vlc.table,
1267 vc->codebooks[
vf->class_masterbook[partition_class]].nb_bits, 3);
1269 for (j = 0; j < cdim; ++j) {
1270 book =
vf->subclass_books[partition_class][cval & csub];
1272 ff_dlog(
NULL,
"book %d Cbits %u cval %u bits:%d\n",
1275 cval = cval >> cbits;
1277 int v =
get_vlc2(gb, vc->codebooks[book].vlc.table,
1278 vc->codebooks[book].nb_bits, 3);
1296 floor1_Y_final[0] = floor1_Y[0];
1297 floor1_Y_final[1] = floor1_Y[1];
1299 for (
i = 2;
i <
vf->x_list_dim; ++
i) {
1300 unsigned val, highroom, lowroom, room, high_neigh_offs, low_neigh_offs;
1302 low_neigh_offs =
vf->list[
i].low;
1303 high_neigh_offs =
vf->list[
i].high;
1304 dy = floor1_Y_final[high_neigh_offs] - floor1_Y_final[low_neigh_offs];
1305 adx =
vf->list[high_neigh_offs].x -
vf->list[low_neigh_offs].x;
1307 err = ady * (
vf->list[
i].x -
vf->list[low_neigh_offs].x);
1310 predicted = floor1_Y_final[low_neigh_offs] - off;
1312 predicted = floor1_Y_final[low_neigh_offs] + off;
1316 highroom =
range-predicted;
1317 lowroom = predicted;
1318 if (highroom < lowroom) {
1319 room = highroom * 2;
1324 floor1_flag[low_neigh_offs] = 1;
1325 floor1_flag[high_neigh_offs] = 1;
1328 if (highroom > lowroom) {
1345 ff_dlog(
NULL,
" Decoded floor(%d) = %u / val %u\n",
1346 vf->list[
i].x, floor1_Y_final[
i],
val);
1360 uint8_t *do_not_decode,
1362 int partition_count,
1368 unsigned c_p_c =
codebook->dimensions;
1371 for (p = 0, j = 0; j < ch_used; ++j) {
1372 if (!do_not_decode[j]) {
1382 "Invalid vlc code decoding %d channel.", j);
1387 for (
i = partition_count + c_p_c - 1;
i >= partition_count;
i--) {
1388 if (
i < ptns_to_read)
1392 for (
i = partition_count + c_p_c - 1;
i >= partition_count;
i--) {
1393 temp2 = (((uint64_t)
temp) * inverse_class) >> 32;
1395 if (
i < ptns_to_read)
1410 uint8_t *do_not_decode,
1417 unsigned c_p_c = vc->codebooks[vr->
classbook].dimensions;
1419 unsigned pass, ch_used,
i, j, k, l;
1420 unsigned max_output = (ch - 1) * vlen;
1422 int libvorbis_bug = 0;
1425 for (j = 1; j < ch; ++j)
1426 do_not_decode[0] &= do_not_decode[j];
1427 if (do_not_decode[0])
1430 max_output += vr->
end / ch;
1433 max_output += vr->
end;
1436 if (max_output > ch_left * vlen) {
1437 if (max_output <= ch_left * vlen + vr->partition_size*ch_used/ch) {
1446 ff_dlog(
NULL,
" residue type 0/1/2 decode begin, ch: %d cpc %d \n", ch, c_p_c);
1448 for (pass = 0; pass <= vr->
maxpass; ++pass) {
1449 int voffset, partition_count, j_times_ptns_to_read;
1451 voffset = vr->
begin;
1452 for (partition_count = 0; partition_count < ptns_to_read;) {
1454 int ret =
setup_classifs(vc, vr, do_not_decode, ch_used, partition_count, ptns_to_read);
1458 for (
i = 0; (
i < c_p_c) && (partition_count < ptns_to_read); ++
i) {
1459 for (j_times_ptns_to_read = 0, j = 0; j < ch_used; ++j) {
1462 if (!do_not_decode[j]) {
1463 unsigned vqclass = classifs[j_times_ptns_to_read + partition_count];
1464 int vqbook = vr->
books[vqclass][pass];
1466 if (vqbook >= 0 && vc->codebooks[vqbook].codevectors) {
1468 unsigned dim = vc->codebooks[vqbook].dimensions;
1477 voffs = voffset+j*vlen;
1478 for (k = 0; k <
step; ++k) {
1483 for (l = 0; l <
dim; ++l)
1484 vec[voffs + k + l *
step] +=
codebook.codevectors[coffs + l];
1486 }
else if (vr_type == 1) {
1487 voffs = voffset + j * vlen;
1488 for (k = 0; k <
step; ++k) {
1493 for (l = 0; l <
dim; ++l, ++voffs) {
1494 vec[voffs]+=
codebook.codevectors[coffs+l];
1496 ff_dlog(
NULL,
" pass %d offs: %d curr: %f change: %f cv offs.: %d \n",
1497 pass, voffs, vec[voffs],
codebook.codevectors[coffs+l], coffs);
1500 }
else if (vr_type == 2 && ch == 2 && (voffset & 1) == 0 && (
dim & 1) == 0) {
1501 voffs = voffset >> 1;
1504 for (k = 0; k <
step; ++k) {
1509 vec[voffs + k ] +=
codebook.codevectors[coffs ];
1510 vec[voffs + k + vlen] +=
codebook.codevectors[coffs + 1];
1512 }
else if (
dim == 4) {
1513 for (k = 0; k <
step; ++k, voffs += 2) {
1518 vec[voffs ] +=
codebook.codevectors[coffs ];
1519 vec[voffs + 1 ] +=
codebook.codevectors[coffs + 2];
1520 vec[voffs + vlen ] +=
codebook.codevectors[coffs + 1];
1521 vec[voffs + vlen + 1] +=
codebook.codevectors[coffs + 3];
1524 for (k = 0; k <
step; ++k) {
1529 for (l = 0; l <
dim; l += 2, voffs++) {
1530 vec[voffs ] +=
codebook.codevectors[coffs + l ];
1531 vec[voffs + vlen] +=
codebook.codevectors[coffs + l + 1];
1533 ff_dlog(
NULL,
" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n",
1534 pass, voffset / ch + (voffs % ch) * vlen,
1535 vec[voffset / ch + (voffs % ch) * vlen],
1536 codebook.codevectors[coffs + l], coffs, l);
1540 }
else if (vr_type == 2) {
1541 unsigned voffs_div = ch == 1 ? voffset :
FASTDIV(voffset, ch);
1542 unsigned voffs_mod = voffset - voffs_div * ch;
1544 for (k = 0; k <
step; ++k) {
1549 for (l = 0; l <
dim; ++l) {
1550 vec[voffs_div + voffs_mod * vlen] +=
1553 ff_dlog(
NULL,
" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n",
1554 pass, voffs_div + voffs_mod * vlen,
1555 vec[voffs_div + voffs_mod * vlen],
1556 codebook.codevectors[coffs + l], coffs, l);
1558 if (++voffs_mod == ch) {
1567 j_times_ptns_to_read += ptns_to_read;
1573 if (libvorbis_bug && !pass) {
1574 for (j = 0; j < ch_used; ++j) {
1575 if (!do_not_decode[j]) {
1577 vc->codebooks[vr->
classbook].nb_bits, 3);
1587 uint8_t *do_not_decode,
1588 float *vec,
unsigned vlen,
1593 else if (vr->
type == 1)
1595 else if (vr->
type == 0)
1610 int previous_window = vc->previous_window;
1611 unsigned mode_number, blockflag, blocksize;
1613 uint8_t no_residue[255];
1614 uint8_t do_not_decode[255];
1616 float *ch_res_ptr = vc->channel_residues;
1617 uint8_t res_chan[255];
1618 unsigned res_num = 0;
1620 unsigned ch_left = vc->audio_channels;
1628 if (vc->mode_count == 1) {
1633 vc->mode_number = mode_number;
1634 mapping = &vc->mappings[vc->modes[mode_number].mapping];
1636 ff_dlog(
NULL,
" Mode number: %u , mapping: %d , blocktype %d\n", mode_number,
1637 vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag);
1639 blockflag = vc->modes[mode_number].blockflag;
1640 blocksize = vc->blocksize[blockflag];
1641 vlen = blocksize / 2;
1644 if (previous_window < 0)
1645 previous_window =
code>>1;
1646 }
else if (previous_window < 0)
1647 previous_window = 0;
1649 memset(ch_res_ptr, 0,
sizeof(
float) * vc->audio_channels * vlen);
1650 for (
i = 0;
i < vc->audio_channels; ++
i)
1651 memset(floor_ptr[
i], 0, vlen *
sizeof(floor_ptr[0][0]));
1655 for (
i = 0;
i < vc->audio_channels; ++
i) {
1670 no_residue[
i] =
ret;
1676 if (!(no_residue[mapping->
magnitude[
i]] & no_residue[mapping->
angle[
i]])) {
1678 no_residue[mapping->
angle[
i]] = 0;
1689 for (j = 0; j < vc->audio_channels; ++j) {
1690 if ((mapping->
submaps == 1) || (
i == mapping->
mux[j])) {
1691 res_chan[j] = res_num;
1692 if (no_residue[j]) {
1693 do_not_decode[ch] = 1;
1695 do_not_decode[ch] = 0;
1712 ch_res_ptr += ch * vlen;
1724 mag = vc->channel_residues+res_chan[mapping->
magnitude[
i]] * blocksize / 2;
1725 ang = vc->channel_residues+res_chan[mapping->
angle[
i]] * blocksize / 2;
1726 vc->dsp.vorbis_inverse_coupling(mag, ang, blocksize / 2);
1731 mdct = vc->mdct[blockflag];
1732 mdct_fn = vc->mdct_fn[blockflag];
1734 for (j = vc->audio_channels-1;j >= 0; j--) {
1735 ch_res_ptr = vc->channel_residues + res_chan[j] * blocksize / 2;
1736 vc->fdsp->vector_fmul(floor_ptr[j], floor_ptr[j], ch_res_ptr, blocksize / 2);
1737 mdct_fn(mdct, ch_res_ptr, floor_ptr[j],
sizeof(
float));
1742 retlen = (blocksize + vc->blocksize[previous_window]) / 4;
1743 for (j = 0; j < vc->audio_channels; j++) {
1744 unsigned bs0 = vc->blocksize[0];
1745 unsigned bs1 = vc->blocksize[1];
1746 float *residue = vc->channel_residues + res_chan[j] * blocksize / 2;
1747 float *saved = vc->saved + j * bs1 / 4;
1748 float *
ret = floor_ptr[j];
1749 float *buf = residue;
1750 const float *
win = vc->win[blockflag & previous_window];
1752 if (blockflag == previous_window) {
1753 vc->fdsp->vector_fmul_window(
ret, saved, buf,
win, blocksize / 4);
1754 }
else if (blockflag > previous_window) {
1755 vc->fdsp->vector_fmul_window(
ret, saved, buf,
win, bs0 / 4);
1756 memcpy(
ret+bs0/2, buf+bs0/4, ((bs1-bs0)/4) *
sizeof(
float));
1758 memcpy(
ret, saved, ((bs1 - bs0) / 4) *
sizeof(
float));
1759 vc->fdsp->vector_fmul_window(
ret + (bs1 - bs0) / 4, saved + (bs1 - bs0) / 4, buf,
win, bs0 / 4);
1761 memcpy(saved, buf + blocksize / 4, blocksize / 4 *
sizeof(
float));
1764 vc->previous_window = blockflag;
1771 int *got_frame_ptr,
AVPacket *avpkt)
1773 const uint8_t *buf = avpkt->
data;
1774 int buf_size = avpkt->
size;
1777 float *channel_ptrs[255];
1782 if (*buf == 1 && buf_size > 7) {
1794 if (vc->audio_channels > 8) {
1805 if (*buf == 3 && buf_size > 7) {
1810 if (*buf == 5 && buf_size > 7 && vc->channel_residues && !vc->modes) {
1822 if (!vc->channel_residues || !vc->modes) {
1828 frame->nb_samples = vc->blocksize[1] / 2;
1832 if (vc->audio_channels > 8) {
1833 for (
i = 0;
i < vc->audio_channels;
i++)
1834 channel_ptrs[
i] = (
float *)
frame->extended_data[
i];
1836 for (
i = 0;
i < vc->audio_channels;
i++) {
1838 channel_ptrs[ch] = (
float *)
frame->extended_data[
i];
1848 if (!vc->first_frame) {
1849 vc->first_frame = 1;
1853 ff_dlog(
NULL,
"parsed %d bytes %d bits, returned %d samples (*ch*bits) \n",
1878 memset(vc->saved, 0, (vc->blocksize[1] / 4) * vc->audio_channels *
1879 sizeof(*vc->saved));
1881 vc->previous_window = -1;
1882 vc->first_frame = 0;
1890 .priv_data_size =
sizeof(vorbis_context),