comparison vorbis.c @ 3801:203cd258fc20 libavcodec

make ready_floor1_list() shared for vorbis_enc.c
author ods15
date Sun, 01 Oct 2006 11:11:30 +0000
parents 6e7b9a44800c
children 094fe185d054
comparison
equal deleted inserted replaced
3800:9b75ab171fa9 3801:203cd258fc20
86 uint_fast8_t class_subclasses[16]; 86 uint_fast8_t class_subclasses[16];
87 uint_fast8_t class_masterbook[16]; 87 uint_fast8_t class_masterbook[16];
88 int_fast16_t subclass_books[16][8]; 88 int_fast16_t subclass_books[16][8];
89 uint_fast8_t multiplier; 89 uint_fast8_t multiplier;
90 uint_fast16_t x_list_dim; 90 uint_fast16_t x_list_dim;
91 uint_fast16_t *x_list; 91 floor1_entry_t * list;
92 uint_fast16_t *x_list_order;
93 uint_fast16_t *low_neighbour;
94 uint_fast16_t *high_neighbour;
95 } t1; 92 } t1;
96 } data; 93 } data;
97 } vorbis_floor; 94 } vorbis_floor;
98 95
99 typedef struct { 96 typedef struct {
251 //FIXME no exits should be left (underspecified tree - ie. unused valid vlcs - not allowed by SPEC) 248 //FIXME no exits should be left (underspecified tree - ie. unused valid vlcs - not allowed by SPEC)
252 249
253 return 0; 250 return 0;
254 } 251 }
255 252
253 void ff_vorbis_ready_floor1_list(floor1_entry_t * list, int values) {
254 int i;
255 list[0].sort = 0;
256 list[1].sort = 1;
257 for (i = 2; i < values; i++) {
258 int j;
259 list[i].low = 0;
260 list[i].high = 1;
261 list[i].sort = i;
262 for (j = 2; j < i; j++) {
263 int tmp = list[j].x;
264 if (tmp < list[i].x) {
265 if (tmp > list[list[i].low].x) list[i].low = j;
266 } else {
267 if (tmp < list[list[i].high].x) list[i].high = j;
268 }
269 }
270 }
271 for (i = 0; i < values - 1; i++) {
272 int j;
273 for (j = i + 1; j < values; j++) {
274 if (list[list[i].sort].x > list[list[j].sort].x) {
275 int tmp = list[i].sort;
276 list[i].sort = list[j].sort;
277 list[j].sort = tmp;
278 }
279 }
280 }
281 }
282
256 // Free all allocated memory ----------------------------------------- 283 // Free all allocated memory -----------------------------------------
257 284
258 static void vorbis_free(vorbis_context *vc) { 285 static void vorbis_free(vorbis_context *vc) {
259 int_fast16_t i; 286 int_fast16_t i;
260 287
283 av_free(vc->floors[i].data.t0.map[1]); 310 av_free(vc->floors[i].data.t0.map[1]);
284 av_free(vc->floors[i].data.t0.book_list); 311 av_free(vc->floors[i].data.t0.book_list);
285 av_free(vc->floors[i].data.t0.lsp); 312 av_free(vc->floors[i].data.t0.lsp);
286 } 313 }
287 else { 314 else {
288 av_free(vc->floors[i].data.t1.x_list); 315 av_free(vc->floors[i].data.t1.list);
289 av_free(vc->floors[i].data.t1.x_list_order);
290 av_free(vc->floors[i].data.t1.low_neighbour);
291 av_free(vc->floors[i].data.t1.high_neighbour);
292 } 316 }
293 } 317 }
294 av_freep(&vc->floors); 318 av_freep(&vc->floors);
295 319
296 for(i=0;i<vc->mapping_count;++i) { 320 for(i=0;i<vc->mapping_count;++i) {
598 622
599 for(j=0;j<floor_setup->data.t1.partitions;++j) { 623 for(j=0;j<floor_setup->data.t1.partitions;++j) {
600 floor_setup->data.t1.x_list_dim+=floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]]; 624 floor_setup->data.t1.x_list_dim+=floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]];
601 } 625 }
602 626
603 floor_setup->data.t1.x_list=(uint_fast16_t *)av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(uint_fast16_t)); 627 floor_setup->data.t1.list=(floor1_entry_t *)av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(floor1_entry_t));
604 floor_setup->data.t1.x_list_order=(uint_fast16_t *)av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(uint_fast16_t));
605 floor_setup->data.t1.low_neighbour=(uint_fast16_t *)av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(uint_fast16_t));
606 floor_setup->data.t1.high_neighbour=(uint_fast16_t *)av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(uint_fast16_t));
607 628
608 629
609 rangebits=get_bits(gb, 4); 630 rangebits=get_bits(gb, 4);
610 floor_setup->data.t1.x_list[0] = 0; 631 floor_setup->data.t1.list[0].x = 0;
611 floor_setup->data.t1.x_list[1] = (1<<rangebits); 632 floor_setup->data.t1.list[1].x = (1<<rangebits);
612 633
613 for(j=0;j<floor_setup->data.t1.partitions;++j) { 634 for(j=0;j<floor_setup->data.t1.partitions;++j) {
614 for(k=0;k<floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]];++k,++floor1_values) { 635 for(k=0;k<floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]];++k,++floor1_values) {
615 floor_setup->data.t1.x_list[floor1_values]=get_bits(gb, rangebits); 636 floor_setup->data.t1.list[floor1_values].x=get_bits(gb, rangebits);
616 637
617 AV_DEBUG(" %d. floor1 Y coord. %d \n", floor1_values, floor_setup->data.t1.x_list[floor1_values]); 638 AV_DEBUG(" %d. floor1 Y coord. %d \n", floor1_values, floor_setup->data.t1.list[floor1_values].x);
618 } 639 }
619 } 640 }
620 641
621 // Precalculate order of x coordinates - needed for decode 642 // Precalculate order of x coordinates - needed for decode
622 643 ff_vorbis_ready_floor1_list(floor_setup->data.t1.list, floor_setup->data.t1.x_list_dim);
623 for(k=0;k<floor_setup->data.t1.x_list_dim;++k) {
624 floor_setup->data.t1.x_list_order[k]=k;
625 }
626
627 for(k=0;k<floor_setup->data.t1.x_list_dim-1;++k) { // FIXME optimize sorting ?
628 for(j=k+1;j<floor_setup->data.t1.x_list_dim;++j) {
629 if(floor_setup->data.t1.x_list[floor_setup->data.t1.x_list_order[k]]>floor_setup->data.t1.x_list[floor_setup->data.t1.x_list_order[j]]) {
630 uint_fast16_t tmp=floor_setup->data.t1.x_list_order[k];
631 floor_setup->data.t1.x_list_order[k]=floor_setup->data.t1.x_list_order[j];
632 floor_setup->data.t1.x_list_order[j]=tmp;
633 }
634 }
635 }
636
637 // Precalculate low and high neighbours
638
639 for(k=2;k<floor_setup->data.t1.x_list_dim;++k) {
640 floor_setup->data.t1.low_neighbour[k]=0;
641 floor_setup->data.t1.high_neighbour[k]=1; // correct according to SPEC requirements
642
643 for (j=0;j<k;++j) {
644 if ((floor_setup->data.t1.x_list[j]<floor_setup->data.t1.x_list[k]) &&
645 (floor_setup->data.t1.x_list[j]>floor_setup->data.t1.x_list[floor_setup->data.t1.low_neighbour[k]])) {
646 floor_setup->data.t1.low_neighbour[k]=j;
647 }
648 if ((floor_setup->data.t1.x_list[j]>floor_setup->data.t1.x_list[k]) &&
649 (floor_setup->data.t1.x_list[j]<floor_setup->data.t1.x_list[floor_setup->data.t1.high_neighbour[k]])) {
650 floor_setup->data.t1.high_neighbour[k]=j;
651 }
652 }
653 }
654 } 644 }
655 else if(floor_setup->floor_type==0) { 645 else if(floor_setup->floor_type==0) {
656 uint_fast8_t max_codebook_dim=0; 646 uint_fast8_t max_codebook_dim=0;
657 647
658 floor_setup->decode=vorbis_floor0_decode; 648 floor_setup->decode=vorbis_floor0_decode;
1254 uint_fast8_t csub; 1244 uint_fast8_t csub;
1255 uint_fast8_t cval; 1245 uint_fast8_t cval;
1256 int_fast16_t book; 1246 int_fast16_t book;
1257 uint_fast16_t offset; 1247 uint_fast16_t offset;
1258 uint_fast16_t i,j; 1248 uint_fast16_t i,j;
1259 uint_fast16_t *floor_x_sort=vf->x_list_order;
1260 /*u*/int_fast16_t adx, ady, off, predicted; // WTF ? dy/adx= (unsigned)dy/adx ? 1249 /*u*/int_fast16_t adx, ady, off, predicted; // WTF ? dy/adx= (unsigned)dy/adx ?
1261 int_fast16_t dy, err; 1250 int_fast16_t dy, err;
1262 uint_fast16_t lx,hx, ly, hy=0; 1251 uint_fast16_t lx,hx, ly, hy=0;
1263 1252
1264 1253
1297 vc->codebooks[book].nb_bits, 3); 1286 vc->codebooks[book].nb_bits, 3);
1298 } else { 1287 } else {
1299 floor1_Y[offset+j]=0; 1288 floor1_Y[offset+j]=0;
1300 } 1289 }
1301 1290
1302 AV_DEBUG(" floor(%d) = %d \n", vf->x_list[offset+j], floor1_Y[offset+j]); 1291 AV_DEBUG(" floor(%d) = %d \n", vf->list[offset+j].x, floor1_Y[offset+j]);
1303 } 1292 }
1304 offset+=cdim; 1293 offset+=cdim;
1305 } 1294 }
1306 1295
1307 // Amplitude calculation from the differences 1296 // Amplitude calculation from the differences
1314 for(i=2;i<vf->x_list_dim;++i) { 1303 for(i=2;i<vf->x_list_dim;++i) {
1315 uint_fast16_t val, highroom, lowroom, room; 1304 uint_fast16_t val, highroom, lowroom, room;
1316 uint_fast16_t high_neigh_offs; 1305 uint_fast16_t high_neigh_offs;
1317 uint_fast16_t low_neigh_offs; 1306 uint_fast16_t low_neigh_offs;
1318 1307
1319 low_neigh_offs=vf->low_neighbour[i]; 1308 low_neigh_offs=vf->list[i].low;
1320 high_neigh_offs=vf->high_neighbour[i]; 1309 high_neigh_offs=vf->list[i].high;
1321 dy=floor1_Y_final[high_neigh_offs]-floor1_Y_final[low_neigh_offs]; // render_point begin 1310 dy=floor1_Y_final[high_neigh_offs]-floor1_Y_final[low_neigh_offs]; // render_point begin
1322 adx=vf->x_list[high_neigh_offs]-vf->x_list[low_neigh_offs]; 1311 adx=vf->list[high_neigh_offs].x-vf->list[low_neigh_offs].x;
1323 ady= ABS(dy); 1312 ady= ABS(dy);
1324 err=ady*(vf->x_list[i]-vf->x_list[low_neigh_offs]); 1313 err=ady*(vf->list[i].x-vf->list[low_neigh_offs].x);
1325 off=(int16_t)err/(int16_t)adx; 1314 off=(int16_t)err/(int16_t)adx;
1326 if (dy<0) { 1315 if (dy<0) {
1327 predicted=floor1_Y_final[low_neigh_offs]-off; 1316 predicted=floor1_Y_final[low_neigh_offs]-off;
1328 } else { 1317 } else {
1329 predicted=floor1_Y_final[low_neigh_offs]+off; 1318 predicted=floor1_Y_final[low_neigh_offs]+off;
1357 } else { 1346 } else {
1358 floor1_flag[i]=0; 1347 floor1_flag[i]=0;
1359 floor1_Y_final[i]=predicted; 1348 floor1_Y_final[i]=predicted;
1360 } 1349 }
1361 1350
1362 AV_DEBUG(" Decoded floor(%d) = %d / val %d \n", vf->x_list[i], floor1_Y_final[i], val); 1351 AV_DEBUG(" Decoded floor(%d) = %d / val %d \n", vf->list[i].x, floor1_Y_final[i], val);
1363 } 1352 }
1364 1353
1365 // Curve synth - connect the calculated dots and convert from dB scale FIXME optimize ? 1354 // Curve synth - connect the calculated dots and convert from dB scale FIXME optimize ?
1366 1355
1367 hx=0; 1356 hx=0;
1371 vec[0]=ff_vorbis_floor1_inverse_db_table[ly]; 1360 vec[0]=ff_vorbis_floor1_inverse_db_table[ly];
1372 1361
1373 for(i=1;i<vf->x_list_dim;++i) { 1362 for(i=1;i<vf->x_list_dim;++i) {
1374 AV_DEBUG(" Looking at post %d \n", i); 1363 AV_DEBUG(" Looking at post %d \n", i);
1375 1364
1376 if (floor1_flag[floor_x_sort[i]]) { // SPEC mispelled 1365 if (floor1_flag[vf->list[i].sort]) { // SPEC mispelled
1377 int_fast16_t x, y, dy, base, sy; // if uncommented: dy = -32 adx = 2 base = 2blablabla ????? 1366 int_fast16_t x, y, dy, base, sy; // if uncommented: dy = -32 adx = 2 base = 2blablabla ?????
1378 1367
1379 hy=floor1_Y_final[floor_x_sort[i]]*vf->multiplier; 1368 hy=floor1_Y_final[vf->list[i].sort]*vf->multiplier;
1380 hx=vf->x_list[floor_x_sort[i]]; 1369 hx=vf->list[vf->list[i].sort].x;
1381 1370
1382 dy=hy-ly; 1371 dy=hy-ly;
1383 adx=hx-lx; 1372 adx=hx-lx;
1384 ady= (dy<0) ? -dy:dy;//ABS(dy); 1373 ady= (dy<0) ? -dy:dy;//ABS(dy);
1385 base=(int16_t)dy/(int16_t)adx; 1374 base=(int16_t)dy/(int16_t)adx;
1397 ady=ady-(base<0 ? -base : base)*adx; 1386 ady=ady-(base<0 ? -base : base)*adx;
1398 vec[x]=ff_vorbis_floor1_inverse_db_table[y]; 1387 vec[x]=ff_vorbis_floor1_inverse_db_table[y];
1399 1388
1400 AV_DEBUG(" vec[ %d ] = %d \n", x, y); 1389 AV_DEBUG(" vec[ %d ] = %d \n", x, y);
1401 1390
1402 for(x=lx+1;(x<hx) && (x<vf->x_list[1]);++x) { 1391 for(x=lx+1;(x<hx) && (x<vf->list[1].x);++x) {
1403 err+=ady; 1392 err+=ady;
1404 if (err>=adx) { 1393 if (err>=adx) {
1405 err-=adx; 1394 err-=adx;
1406 y+=sy; 1395 y+=sy;
1407 } else { 1396 } else {
1431 lx=hx; 1420 lx=hx;
1432 ly=hy; 1421 ly=hy;
1433 } 1422 }
1434 } 1423 }
1435 1424
1436 if (hx<vf->x_list[1]) { 1425 if (hx<vf->list[1].x) {
1437 for(i=hx;i<vf->x_list[1];++i) { 1426 for(i=hx;i<vf->list[1].x;++i) {
1438 vec[i]=ff_vorbis_floor1_inverse_db_table[hy]; 1427 vec[i]=ff_vorbis_floor1_inverse_db_table[hy];
1439 } 1428 }
1440 } 1429 }
1441 1430
1442 AV_DEBUG(" Floor decoded\n"); 1431 AV_DEBUG(" Floor decoded\n");