| 131 | } |
| 132 | |
| 133 | static int update_error_limit(WavpackFrameContext *ctx) |
| 134 | { |
| 135 | int i, br[2], sl[2]; |
| 136 | |
| 137 | for (i = 0; i <= ctx->stereo_in; i++) { |
| 138 | if (ctx->ch[i].bitrate_acc > UINT_MAX - ctx->ch[i].bitrate_delta) |
| 139 | return AVERROR_INVALIDDATA; |
| 140 | ctx->ch[i].bitrate_acc += ctx->ch[i].bitrate_delta; |
| 141 | br[i] = ctx->ch[i].bitrate_acc >> 16; |
| 142 | sl[i] = LEVEL_DECAY(ctx->ch[i].slow_level); |
| 143 | } |
| 144 | if (ctx->stereo_in && ctx->hybrid_bitrate) { |
| 145 | int balance = (sl[1] - sl[0] + br[1] + 1) >> 1; |
| 146 | if (balance > br[0]) { |
| 147 | br[1] = br[0] * 2; |
| 148 | br[0] = 0; |
| 149 | } else if (-balance > br[0]) { |
| 150 | br[0] *= 2; |
| 151 | br[1] = 0; |
| 152 | } else { |
| 153 | br[1] = br[0] + balance; |
| 154 | br[0] = br[0] - balance; |
| 155 | } |
| 156 | } |
| 157 | for (i = 0; i <= ctx->stereo_in; i++) { |
| 158 | if (ctx->hybrid_bitrate) { |
| 159 | if (sl[i] - br[i] > -0x100) |
| 160 | ctx->ch[i].error_limit = wp_exp2(sl[i] - br[i] + 0x100); |
| 161 | else |
| 162 | ctx->ch[i].error_limit = 0; |
| 163 | } else { |
| 164 | ctx->ch[i].error_limit = wp_exp2(br[i]); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, |
| 172 | int channel, int *last) |
no test coverage detected