Mercurial > libavcodec.hg
comparison flacenc.c @ 12323:df22caaab59e libavcodec
Combine calc_rice_params_fixed() and calc_rice_params_lpc() into a single
function.
author | jbr |
---|---|
date | Sat, 31 Jul 2010 17:06:10 +0000 |
parents | 530bf62f3940 |
children | 549a40628c70 |
comparison
equal
deleted
inserted
replaced
12322:530bf62f3940 | 12323:df22caaab59e |
---|---|
604 porder = FFMIN(porder, av_log2(n/order)); | 604 porder = FFMIN(porder, av_log2(n/order)); |
605 return porder; | 605 return porder; |
606 } | 606 } |
607 | 607 |
608 | 608 |
609 static uint32_t calc_rice_params_fixed(RiceContext *rc, int pmin, int pmax, | 609 static uint32_t find_subblock_rice_params(RiceContext *rc, int pmin, int pmax, |
610 int32_t *data, int n, int pred_order, | 610 int32_t *data, int n, int pred_order, |
611 int bps) | 611 int bps, int precision) |
612 { | 612 { |
613 uint32_t bits; | 613 uint32_t bits; |
614 pmin = get_max_p_order(pmin, n, pred_order); | 614 pmin = get_max_p_order(pmin, n, pred_order); |
615 pmax = get_max_p_order(pmax, n, pred_order); | 615 pmax = get_max_p_order(pmax, n, pred_order); |
616 bits = pred_order * bps + 6; | 616 bits = pred_order * bps + 6; |
617 bits += calc_rice_params(rc, pmin, pmax, data, n, pred_order); | 617 if (precision > 0) |
618 return bits; | 618 bits += 4 + 5 + pred_order * precision; |
619 } | |
620 | |
621 | |
622 static uint32_t calc_rice_params_lpc(RiceContext *rc, int pmin, int pmax, | |
623 int32_t *data, int n, int pred_order, | |
624 int bps, int precision) | |
625 { | |
626 uint32_t bits; | |
627 pmin = get_max_p_order(pmin, n, pred_order); | |
628 pmax = get_max_p_order(pmax, n, pred_order); | |
629 bits = pred_order*bps + 4 + 5 + pred_order*precision + 6; | |
630 bits += calc_rice_params(rc, pmin, pmax, data, n, pred_order); | 619 bits += calc_rice_params(rc, pmin, pmax, data, n, pred_order); |
631 return bits; | 620 return bits; |
632 } | 621 } |
633 | 622 |
634 | 623 |
836 max_order = MAX_FIXED_ORDER; | 825 max_order = MAX_FIXED_ORDER; |
837 opt_order = 0; | 826 opt_order = 0; |
838 bits[0] = UINT32_MAX; | 827 bits[0] = UINT32_MAX; |
839 for (i = min_order; i <= max_order; i++) { | 828 for (i = min_order; i <= max_order; i++) { |
840 encode_residual_fixed(res, smp, n, i); | 829 encode_residual_fixed(res, smp, n, i); |
841 bits[i] = calc_rice_params_fixed(&sub->rc, min_porder, max_porder, res, | 830 bits[i] = find_subblock_rice_params(&sub->rc, min_porder, |
842 n, i, sub->obits); | 831 max_porder, res, n, i, |
832 sub->obits, 0); | |
843 if (bits[i] < bits[opt_order]) | 833 if (bits[i] < bits[opt_order]) |
844 opt_order = i; | 834 opt_order = i; |
845 } | 835 } |
846 sub->order = opt_order; | 836 sub->order = opt_order; |
847 sub->type = FLAC_SUBFRAME_FIXED; | 837 sub->type = FLAC_SUBFRAME_FIXED; |
848 sub->type_code = sub->type | sub->order; | 838 sub->type_code = sub->type | sub->order; |
849 if (sub->order != max_order) { | 839 if (sub->order != max_order) { |
850 encode_residual_fixed(res, smp, n, sub->order); | 840 encode_residual_fixed(res, smp, n, sub->order); |
851 return calc_rice_params_fixed(&sub->rc, min_porder, max_porder, res, n, | 841 return find_subblock_rice_params(&sub->rc, min_porder, max_porder, |
852 sub->order, sub->obits); | 842 res, n, sub->order, sub->obits, 0); |
853 } | 843 } |
854 return bits[sub->order]; | 844 return bits[sub->order]; |
855 } | 845 } |
856 | 846 |
857 /* LPC */ | 847 /* LPC */ |
872 for (i = levels-1; i >= 0; i--) { | 862 for (i = levels-1; i >= 0; i--) { |
873 order = min_order + (((max_order-min_order+1) * (i+1)) / levels)-1; | 863 order = min_order + (((max_order-min_order+1) * (i+1)) / levels)-1; |
874 if (order < 0) | 864 if (order < 0) |
875 order = 0; | 865 order = 0; |
876 encode_residual_lpc(res, smp, n, order+1, coefs[order], shift[order]); | 866 encode_residual_lpc(res, smp, n, order+1, coefs[order], shift[order]); |
877 bits[i] = calc_rice_params_lpc(&sub->rc, min_porder, max_porder, | 867 bits[i] = find_subblock_rice_params(&sub->rc, min_porder, max_porder, |
878 res, n, order+1, sub->obits, precision); | 868 res, n, order+1, sub->obits, precision); |
879 if (bits[i] < bits[opt_index]) { | 869 if (bits[i] < bits[opt_index]) { |
880 opt_index = i; | 870 opt_index = i; |
881 opt_order = order; | 871 opt_order = order; |
882 } | 872 } |
887 uint32_t bits[MAX_LPC_ORDER]; | 877 uint32_t bits[MAX_LPC_ORDER]; |
888 opt_order = 0; | 878 opt_order = 0; |
889 bits[0] = UINT32_MAX; | 879 bits[0] = UINT32_MAX; |
890 for (i = min_order-1; i < max_order; i++) { | 880 for (i = min_order-1; i < max_order; i++) { |
891 encode_residual_lpc(res, smp, n, i+1, coefs[i], shift[i]); | 881 encode_residual_lpc(res, smp, n, i+1, coefs[i], shift[i]); |
892 bits[i] = calc_rice_params_lpc(&sub->rc, min_porder, max_porder, | 882 bits[i] = find_subblock_rice_params(&sub->rc, min_porder, max_porder, |
893 res, n, i+1, sub->obits, precision); | 883 res, n, i+1, sub->obits, precision); |
894 if (bits[i] < bits[opt_order]) | 884 if (bits[i] < bits[opt_order]) |
895 opt_order = i; | 885 opt_order = i; |
896 } | 886 } |
897 opt_order++; | 887 opt_order++; |
906 int last = opt_order; | 896 int last = opt_order; |
907 for (i = last-step; i <= last+step; i += step) { | 897 for (i = last-step; i <= last+step; i += step) { |
908 if (i < min_order-1 || i >= max_order || bits[i] < UINT32_MAX) | 898 if (i < min_order-1 || i >= max_order || bits[i] < UINT32_MAX) |
909 continue; | 899 continue; |
910 encode_residual_lpc(res, smp, n, i+1, coefs[i], shift[i]); | 900 encode_residual_lpc(res, smp, n, i+1, coefs[i], shift[i]); |
911 bits[i] = calc_rice_params_lpc(&sub->rc, min_porder, max_porder, | 901 bits[i] = find_subblock_rice_params(&sub->rc, min_porder, max_porder, |
912 res, n, i+1, sub->obits, | 902 res, n, i+1, sub->obits, |
913 precision); | 903 precision); |
914 if (bits[i] < bits[opt_order]) | 904 if (bits[i] < bits[opt_order]) |
915 opt_order = i; | 905 opt_order = i; |
916 } | 906 } |
925 for (i = 0; i < sub->order; i++) | 915 for (i = 0; i < sub->order; i++) |
926 sub->coefs[i] = coefs[sub->order-1][i]; | 916 sub->coefs[i] = coefs[sub->order-1][i]; |
927 | 917 |
928 encode_residual_lpc(res, smp, n, sub->order, sub->coefs, sub->shift); | 918 encode_residual_lpc(res, smp, n, sub->order, sub->coefs, sub->shift); |
929 | 919 |
930 return calc_rice_params_lpc(&sub->rc, min_porder, max_porder, res, n, | 920 return find_subblock_rice_params(&sub->rc, min_porder, max_porder, res, n, |
931 sub->order, sub->obits, precision); | 921 sub->order, sub->obits, precision); |
932 } | 922 } |
933 | 923 |
934 | 924 |
935 static int count_frame_header(FlacEncodeContext *s) | 925 static int count_frame_header(FlacEncodeContext *s) |