int scaling;
int coefsend;
int bitsend;
- DECLARE_ALIGNED(16, int32_t, coefs)[MAX_ORDER + WMALL_COEFF_PAD_SIZE/sizeof(int16_t)];
+ DECLARE_ALIGNED(16, int16_t, coefs)[MAX_ORDER + WMALL_COEFF_PAD_SIZE/sizeof(int16_t)];
DECLARE_ALIGNED(16, int32_t, lms_prevvalues)[MAX_ORDER * 2 + WMALL_COEFF_PAD_SIZE/sizeof(int16_t)];
- DECLARE_ALIGNED(16, int32_t, lms_updates)[MAX_ORDER * 2 + WMALL_COEFF_PAD_SIZE/sizeof(int16_t)];
+ DECLARE_ALIGNED(16, int16_t, lms_updates)[MAX_ORDER * 2 + WMALL_COEFF_PAD_SIZE/sizeof(int16_t)];
int recent;
} cdlms[WMALL_MAX_CHANNELS][9];
int lpc_order;
int lpc_scaling;
int lpc_intbits;
-
- int channel_coeffs[WMALL_MAX_CHANNELS][WMALL_BLOCK_MAX_SIZE];
} WmallDecodeCtx;
/** Get sign of integer (1 for positive, -1 for negative and 0 for zero) */
s->cdlms[0][0].order = 0;
return AVERROR_INVALIDDATA;
}
- if(s->cdlms[c][i].order & 8) {
+ if(s->cdlms[c][i].order & 8 && s->bits_per_sample == 16) {
static int warned;
if(!warned)
avpriv_request_sample(s->avctx, "CDLMS of order %d",
}
}
-static void lms_update(WmallDecodeCtx *s, int ich, int ilms, int input)
-{
- int recent = s->cdlms[ich][ilms].recent;
- int range = 1 << s->bits_per_sample - 1;
- int order = s->cdlms[ich][ilms].order;
-
- if (recent)
- recent--;
- else {
- memcpy(s->cdlms[ich][ilms].lms_prevvalues + order,
- s->cdlms[ich][ilms].lms_prevvalues, sizeof(*s->cdlms[ich][ilms].lms_prevvalues) * order);
- memcpy(s->cdlms[ich][ilms].lms_updates + order,
- s->cdlms[ich][ilms].lms_updates, sizeof(*s->cdlms[ich][ilms].lms_updates) * order);
- recent = order - 1;
- }
-
- s->cdlms[ich][ilms].lms_prevvalues[recent] = av_clip(input, -range, range - 1);
- s->cdlms[ich][ilms].lms_updates[recent] = WMASIGN(input) * s->update_speed[ich];
-
- s->cdlms[ich][ilms].lms_updates[recent + (order >> 4)] >>= 2;
- s->cdlms[ich][ilms].lms_updates[recent + (order >> 3)] >>= 1;
- s->cdlms[ich][ilms].recent = recent;
- memset(s->cdlms[ich][ilms].lms_updates + recent + order, 0,
- sizeof(s->cdlms[ich][ilms].lms_updates) - 4*(recent+order));
-}
-
static void use_high_update_speed(WmallDecodeCtx *s, int ich)
{
int ilms, recent, icoef;
s->update_speed[ich] = 8;
}
-static void revert_cdlms(WmallDecodeCtx *s, int ch,
- int coef_begin, int coef_end)
-{
- int icoef, pred, ilms, num_lms, residue, input;
-
- num_lms = s->cdlms_ttl[ch];
- for (ilms = num_lms - 1; ilms >= 0; ilms--) {
- for (icoef = coef_begin; icoef < coef_end; icoef++) {
- pred = 1 << (s->cdlms[ch][ilms].scaling - 1);
- residue = s->channel_residues[ch][icoef];
- pred += s->dsp.scalarproduct_and_madd_int32(s->cdlms[ch][ilms].coefs,
- s->cdlms[ch][ilms].lms_prevvalues
- + s->cdlms[ch][ilms].recent,
- s->cdlms[ch][ilms].lms_updates
- + s->cdlms[ch][ilms].recent,
- FFALIGN(s->cdlms[ch][ilms].order,
- WMALL_COEFF_PAD_SIZE),
- WMASIGN(residue));
- input = residue + (pred >> s->cdlms[ch][ilms].scaling);
- lms_update(s, ch, ilms, input);
- s->channel_residues[ch][icoef] = input;
- }
- }
- emms_c();
+#define CD_LMS(bits, ROUND) \
+static void lms_update ## bits (WmallDecodeCtx *s, int ich, int ilms, int input) \
+{ \
+ int recent = s->cdlms[ich][ilms].recent; \
+ int range = 1 << s->bits_per_sample - 1; \
+ int order = s->cdlms[ich][ilms].order; \
+ int ##bits##_t *prev = (int##bits##_t *)s->cdlms[ich][ilms].lms_prevvalues; \
+ \
+ if (recent) \
+ recent--; \
+ else { \
+ memcpy(prev + order, prev, (bits/8) * order); \
+ memcpy(s->cdlms[ich][ilms].lms_updates + order, \
+ s->cdlms[ich][ilms].lms_updates, \
+ sizeof(*s->cdlms[ich][ilms].lms_updates) * order); \
+ recent = order - 1; \
+ } \
+ \
+ prev[recent] = av_clip(input, -range, range - 1); \
+ s->cdlms[ich][ilms].lms_updates[recent] = WMASIGN(input) * s->update_speed[ich]; \
+ \
+ s->cdlms[ich][ilms].lms_updates[recent + (order >> 4)] >>= 2; \
+ s->cdlms[ich][ilms].lms_updates[recent + (order >> 3)] >>= 1; \
+ s->cdlms[ich][ilms].recent = recent; \
+ memset(s->cdlms[ich][ilms].lms_updates + recent + order, 0, \
+ sizeof(s->cdlms[ich][ilms].lms_updates) - \
+ sizeof(*s->cdlms[ich][ilms].lms_updates)*(recent+order)); \
+} \
+ \
+static void revert_cdlms ## bits (WmallDecodeCtx *s, int ch, \
+ int coef_begin, int coef_end) \
+{ \
+ int icoef, pred, ilms, num_lms, residue, input; \
+ \
+ num_lms = s->cdlms_ttl[ch]; \
+ for (ilms = num_lms - 1; ilms >= 0; ilms--) { \
+ for (icoef = coef_begin; icoef < coef_end; icoef++) { \
+ int##bits##_t *prevvalues = (int##bits##_t *)s->cdlms[ch][ilms].lms_prevvalues; \
+ pred = 1 << (s->cdlms[ch][ilms].scaling - 1); \
+ residue = s->channel_residues[ch][icoef]; \
+ pred += s->dsp.scalarproduct_and_madd_int## bits (s->cdlms[ch][ilms].coefs, \
+ prevvalues + s->cdlms[ch][ilms].recent, \
+ s->cdlms[ch][ilms].lms_updates + \
+ s->cdlms[ch][ilms].recent, \
+ FFALIGN(s->cdlms[ch][ilms].order, ROUND), \
+ WMASIGN(residue)); \
+ input = residue + (pred >> s->cdlms[ch][ilms].scaling); \
+ lms_update ## bits(s, ch, ilms, input); \
+ s->channel_residues[ch][icoef] = input; \
+ } \
+ } \
+ if (bits <= 16) emms_c(); \
}
+CD_LMS(16, WMALL_COEFF_PAD_SIZE)
+CD_LMS(32, 8)
+
static void revert_inter_ch_decorr(WmallDecodeCtx *s, int tile_size)
{
if (s->num_channels != 2)
s->quant_stepsize = get_bits(&s->gb, 8) + 1;
reset_codec(s);
- } else if (!s->cdlms[0][0].order) {
+ }
+
+ rawpcm_tile = get_bits1(&s->gb);
+
+ if (!rawpcm_tile && !s->cdlms[0][0].order) {
av_log(s->avctx, AV_LOG_DEBUG,
"Waiting for seekable tile\n");
av_frame_unref(s->frame);
return -1;
}
- rawpcm_tile = get_bits1(&s->gb);
for (i = 0; i < s->num_channels; i++)
s->is_channel_coded[i] = 1;
bits * s->num_channels * subframe_len, get_bits_count(&s->gb));
for (i = 0; i < s->num_channels; i++)
for (j = 0; j < subframe_len; j++)
- s->channel_coeffs[i][j] = get_sbits_long(&s->gb, bits);
+ s->channel_residues[i][j] = get_sbits_long(&s->gb, bits);
} else {
- for (i = 0; i < s->num_channels; i++)
+ for (i = 0; i < s->num_channels; i++) {
if (s->is_channel_coded[i]) {
decode_channel_residues(s, i, subframe_len);
if (s->seekable_tile)
use_high_update_speed(s, i);
else
use_normal_update_speed(s, i);
- revert_cdlms(s, i, 0, subframe_len);
+ if (s->bits_per_sample > 16)
+ revert_cdlms32(s, i, 0, subframe_len);
+ else
+ revert_cdlms16(s, i, 0, subframe_len);
} else {
memset(s->channel_residues[i], 0, sizeof(**s->channel_residues) * subframe_len);
}
+ }
+
+ if (s->do_mclms)
+ revert_mclms(s, subframe_len);
+ if (s->do_inter_ch_decorr)
+ revert_inter_ch_decorr(s, subframe_len);
+ if (s->do_ac_filter)
+ revert_acfilter(s, subframe_len);
+
+ /* Dequantize */
+ if (s->quant_stepsize != 1)
+ for (i = 0; i < s->num_channels; i++)
+ for (j = 0; j < subframe_len; j++)
+ s->channel_residues[i][j] *= s->quant_stepsize;
}
- if (s->do_mclms)
- revert_mclms(s, subframe_len);
- if (s->do_inter_ch_decorr)
- revert_inter_ch_decorr(s, subframe_len);
- if (s->do_ac_filter)
- revert_acfilter(s, subframe_len);
-
- /* Dequantize */
- if (s->quant_stepsize != 1)
- for (i = 0; i < s->num_channels; i++)
- for (j = 0; j < subframe_len; j++)
- s->channel_residues[i][j] *= s->quant_stepsize;
/* Write to proper output buffer depending on bit-depth */
for (i = 0; i < s->channels_for_cur_subframe; i++) {