| 713 | } |
| 714 | |
| 715 | static int encode_residual(FlacEncodeContext *ctx, int ch) |
| 716 | { |
| 717 | int i, n; |
| 718 | int min_order, max_order, opt_order, precision, omethod; |
| 719 | int min_porder, max_porder; |
| 720 | FlacFrame *frame; |
| 721 | FlacSubframe *sub; |
| 722 | int32_t coefs[MAX_LPC_ORDER][MAX_LPC_ORDER]; |
| 723 | int shift[MAX_LPC_ORDER]; |
| 724 | int32_t *res, *smp; |
| 725 | |
| 726 | frame = &ctx->frame; |
| 727 | sub = &frame->subframes[ch]; |
| 728 | res = sub->residual; |
| 729 | smp = sub->samples; |
| 730 | n = frame->blocksize; |
| 731 | |
| 732 | /* CONSTANT */ |
| 733 | for(i=1; i<n; i++) { |
| 734 | if(smp[i] != smp[0]) break; |
| 735 | } |
| 736 | if(i == n) { |
| 737 | sub->type = sub->type_code = FLAC_SUBFRAME_CONSTANT; |
| 738 | res[0] = smp[0]; |
| 739 | return sub->obits; |
| 740 | } |
| 741 | |
| 742 | /* VERBATIM */ |
| 743 | if(n < 5) { |
| 744 | sub->type = sub->type_code = FLAC_SUBFRAME_VERBATIM; |
| 745 | encode_residual_verbatim(res, smp, n); |
| 746 | return sub->obits * n; |
| 747 | } |
| 748 | |
| 749 | min_order = ctx->options.min_prediction_order; |
| 750 | max_order = ctx->options.max_prediction_order; |
| 751 | min_porder = ctx->options.min_partition_order; |
| 752 | max_porder = ctx->options.max_partition_order; |
| 753 | precision = ctx->options.lpc_coeff_precision; |
| 754 | omethod = ctx->options.prediction_order_method; |
| 755 | |
| 756 | /* FIXED */ |
| 757 | if(!ctx->options.use_lpc || max_order == 0 || (n <= max_order)) { |
| 758 | uint32_t bits[MAX_FIXED_ORDER+1]; |
| 759 | if(max_order > MAX_FIXED_ORDER) max_order = MAX_FIXED_ORDER; |
| 760 | opt_order = 0; |
| 761 | bits[0] = UINT32_MAX; |
| 762 | for(i=min_order; i<=max_order; i++) { |
| 763 | encode_residual_fixed(res, smp, n, i); |
| 764 | bits[i] = calc_rice_params_fixed(&sub->rc, min_porder, max_porder, res, |
| 765 | n, i, sub->obits); |
| 766 | if(bits[i] < bits[opt_order]) { |
| 767 | opt_order = i; |
| 768 | } |
| 769 | } |
| 770 | sub->order = opt_order; |
| 771 | sub->type = FLAC_SUBFRAME_FIXED; |
| 772 | sub->type_code = sub->type | sub->order; |
no test coverage detected