35 #define BITSTREAM_READER_LE
47 #define V_MAX_VLCS (1 << 16)
48 #define V_MAX_PARTITIONS (1 << 20)
161 (13.1f * atan(0.00074f * (x)) + 2.24f * atan(1.85e-8f * (x) * (x)) + 1e-4f * (x))
163 static const char idx_err_str[] =
"Index value %d out of range (0 - %d) for %s at %s:%i\n";
164 #define VALIDATE_INDEX(idx, limit) \
166 av_log(vc->avctx, AV_LOG_ERROR,\
168 (int)(idx), (int)(limit - 1), #idx, __FILE__, __LINE__);\
169 return AVERROR_INVALIDDATA;\
171 #define GET_VALIDATED_INDEX(idx, bits, limit) \
173 idx = get_bits(gb, bits);\
174 VALIDATE_INDEX(idx, limit)\
179 double mant =
val & 0x1fffff;
180 long exp = (
val & 0x7fe00000
L) >> 21;
181 if (
val & 0x80000000)
183 return ldexp(mant,
exp - 20 - 768);
198 for (
i = 0;
i < vc->residue_count;
i++)
207 for (
i = 0;
i < vc->codebook_count; ++
i) {
214 for (
i = 0;
i < vc->floor_count; ++
i) {
215 if (vc->floors[
i].floor_type == 0) {
218 av_freep(&vc->floors[
i].data.t0.book_list);
227 for (
i = 0;
i < vc->mapping_count; ++
i) {
242 uint8_t *tmp_vlc_bits =
NULL;
243 uint32_t *tmp_vlc_codes =
NULL;
245 uint16_t *codebook_multiplicands =
NULL;
248 vc->codebook_count =
get_bits(gb, 8) + 1;
250 ff_dlog(
NULL,
" Codebooks: %d \n", vc->codebook_count);
252 vc->codebooks =
av_mallocz(vc->codebook_count *
sizeof(*vc->codebooks));
256 if (!vc->codebooks ||
257 !tmp_vlc_bits || !tmp_vlc_codes || !codebook_multiplicands) {
262 for (
cb = 0;
cb < vc->codebook_count; ++
cb) {
264 unsigned ordered, t, entries, used_entries = 0;
270 " %u. Codebook setup data corrupt.\n",
cb);
278 " %u. Codebook's dimension is invalid (%d).\n",
286 " %u. Codebook has too many entries (%u).\n",
294 ff_dlog(
NULL,
" codebook_dimensions %d, codebook_entries %u\n",
307 for (ce = 0; ce < entries; ++ce) {
310 tmp_vlc_bits[ce] =
get_bits(gb, 5) + 1;
313 tmp_vlc_bits[ce] = 0;
318 used_entries = entries;
319 for (ce = 0; ce < entries; ++ce)
320 tmp_vlc_bits[ce] =
get_bits(gb, 5) + 1;
323 unsigned current_entry = 0;
324 unsigned current_length =
get_bits(gb, 5) + 1;
326 ff_dlog(
NULL,
" ordered, current length: %u\n", current_length);
328 used_entries = entries;
329 for (; current_entry < used_entries && current_length <= 32; ++current_length) {
338 for (
i = current_entry;
i < number+current_entry; ++
i)
339 if (
i < used_entries)
340 tmp_vlc_bits[
i] = current_length;
342 current_entry+=number;
344 if (current_entry>used_entries) {
364 unsigned codebook_value_bits =
get_bits(gb, 4) + 1;
365 unsigned codebook_sequence_p =
get_bits1(gb);
367 ff_dlog(
NULL,
" We expect %d numbers for building the codevectors. \n",
368 codebook_lookup_values);
370 codebook_delta_value, codebook_minimum_value);
372 for (
i = 0;
i < codebook_lookup_values; ++
i) {
373 codebook_multiplicands[
i] =
get_bits(gb, codebook_value_bits);
375 ff_dlog(
NULL,
" multiplicands*delta+minmum : %e \n",
376 (
float)codebook_multiplicands[
i] * codebook_delta_value + codebook_minimum_value);
377 ff_dlog(
NULL,
" multiplicand %u\n", codebook_multiplicands[
i]);
392 for (j = 0,
i = 0;
i < entries; ++
i) {
395 if (tmp_vlc_bits[
i]) {
397 unsigned lookup_offset =
i;
399 ff_dlog(vc->avctx,
"Lookup offset %u ,",
i);
401 for (k = 0; k <
dim; ++k) {
402 unsigned multiplicand_offset = lookup_offset % codebook_lookup_values;
403 codebook_setup->
codevectors[j *
dim + k] = codebook_multiplicands[multiplicand_offset] * codebook_delta_value + codebook_minimum_value + last;
404 if (codebook_sequence_p)
406 lookup_offset/=codebook_lookup_values;
408 tmp_vlc_bits[j] = tmp_vlc_bits[
i];
410 ff_dlog(vc->avctx,
"real lookup offset %u, vector: ", j);
411 for (k = 0; k <
dim; ++k)
419 if (j != used_entries) {
424 entries = used_entries;
438 for (t = 0; t < entries; ++t)
439 if (tmp_vlc_bits[t] >= codebook_setup->
maxdepth)
440 codebook_setup->
maxdepth = tmp_vlc_bits[t];
450 entries, tmp_vlc_bits,
sizeof(*tmp_vlc_bits),
451 sizeof(*tmp_vlc_bits), tmp_vlc_codes,
452 sizeof(*tmp_vlc_codes),
sizeof(*tmp_vlc_codes),
461 av_free(codebook_multiplicands);
468 av_free(codebook_multiplicands);
477 unsigned i, vorbis_time_count =
get_bits(gb, 6) + 1;
479 for (
i = 0;
i < vorbis_time_count; ++
i) {
480 unsigned vorbis_tdtransform =
get_bits(gb, 16);
482 ff_dlog(
NULL,
" Vorbis time domain transform %u: %u\n",
483 vorbis_time_count, vorbis_tdtransform);
485 if (vorbis_tdtransform) {
497 static int create_map(vorbis_context *vc,
unsigned floor_number);
505 vc->floor_count =
get_bits(gb, 6) + 1;
507 vc->floors =
av_mallocz(vc->floor_count *
sizeof(*vc->floors));
511 for (
i = 0;
i < vc->floor_count; ++
i) {
519 int maximum_class = -1;
520 unsigned rangebits, rangemax, floor1_values = 2;
534 ff_dlog(
NULL,
" %d. floor %d partition class %d \n",
539 ff_dlog(
NULL,
" maximum class %d \n", maximum_class);
541 for (j = 0; j <= maximum_class; ++j) {
545 ff_dlog(
NULL,
" %d floor %d class dim: %d subclasses %d \n",
i, j,
579 "A rangebits value of 0 is not compliant with the Vorbis I specification.\n");
582 rangemax = (1 << rangebits);
583 if (rangemax > vc->blocksize[1] / 2) {
585 "Floor value is too large for blocksize: %u (%"PRIu32
")\n",
586 rangemax, vc->blocksize[1] / 2);
596 ff_dlog(
NULL,
" %u. floor1 Y coord. %d\n", floor1_values,
608 unsigned max_codebook_dim = 0;
625 "Floor 0 bark map size is 0.\n");
644 if (vc->codebooks[book_idx].dimensions > max_codebook_dim)
645 max_codebook_dim = vc->codebooks[book_idx].dimensions;
695 vc->residue_count =
get_bits(gb, 6)+1;
696 vc->residues =
av_mallocz(vc->residue_count *
sizeof(*vc->residues));
700 ff_dlog(
NULL,
" There are %d residues. \n", vc->residue_count);
702 for (
i = 0;
i < vc->residue_count; ++
i) {
705 unsigned high_bits, low_bits;
715 if (res_setup->
begin>res_setup->
end ||
718 "partition out of bounds: type, begin, end, size, blocksize: %"PRIu16
", %"PRIu32
", %"PRIu32
", %u, %"PRIu32
"\n",
735 ff_dlog(
NULL,
" begin %"PRIu32
" end %"PRIu32
" part.size %u classif.s %"PRIu8
" classbook %"PRIu8
"\n",
744 cascade[j] = (high_bits << 3) + low_bits;
751 for (k = 0; k < 8; ++k) {
752 if (cascade[j]&(1 << k)) {
755 ff_dlog(
NULL,
" %u class cascade depth %u book: %d\n",
756 j, k, res_setup->
books[j][k]);
761 res_setup->
books[j][k] = -1;
776 vc->mapping_count =
get_bits(gb, 6)+1;
777 vc->mappings =
av_mallocz(vc->mapping_count *
sizeof(*vc->mappings));
781 ff_dlog(
NULL,
" There are %d mappings. \n", vc->mapping_count);
783 for (
i = 0;
i < vc->mapping_count; ++
i) {
787 av_log(vc->avctx,
AV_LOG_ERROR,
"Other mappings than type 0 are not compliant with the Vorbis I specification. \n");
798 if (vc->audio_channels < 2) {
800 "Square polar channel mapping with less than two channels is not compliant with the Vorbis I specification.\n");
806 sizeof(*mapping_setup->
angle));
826 if (mapping_setup->
submaps>1) {
828 sizeof(*mapping_setup->
mux));
829 if (!mapping_setup->
mux)
832 for (j = 0; j < vc->audio_channels; ++j)
836 for (j = 0; j < mapping_setup->
submaps; ++j) {
841 ff_dlog(
NULL,
" %u mapping %u submap : floor %d, residue %d\n",
i, j,
851 static int create_map(vorbis_context *vc,
unsigned floor_number)
859 for (blockflag = 0; blockflag < 2; ++blockflag) {
860 n = vc->blocksize[blockflag] / 2;
861 floors[floor_number].
data.
t0.
map[blockflag] =
863 if (!floors[floor_number].
data.t0.map[blockflag])
867 vf = &floors[floor_number].
data.
t0;
869 for (idx = 0; idx < n; ++idx) {
871 (vf->bark_map_size /
BARK(vf->rate / 2.0f)));
872 if (vf->bark_map_size-1 <
map[idx])
873 map[idx] = vf->bark_map_size - 1;
876 vf->map_size[blockflag] = n;
879 for (idx = 0; idx <= n; ++idx) {
880 ff_dlog(
NULL,
"floor0 map: map at pos %d is %"PRId32
"\n", idx,
map[idx]);
891 vc->mode_count =
get_bits(gb, 6) + 1;
892 vc->modes =
av_mallocz(vc->mode_count *
sizeof(*vc->modes));
896 ff_dlog(
NULL,
" There are %d modes.\n", vc->mode_count);
898 for (
i = 0;
i < vc->mode_count; ++
i) {
906 ff_dlog(
NULL,
" %u mode: blockflag %d, windowtype %d, transformtype %d, mapping %d\n",
923 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis setup header packet corrupt (no vorbis signature). \n");
928 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis setup header packet corrupt (codebooks). \n");
932 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis setup header packet corrupt (time domain transforms). \n");
940 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis setup header packet corrupt (residues). \n");
944 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis setup header packet corrupt (mappings). \n");
952 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis setup header packet corrupt (framing flag). \n");
969 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis id header packet corrupt (no vorbis signature). \n");
974 vc->audio_channels =
get_bits(gb, 8);
975 if (vc->audio_channels <= 0) {
980 if (vc->audio_samplerate <= 0) {
989 if (bl0 > 13 || bl0 < 6 || bl1 > 13 || bl1 < 6 || bl1 < bl0) {
990 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis id header packet corrupt (illegal blocksize). \n");
993 vc->blocksize[0] = (1 << bl0);
994 vc->blocksize[1] = (1 << bl1);
999 av_log(vc->avctx,
AV_LOG_ERROR,
" Vorbis id header packet corrupt (framing flag not set). \n");
1003 vc->channel_residues =
av_malloc_array(vc->blocksize[1] / 2, vc->audio_channels *
sizeof(*vc->channel_residues));
1004 vc->saved =
av_calloc(vc->blocksize[1] / 4, vc->audio_channels *
sizeof(*vc->saved));
1005 if (!vc->channel_residues || !vc->saved)
1008 vc->previous_window = -1;
1016 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 ",
1017 vc->version, vc->audio_channels, vc->audio_samplerate, vc->bitrate_maximum, vc->bitrate_nominal, vc->bitrate_minimum, vc->blocksize[0], vc->blocksize[1]);
1036 const uint8_t *header_start[3];
1058 if (hdr_type != 1) {
1070 if (hdr_type != 5) {
1082 if (vc->audio_channels > 8) {
1102 float *lsp = vf->lsp;
1105 unsigned blockflag = vc->modes[vc->mode_number].blockflag;
1107 if (!vf->amplitude_bits)
1110 amplitude =
get_bits64(&vc->gb, vf->amplitude_bits);
1111 if (amplitude > 0) {
1113 unsigned idx, lsp_len = 0;
1117 if (book_idx >= vf->num_books) {
1121 ff_dlog(
NULL,
"floor0 dec: booknumber: %u\n", book_idx);
1122 codebook = vc->codebooks[vf->book_list[book_idx]];
1127 while (lsp_len<vf->order) {
1138 ff_dlog(
NULL,
"floor0 dec: vector offset: %d\n", vec_off);
1140 for (idx = 0; idx <
codebook.dimensions; ++idx)
1141 lsp[lsp_len+idx] =
codebook.codevectors[vec_off+idx] + last;
1142 last = lsp[lsp_len+idx-1];
1149 for (idx = 0; idx < lsp_len; ++idx)
1150 ff_dlog(
NULL,
"floor0 dec: coeff at %d is %f\n", idx, lsp[idx]);
1156 int order = vf->order;
1157 float wstep =
M_PI / vf->bark_map_size;
1159 for (
i = 0;
i < order;
i++)
1160 lsp[
i] = 2.0
f * cos(lsp[
i]);
1162 ff_dlog(
NULL,
"floor0 synth: map_size = %"PRIu32
"; m = %d; wstep = %f\n",
1163 vf->map_size[blockflag], order, wstep);
1166 while (i < vf->map_size[blockflag]) {
1167 int j, iter_cond = vf->map[blockflag][
i];
1170 float two_cos_w = 2.0f * cos(wstep * iter_cond);
1173 for (j = 0; j + 1 < order; j += 2) {
1174 q *= lsp[j] - two_cos_w;
1175 p *= lsp[j + 1] - two_cos_w;
1178 p *= p * (2.0f - two_cos_w);
1179 q *= q * (2.0f + two_cos_w);
1181 q *= two_cos_w-lsp[j];
1184 p *= p * (4.f - two_cos_w * two_cos_w);
1192 q =
exp((((amplitude*vf->amplitude_offset) /
1193 (((1ULL << vf->amplitude_bits) - 1) * sqrt(p + q)))
1194 - vf->amplitude_offset) * .11512925f);
1199 }
while (vf->map[blockflag][
i] == iter_cond);
1217 uint16_t range_v[4] = { 256, 128, 86, 64 };
1218 unsigned range = range_v[vf->multiplier - 1];
1219 uint16_t floor1_Y[258];
1220 uint16_t floor1_Y_final[258];
1221 int floor1_flag[258];
1222 unsigned partition_class, cdim, cbits, csub, cval,
offset,
i, j;
1223 int book, adx, ady, dy, off, predicted, err;
1234 ff_dlog(
NULL,
"floor 0 Y %d floor 1 Y %d \n", floor1_Y[0], floor1_Y[1]);
1237 for (
i = 0;
i < vf->partitions; ++
i) {
1238 partition_class = vf->partition_class[
i];
1239 cdim = vf->class_dimensions[partition_class];
1240 cbits = vf->class_subclasses[partition_class];
1241 csub = (1 << cbits) - 1;
1247 cval =
get_vlc2(gb, vc->codebooks[vf->class_masterbook[partition_class]].vlc.table,
1248 vc->codebooks[vf->class_masterbook[partition_class]].nb_bits, 3);
1250 for (j = 0; j < cdim; ++j) {
1251 book = vf->subclass_books[partition_class][cval & csub];
1253 ff_dlog(
NULL,
"book %d Cbits %u cval %u bits:%d\n",
1256 cval = cval >> cbits;
1258 int v =
get_vlc2(gb, vc->codebooks[book].vlc.table,
1259 vc->codebooks[book].nb_bits, 3);
1277 floor1_Y_final[0] = floor1_Y[0];
1278 floor1_Y_final[1] = floor1_Y[1];
1280 for (
i = 2;
i < vf->x_list_dim; ++
i) {
1281 unsigned val, highroom, lowroom, room, high_neigh_offs, low_neigh_offs;
1283 low_neigh_offs = vf->list[
i].low;
1284 high_neigh_offs = vf->list[
i].high;
1285 dy = floor1_Y_final[high_neigh_offs] - floor1_Y_final[low_neigh_offs];
1286 adx = vf->list[high_neigh_offs].x - vf->list[low_neigh_offs].x;
1288 err = ady * (vf->list[
i].x - vf->list[low_neigh_offs].x);
1291 predicted = floor1_Y_final[low_neigh_offs] - off;
1293 predicted = floor1_Y_final[low_neigh_offs] + off;
1297 highroom = range-predicted;
1298 lowroom = predicted;
1299 if (highroom < lowroom) {
1300 room = highroom * 2;
1305 floor1_flag[low_neigh_offs] = 1;
1306 floor1_flag[high_neigh_offs] = 1;
1309 if (highroom > lowroom) {
1326 ff_dlog(
NULL,
" Decoded floor(%d) = %u / val %u\n",
1327 vf->list[
i].x, floor1_Y_final[
i],
val);
1341 uint8_t *do_not_decode,
1343 int partition_count,
1349 unsigned c_p_c =
codebook->dimensions;
1352 for (p = 0, j = 0; j < ch_used; ++j) {
1353 if (!do_not_decode[j]) {
1363 "Invalid vlc code decoding %d channel.", j);
1368 for (
i = partition_count + c_p_c - 1;
i >= partition_count;
i--) {
1369 if (
i < ptns_to_read)
1373 for (
i = partition_count + c_p_c - 1;
i >= partition_count;
i--) {
1374 temp2 = (((uint64_t)
temp) * inverse_class) >> 32;
1376 if (
i < ptns_to_read)
1391 uint8_t *do_not_decode,
1398 unsigned c_p_c = vc->codebooks[vr->
classbook].dimensions;
1400 unsigned pass, ch_used,
i, j, k, l;
1401 unsigned max_output = (ch - 1) * vlen;
1403 int libvorbis_bug = 0;
1406 for (j = 1; j < ch; ++j)
1407 do_not_decode[0] &= do_not_decode[j];
1408 if (do_not_decode[0])
1411 max_output += vr->
end / ch;
1414 max_output += vr->
end;
1417 if (max_output > ch_left * vlen) {
1418 if (max_output <= ch_left * vlen + vr->partition_size*ch_used/ch) {
1427 ff_dlog(
NULL,
" residue type 0/1/2 decode begin, ch: %d cpc %d \n", ch, c_p_c);
1430 int voffset, partition_count, j_times_ptns_to_read;
1432 voffset = vr->
begin;
1433 for (partition_count = 0; partition_count < ptns_to_read;) {
1435 int ret =
setup_classifs(vc, vr, do_not_decode, ch_used, partition_count, ptns_to_read);
1439 for (
i = 0; (
i < c_p_c) && (partition_count < ptns_to_read); ++
i) {
1440 for (j_times_ptns_to_read = 0, j = 0; j < ch_used; ++j) {
1443 if (!do_not_decode[j]) {
1444 unsigned vqclass = classifs[j_times_ptns_to_read + partition_count];
1447 if (vqbook >= 0 && vc->codebooks[vqbook].codevectors) {
1449 unsigned dim = vc->codebooks[vqbook].dimensions;
1455 voffs = voffset+j*vlen;
1456 for (k = 0; k <
step; ++k) {
1461 for (l = 0; l <
dim; ++l)
1462 vec[voffs + k + l *
step] +=
codebook.codevectors[coffs + l];
1464 }
else if (vr_type == 1) {
1465 voffs = voffset + j * vlen;
1466 for (k = 0; k <
step; ++k) {
1471 for (l = 0; l <
dim; ++l, ++voffs) {
1472 vec[voffs]+=
codebook.codevectors[coffs+l];
1474 ff_dlog(
NULL,
" pass %d offs: %d curr: %f change: %f cv offs.: %d \n",
1475 pass, voffs, vec[voffs],
codebook.codevectors[coffs+l], coffs);
1478 }
else if (vr_type == 2 && ch == 2 && (voffset & 1) == 0 && (
dim & 1) == 0) {
1479 voffs = voffset >> 1;
1482 for (k = 0; k <
step; ++k) {
1487 vec[voffs + k ] +=
codebook.codevectors[coffs ];
1488 vec[voffs + k + vlen] +=
codebook.codevectors[coffs + 1];
1490 }
else if (
dim == 4) {
1491 for (k = 0; k <
step; ++k, voffs += 2) {
1496 vec[voffs ] +=
codebook.codevectors[coffs ];
1497 vec[voffs + 1 ] +=
codebook.codevectors[coffs + 2];
1498 vec[voffs + vlen ] +=
codebook.codevectors[coffs + 1];
1499 vec[voffs + vlen + 1] +=
codebook.codevectors[coffs + 3];
1502 for (k = 0; k <
step; ++k) {
1507 for (l = 0; l <
dim; l += 2, voffs++) {
1508 vec[voffs ] +=
codebook.codevectors[coffs + l ];
1509 vec[voffs + vlen] +=
codebook.codevectors[coffs + l + 1];
1511 ff_dlog(
NULL,
" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n",
1512 pass, voffset / ch + (voffs % ch) * vlen,
1513 vec[voffset / ch + (voffs % ch) * vlen],
1514 codebook.codevectors[coffs + l], coffs, l);
1518 }
else if (vr_type == 2) {
1519 unsigned voffs_div = ch == 1 ? voffset :
FASTDIV(voffset, ch);
1520 unsigned voffs_mod = voffset - voffs_div * ch;
1522 for (k = 0; k <
step; ++k) {
1527 for (l = 0; l <
dim; ++l) {
1528 vec[voffs_div + voffs_mod * vlen] +=
1531 ff_dlog(
NULL,
" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n",
1532 pass, voffs_div + voffs_mod * vlen,
1533 vec[voffs_div + voffs_mod * vlen],
1534 codebook.codevectors[coffs + l], coffs, l);
1536 if (++voffs_mod == ch) {
1545 j_times_ptns_to_read += ptns_to_read;
1551 if (libvorbis_bug && !
pass) {
1552 for (j = 0; j < ch_used; ++j) {
1553 if (!do_not_decode[j]) {
1555 vc->codebooks[vr->
classbook].nb_bits, 3);
1565 uint8_t *do_not_decode,
1566 float *vec,
unsigned vlen,
1571 else if (vr->
type == 1)
1573 else if (vr->
type == 0)
1584 for (
i = 0;
i < blocksize;
i++) {
1587 ang[
i] = mag[
i] - ang[
i];
1589 float temp = ang[
i];
1597 float temp = ang[
i];
1611 int previous_window = vc->previous_window;
1612 unsigned mode_number, blockflag, blocksize;
1614 uint8_t no_residue[255];
1615 uint8_t do_not_decode[255];
1617 float *ch_res_ptr = vc->channel_residues;
1618 uint8_t res_chan[255];
1619 unsigned res_num = 0;
1621 unsigned ch_left = vc->audio_channels;
1629 if (vc->mode_count == 1) {
1634 vc->mode_number = mode_number;
1635 mapping = &vc->mappings[vc->modes[mode_number].mapping];
1637 ff_dlog(
NULL,
" Mode number: %u , mapping: %d , blocktype %d\n", mode_number,
1638 vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag);
1640 blockflag = vc->modes[mode_number].blockflag;
1641 blocksize = vc->blocksize[blockflag];
1642 vlen = blocksize / 2;
1645 if (previous_window < 0)
1646 previous_window =
code>>1;
1647 }
else if (previous_window < 0)
1648 previous_window = 0;
1650 memset(ch_res_ptr, 0,
sizeof(
float) * vc->audio_channels * vlen);
1651 for (
i = 0;
i < vc->audio_channels; ++
i)
1652 memset(floor_ptr[
i], 0, vlen *
sizeof(floor_ptr[0][0]));
1656 for (
i = 0;
i < vc->audio_channels; ++
i) {
1671 no_residue[
i] =
ret;
1677 if (!(no_residue[mapping->
magnitude[
i]] & no_residue[mapping->
angle[
i]])) {
1679 no_residue[mapping->
angle[
i]] = 0;
1690 for (j = 0; j < vc->audio_channels; ++j) {
1691 if ((mapping->
submaps == 1) || (
i == mapping->
mux[j])) {
1692 res_chan[j] = res_num;
1693 if (no_residue[j]) {
1694 do_not_decode[ch] = 1;
1696 do_not_decode[ch] = 0;
1713 ch_res_ptr += ch * vlen;
1725 mag = vc->channel_residues+res_chan[mapping->
magnitude[
i]] * blocksize / 2;
1726 ang = vc->channel_residues+res_chan[mapping->
angle[
i]] * blocksize / 2;
1727 vc->dsp.vorbis_inverse_coupling(mag, ang, blocksize / 2);
1732 mdct = &vc->mdct[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->
imdct_half(mdct, ch_res_ptr, floor_ptr[j]);
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;
1855 ff_dlog(
NULL,
"parsed %d bytes %d bits, returned %d samples (*ch*bits) \n",
1880 memset(vc->saved, 0, (vc->blocksize[1] / 4) * vc->audio_channels *
1881 sizeof(*vc->saved));
1883 vc->previous_window = -1;
1884 vc->first_frame = 0;
1892 .priv_data_size =
sizeof(vorbis_context),
1899 #if FF_API_OLD_CHANNEL_LAYOUT
1900 .p.channel_layouts = ff_vorbis_channel_layouts,