Revision 089c18f3

View differences:

libavcodec/flacenc.c
606 606
}
607 607

  
608 608

  
609
static uint32_t find_subblock_rice_params(RiceContext *rc, int pmin, int pmax,
610
                                          int32_t *data, int n, int pred_order,
611
                                          int bps, int precision)
609
static uint32_t find_subblock_rice_params(FlacEncodeContext *s,
610
                                          FlacSubframe *sub, int pred_order)
612 611
{
613
    uint32_t bits;
614
    pmin  = get_max_p_order(pmin, n, pred_order);
615
    pmax  = get_max_p_order(pmax, n, pred_order);
616
    bits  = pred_order * bps + 6;
617
    if (precision > 0)
618
        bits += 4 + 5 + pred_order * precision;
619
    bits += calc_rice_params(rc, pmin, pmax, data, n, pred_order);
612
    int pmin = get_max_p_order(s->options.min_partition_order,
613
                               s->frame.blocksize, pred_order);
614
    int pmax = get_max_p_order(s->options.max_partition_order,
615
                               s->frame.blocksize, pred_order);
616

  
617
    uint32_t bits = 8 + pred_order * sub->obits + 2 + 4;
618
    if (sub->type == FLAC_SUBFRAME_LPC)
619
        bits += 4 + 5 + pred_order * s->options.lpc_coeff_precision;
620
    bits += calc_rice_params(&sub->rc, pmin, pmax, sub->residual,
621
                             s->frame.blocksize, pred_order);
620 622
    return bits;
621 623
}
622 624

  
......
779 781
static int encode_residual_ch(FlacEncodeContext *s, int ch)
780 782
{
781 783
    int i, n;
782
    int min_order, max_order, opt_order, precision, omethod;
783
    int min_porder, max_porder;
784
    int min_order, max_order, opt_order, omethod;
784 785
    FlacFrame *frame;
785 786
    FlacSubframe *sub;
786 787
    int32_t coefs[MAX_LPC_ORDER][MAX_LPC_ORDER];
......
812 813

  
813 814
    min_order  = s->options.min_prediction_order;
814 815
    max_order  = s->options.max_prediction_order;
815
    min_porder = s->options.min_partition_order;
816
    max_porder = s->options.max_partition_order;
817
    precision  = s->options.lpc_coeff_precision;
818 816
    omethod    = s->options.prediction_order_method;
819 817

  
820 818
    /* FIXED */
819
    sub->type = FLAC_SUBFRAME_FIXED;
821 820
    if (s->options.lpc_type == AV_LPC_TYPE_NONE  ||
822 821
        s->options.lpc_type == AV_LPC_TYPE_FIXED || n <= max_order) {
823 822
        uint32_t bits[MAX_FIXED_ORDER+1];
......
827 826
        bits[0]   = UINT32_MAX;
828 827
        for (i = min_order; i <= max_order; i++) {
829 828
            encode_residual_fixed(res, smp, n, i);
830
            bits[i] = find_subblock_rice_params(&sub->rc, min_porder,
831
                                                max_porder, res, n, i,
832
                                                sub->obits, 0);
829
            bits[i] = find_subblock_rice_params(s, sub, i);
833 830
            if (bits[i] < bits[opt_order])
834 831
                opt_order = i;
835 832
        }
836 833
        sub->order     = opt_order;
837
        sub->type      = FLAC_SUBFRAME_FIXED;
838 834
        sub->type_code = sub->type | sub->order;
839 835
        if (sub->order != max_order) {
840 836
            encode_residual_fixed(res, smp, n, sub->order);
841
            return find_subblock_rice_params(&sub->rc, min_porder, max_porder,
842
                                             res, n, sub->order, sub->obits, 0);
837
            return find_subblock_rice_params(s, sub, sub->order);
843 838
        }
844 839
        return bits[sub->order];
845 840
    }
846 841

  
847 842
    /* LPC */
843
    sub->type = FLAC_SUBFRAME_LPC;
848 844
    opt_order = ff_lpc_calc_coefs(&s->dsp, smp, n, min_order, max_order,
849
                                  precision, coefs, shift, s->options.lpc_type,
845
                                  s->options.lpc_coeff_precision, coefs, shift, s->options.lpc_type,
850 846
                                  s->options.lpc_passes, omethod,
851 847
                                  MAX_LPC_SHIFT, 0);
852 848

  
......
864 860
            if (order < 0)
865 861
                order = 0;
866 862
            encode_residual_lpc(res, smp, n, order+1, coefs[order], shift[order]);
867
            bits[i] = find_subblock_rice_params(&sub->rc, min_porder,
868
                                                max_porder, res, n, order+1,
869
                                                sub->obits, precision);
863
            bits[i] = find_subblock_rice_params(s, sub, order+1);
870 864
            if (bits[i] < bits[opt_index]) {
871 865
                opt_index = i;
872 866
                opt_order = order;
......
880 874
        bits[0]   = UINT32_MAX;
881 875
        for (i = min_order-1; i < max_order; i++) {
882 876
            encode_residual_lpc(res, smp, n, i+1, coefs[i], shift[i]);
883
            bits[i] = find_subblock_rice_params(&sub->rc, min_porder,
884
                                                max_porder, res, n, i+1,
885
                                                sub->obits, precision);
877
            bits[i] = find_subblock_rice_params(s, sub, i+1);
886 878
            if (bits[i] < bits[opt_order])
887 879
                opt_order = i;
888 880
        }
......
900 892
                if (i < min_order-1 || i >= max_order || bits[i] < UINT32_MAX)
901 893
                    continue;
902 894
                encode_residual_lpc(res, smp, n, i+1, coefs[i], shift[i]);
903
                bits[i] = find_subblock_rice_params(&sub->rc, min_porder,
904
                                                    max_porder, res, n, i+1,
905
                                                    sub->obits, precision);
895
                bits[i] = find_subblock_rice_params(s, sub, i+1);
906 896
                if (bits[i] < bits[opt_order])
907 897
                    opt_order = i;
908 898
            }
......
911 901
    }
912 902

  
913 903
    sub->order     = opt_order;
914
    sub->type      = FLAC_SUBFRAME_LPC;
915 904
    sub->type_code = sub->type | (sub->order-1);
916 905
    sub->shift     = shift[sub->order-1];
917 906
    for (i = 0; i < sub->order; i++)
......
919 908

  
920 909
    encode_residual_lpc(res, smp, n, sub->order, sub->coefs, sub->shift);
921 910

  
922
    return find_subblock_rice_params(&sub->rc, min_porder, max_porder, res, n,
923
                                     sub->order, sub->obits, precision);
911
    return find_subblock_rice_params(s, sub, sub->order);
924 912
}
925 913

  
926 914

  

Also available in: Unified diff