} DecodingParams;
typedef struct BestOffset {
- int16_t offset;
+ int32_t offset;
int bitcount;
int lsb_bits;
- int16_t min;
- int16_t max;
+ int32_t min;
+ int32_t max;
} BestOffset;
-#define HUFF_OFFSET_MIN -16384
-#define HUFF_OFFSET_MAX 16383
+#define HUFF_OFFSET_MIN (-16384)
+#define HUFF_OFFSET_MAX ( 16383)
/** Number of possible codebooks (counting "no codebooks") */
#define NUM_CODEBOOKS 4
static void write_restart_header(MLPEncodeContext *ctx, PutBitContext *pb)
{
RestartHeader *rh = ctx->cur_restart_header;
- int32_t lossless_check = xor_32_to_8(rh->lossless_check_data);
+ uint8_t lossless_check = xor_32_to_8(rh->lossless_check_data);
unsigned int start_count = put_bits_count(pb);
PutBitContext tmpb;
uint8_t checksum;
put_bits(pb, 1, 0);
}
}
+ if (cp->codebook > 0 && cp->huff_lsbs > 24) {
+ av_log(ctx->avctx, AV_LOG_ERROR, "Invalid Huff LSBs\n");
+ }
put_bits(pb, 2, cp->codebook );
put_bits(pb, 5, cp->huff_lsbs);
codebook_index [ch] = cp->codebook - 1;
sign_huff_offset[ch] = cp->huff_offset;
- sign_shift = lsb_bits[ch] - 1;
+ sign_shift = lsb_bits[ch] + (cp->codebook ? 2 - cp->codebook : -1);
- if (cp->codebook > 0) {
+ if (cp->codebook > 0)
sign_huff_offset[ch] -= 7 << lsb_bits[ch];
- sign_shift += 3 - cp->codebook;
- }
/* Unsign if needed. */
if (sign_shift >= 0)
for (i = 0; i < dp->blocksize; i++) {
for (ch = rh->min_channel; ch <= rh->max_channel; ch++) {
int32_t sample = *sample_buffer++ >> dp->quant_step_size[ch];
-
sample -= sign_huff_offset[ch];
if (codebook_index[ch] >= 0) {
uint32_t abs_sample;
int32_t sample;
- sample = is24 ? *samples_32++ >> 8 : *samples_16++ << 8;
+ sample = is24 ? *samples_32++ >> 8 : *samples_16++ * 256;
/* TODO Find out if number_sbits can be used for negative values. */
abs_sample = FFABS(sample);
#define SAMPLE_MAX(bitdepth) ((1 << (bitdepth - 1)) - 1)
#define SAMPLE_MIN(bitdepth) (~SAMPLE_MAX(bitdepth))
-#define MSB_MASK(bits) (-1u << bits)
+#define MSB_MASK(bits) (-(int)(1u << (bits)))
/** Applies the filter to the current samples, and saves the residual back
* into the samples buffer. If the filter is too bad and overflows the
for (i = 0; i < ctx->number_of_samples; i++) {
uint16_t seed_shr7 = seed >> 7;
- *sample_buffer++ = ((int8_t)(seed >> 15)) << rh->noise_shift;
- *sample_buffer++ = ((int8_t) seed_shr7) << rh->noise_shift;
+ *sample_buffer++ = ((int8_t)(seed >> 15)) * (1 << rh->noise_shift);
+ *sample_buffer++ = ((int8_t) seed_shr7) * (1 << rh->noise_shift);
seed = (seed << 16) ^ seed_shr7 ^ (seed_shr7 << 5);
best_codebook = *best_path++ - ZERO_PATH;
cur_bo = &ctx->best_offset[index][channel][best_codebook];
- cp->huff_offset = cur_bo->offset;
- cp->huff_lsbs = cur_bo->lsb_bits + dp->quant_step_size[channel];
- cp->codebook = best_codebook;
+ cp->huff_offset = cur_bo->offset;
+ cp->huff_lsbs = cur_bo->lsb_bits + dp->quant_step_size[channel];
+ cp->codebook = best_codebook;
}
}
}
if (restart_frame) {
set_major_params(ctx);
if (ctx->min_restart_interval != ctx->max_restart_interval)
- process_major_frame(ctx);
+ process_major_frame(ctx);
}
if (ctx->min_restart_interval == ctx->max_restart_interval)
av_freep(&ctx->decoding_params);
av_freep(&ctx->channel_params);
av_freep(&ctx->frame_size);
+ av_freep(&ctx->max_output_bits);
ff_af_queue_close(&ctx->afq);
return 0;