| 922 | } |
| 923 | |
| 924 | static void assign_bits(DCAEncContext *c) |
| 925 | { |
| 926 | /* Find the bounds where the binary search should work */ |
| 927 | int low, high, down; |
| 928 | int used_abits = 0; |
| 929 | int forbid_zero = 1; |
| 930 | restart: |
| 931 | init_quantization_noise(c, c->worst_quantization_noise, forbid_zero); |
| 932 | low = high = c->worst_quantization_noise; |
| 933 | if (c->consumed_bits > c->frame_bits) { |
| 934 | while (c->consumed_bits > c->frame_bits) { |
| 935 | if (used_abits == USED_1ABITS && forbid_zero) { |
| 936 | forbid_zero = 0; |
| 937 | goto restart; |
| 938 | } |
| 939 | low = high; |
| 940 | high += snr_fudge; |
| 941 | used_abits = init_quantization_noise(c, high, forbid_zero); |
| 942 | } |
| 943 | } else { |
| 944 | while (c->consumed_bits <= c->frame_bits) { |
| 945 | high = low; |
| 946 | if (used_abits == USED_26ABITS) |
| 947 | goto out; /* The requested bitrate is too high, pad with zeros */ |
| 948 | low -= snr_fudge; |
| 949 | used_abits = init_quantization_noise(c, low, forbid_zero); |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | /* Now do a binary search between low and high to see what fits */ |
| 954 | for (down = snr_fudge >> 1; down; down >>= 1) { |
| 955 | init_quantization_noise(c, high - down, forbid_zero); |
| 956 | if (c->consumed_bits <= c->frame_bits) |
| 957 | high -= down; |
| 958 | } |
| 959 | init_quantization_noise(c, high, forbid_zero); |
| 960 | out: |
| 961 | c->worst_quantization_noise = high; |
| 962 | if (high > c->worst_noise_ever) |
| 963 | c->worst_noise_ever = high; |
| 964 | } |
| 965 | |
| 966 | static void shift_history(DCAEncContext *c, const int32_t *input) |
| 967 | { |
no test coverage detected