Mercurial > libavcodec.hg
comparison flacenc.c @ 3397:bdfc530c417c libavcodec
porder patch by (Justin Ruggles jruggle a t earthlink d ot net)
author | michael |
---|---|
date | Mon, 03 Jul 2006 09:20:26 +0000 |
parents | 63a4adcaf226 |
children | 5d133e59ecf2 |
comparison
equal
deleted
inserted
replaced
3396:3f43459705a5 | 3397:bdfc530c417c |
---|---|
535 | 535 |
536 av_freep(&udata); | 536 av_freep(&udata); |
537 return bits[opt_porder]; | 537 return bits[opt_porder]; |
538 } | 538 } |
539 | 539 |
540 static int get_max_p_order(int max_porder, int n, int order) | |
541 { | |
542 int porder = FFMIN(max_porder, av_log2(n^(n-1))); | |
543 if(order > 0) | |
544 porder = FFMIN(porder, av_log2(n/order)); | |
545 return porder; | |
546 } | |
547 | |
540 static uint32_t calc_rice_params_fixed(RiceContext *rc, int pmin, int pmax, | 548 static uint32_t calc_rice_params_fixed(RiceContext *rc, int pmin, int pmax, |
541 int32_t *data, int n, int pred_order, | 549 int32_t *data, int n, int pred_order, |
542 int bps) | 550 int bps) |
543 { | 551 { |
544 uint32_t bits; | 552 uint32_t bits; |
553 pmin = get_max_p_order(pmin, n, pred_order); | |
554 pmax = get_max_p_order(pmax, n, pred_order); | |
545 bits = pred_order*bps + 6; | 555 bits = pred_order*bps + 6; |
546 bits += calc_rice_params(rc, pmin, pmax, data, n, pred_order); | 556 bits += calc_rice_params(rc, pmin, pmax, data, n, pred_order); |
547 return bits; | 557 return bits; |
548 } | 558 } |
549 | 559 |
550 static uint32_t calc_rice_params_lpc(RiceContext *rc, int pmin, int pmax, | 560 static uint32_t calc_rice_params_lpc(RiceContext *rc, int pmin, int pmax, |
551 int32_t *data, int n, int pred_order, | 561 int32_t *data, int n, int pred_order, |
552 int bps, int precision) | 562 int bps, int precision) |
553 { | 563 { |
554 uint32_t bits; | 564 uint32_t bits; |
565 pmin = get_max_p_order(pmin, n, pred_order); | |
566 pmax = get_max_p_order(pmax, n, pred_order); | |
555 bits = pred_order*bps + 4 + 5 + pred_order*precision + 6; | 567 bits = pred_order*bps + 4 + 5 + pred_order*precision + 6; |
556 bits += calc_rice_params(rc, pmin, pmax, data, n, pred_order); | 568 bits += calc_rice_params(rc, pmin, pmax, data, n, pred_order); |
557 return bits; | 569 return bits; |
558 } | 570 } |
559 | 571 |
782 } | 794 } |
783 res[i] = smp[i] - (pred >> shift); | 795 res[i] = smp[i] - (pred >> shift); |
784 } | 796 } |
785 } | 797 } |
786 | 798 |
787 static int get_max_p_order(int max_porder, int n, int order) | |
788 { | |
789 int porder, max_parts; | |
790 | |
791 for(porder = max_porder; porder > 0; porder--) { | |
792 max_parts = (1 << porder); | |
793 if(!(n % max_parts) && (n > max_parts*order)) { | |
794 break; | |
795 } | |
796 } | |
797 return porder; | |
798 } | |
799 | |
800 static int encode_residual(FlacEncodeContext *ctx, int ch) | 799 static int encode_residual(FlacEncodeContext *ctx, int ch) |
801 { | 800 { |
802 int i, n; | 801 int i, n; |
803 int min_order, max_order, opt_order, precision; | 802 int min_order, max_order, opt_order, precision; |
804 int porder, min_porder, max_porder; | 803 int min_porder, max_porder; |
805 FlacFrame *frame; | 804 FlacFrame *frame; |
806 FlacSubframe *sub; | 805 FlacSubframe *sub; |
807 int32_t coefs[MAX_LPC_ORDER][MAX_LPC_ORDER]; | 806 int32_t coefs[MAX_LPC_ORDER][MAX_LPC_ORDER]; |
808 int shift[MAX_LPC_ORDER]; | 807 int shift[MAX_LPC_ORDER]; |
809 int32_t *res, *smp; | 808 int32_t *res, *smp; |
843 if(max_order > MAX_FIXED_ORDER) max_order = MAX_FIXED_ORDER; | 842 if(max_order > MAX_FIXED_ORDER) max_order = MAX_FIXED_ORDER; |
844 opt_order = 0; | 843 opt_order = 0; |
845 bits[0] = UINT32_MAX; | 844 bits[0] = UINT32_MAX; |
846 for(i=min_order; i<=max_order; i++) { | 845 for(i=min_order; i<=max_order; i++) { |
847 encode_residual_fixed(res, smp, n, i); | 846 encode_residual_fixed(res, smp, n, i); |
848 porder = get_max_p_order(max_porder, n, i); | 847 bits[i] = calc_rice_params_fixed(&sub->rc, min_porder, max_porder, res, |
849 bits[i] = calc_rice_params_fixed(&sub->rc, min_porder, porder, res, | |
850 n, i, sub->obits); | 848 n, i, sub->obits); |
851 if(bits[i] < bits[opt_order]) { | 849 if(bits[i] < bits[opt_order]) { |
852 opt_order = i; | 850 opt_order = i; |
853 } | 851 } |
854 } | 852 } |
855 sub->order = opt_order; | 853 sub->order = opt_order; |
856 sub->type = FLAC_SUBFRAME_FIXED; | 854 sub->type = FLAC_SUBFRAME_FIXED; |
857 sub->type_code = sub->type | sub->order; | 855 sub->type_code = sub->type | sub->order; |
858 if(sub->order != max_order) { | 856 if(sub->order != max_order) { |
859 encode_residual_fixed(res, smp, n, sub->order); | 857 encode_residual_fixed(res, smp, n, sub->order); |
860 porder = get_max_p_order(max_porder, n, sub->order); | 858 return calc_rice_params_fixed(&sub->rc, min_porder, max_porder, res, n, |
861 return calc_rice_params_fixed(&sub->rc, min_porder, porder, res, n, | |
862 sub->order, sub->obits); | 859 sub->order, sub->obits); |
863 } | 860 } |
864 return bits[sub->order]; | 861 return bits[sub->order]; |
865 } | 862 } |
866 | 863 |
870 sub->type_code = sub->type | (sub->order-1); | 867 sub->type_code = sub->type | (sub->order-1); |
871 sub->shift = shift[sub->order-1]; | 868 sub->shift = shift[sub->order-1]; |
872 for(i=0; i<sub->order; i++) { | 869 for(i=0; i<sub->order; i++) { |
873 sub->coefs[i] = coefs[sub->order-1][i]; | 870 sub->coefs[i] = coefs[sub->order-1][i]; |
874 } | 871 } |
875 porder = get_max_p_order(max_porder, n, sub->order); | |
876 encode_residual_lpc(res, smp, n, sub->order, sub->coefs, sub->shift); | 872 encode_residual_lpc(res, smp, n, sub->order, sub->coefs, sub->shift); |
877 return calc_rice_params_lpc(&sub->rc, 0, porder, res, n, sub->order, | 873 return calc_rice_params_lpc(&sub->rc, min_porder, max_porder, res, n, sub->order, |
878 sub->obits, precision); | 874 sub->obits, precision); |
879 } | 875 } |
880 | 876 |
881 static int encode_residual_v(FlacEncodeContext *ctx, int ch) | 877 static int encode_residual_v(FlacEncodeContext *ctx, int ch) |
882 { | 878 { |