int16_t mclms_coeffs_cur[4];
int mclms_prevvalues[64]; // FIXME: should be 32-bit / 16-bit depending on bit-depth
int16_t mclms_updates[64];
+ int mclms_recent;
int movave_scaling;
int quant_stepsize;
int16_t coefs[256];
int lms_prevvalues[512]; // FIXME: see above
int16_t lms_updates[512]; // and here too
+ int recent;
} cdlms[2][9]; /* XXX: Here, 2 is the max. no. of channels allowed,
9 is the maximum no. of filters per channel.
Question is, why 2 if WMALL_MAX_CHANNELS == 8 */
int bV3RTM;
int is_channel_coded[2]; // XXX: same question as above applies here too (and below)
+ int update_speed[2];
int transient[2];
int transient_pos[2];
#define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
+static int num_logged_tiles = 0;
+
/**
*@brief helper function to print the most important members of the context
*@param s context
s->channel_residues[ch][0] = get_sbits(&s->gb, s->bits_per_sample);
i++;
}
+ av_log(0, 0, "%8d: ", num_logged_tiles++);
for(; i < tile_size; i++) {
int quo = 0, rem, rem_bits, residue;
while(get_bits1(&s->gb))
residue = residue >> 1;
s->channel_residues[ch][i] = residue;
+ //if (num_logged_tiles < 1)
+ av_log(0, 0, "%4d ", residue);
// dprintf(s->avctx, "%5d: %5d %10d %12d %12d %5d %-16d %04x\n",i, quo, ave_mean, s->ave_sum[ch], rem, rem_bits, s->channel_residues[ch][i], show_bits(&s->gb, 16));
}
+ av_log(0, 0, "\n Tile size = %d\n", tile_size);
return 0;
}
}
+static void reset_codec(WmallDecodeCtx *s)
+{
+ int ich, ilms;
+ s->mclms_recent = s->mclms_order * s->num_channels;
+ for (ich = 0; ich < s->num_channels; ich++)
+ for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++)
+ s->cdlms[ich][ilms].recent = s->cdlms[ich][ilms].order;
+}
+
+
+
+static int lms_predict(WmallDecodeCtx *s, int ich, int ilms)
+{
+ int32_t pred, icoef;
+ int recent = s->cdlms[ich][ilms].recent;
+
+ for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
+ pred += s->cdlms[ich][ilms].coefs[icoef] *
+ s->cdlms[ich][ilms].lms_prevvalues[icoef + recent];
+
+ pred += (1 << (s->cdlms[ich][ilms].scaling - 1));
+ /* XXX: Table 29 has:
+ iPred >= cdlms[iCh][ilms].scaling;
+ seems to me like a missing > */
+ pred >>= s->cdlms[ich][ilms].scaling;
+ return pred;
+}
+
+static void lms_update(WmallDecodeCtx *s, int ich, int ilms, int32_t input, int32_t pred)
+{
+ int icoef;
+ int recent = s->cdlms[ich][ilms].recent;
+ int range = 1 << (s->bits_per_sample - 1);
+ int bps = s->bits_per_sample > 16 ? 4 : 2; // bytes per sample
+
+ if (input > pred) {
+ for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
+ s->cdlms[ich][ilms].coefs[icoef] +=
+ s->cdlms[ich][ilms].lms_updates[icoef + recent];
+ } else {
+ for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
+ s->cdlms[ich][ilms].coefs[icoef] -=
+ s->cdlms[ich][ilms].lms_updates[icoef]; // XXX: [icoef + recent] ?
+ }
+ s->cdlms[ich][ilms].recent--;
+ s->cdlms[ich][ilms].lms_prevvalues[recent] = av_clip(input, -range, range - 1);
+
+ if (input > pred)
+ s->cdlms[ich][ilms].lms_updates[recent] = s->update_speed[ich];
+ else if (input < pred)
+ s->cdlms[ich][ilms].lms_updates[recent] = -s->update_speed[ich];
+
+ /* XXX: spec says:
+ cdlms[iCh][ilms].updates[iRecent + cdlms[iCh][ilms].order >> 4] >>= 2;
+ lms_updates[iCh][ilms][iRecent + cdlms[iCh][ilms].order >> 3] >>= 1;
+
+ Questions is - are cdlms[iCh][ilms].updates[] and lms_updates[][][] two
+ seperate buffers? Here I've assumed that the two are same which makes
+ more sense to me.
+ */
+ s->cdlms[ich][ilms].lms_updates[recent + s->cdlms[ich][ilms].order >> 4] >>= 2;
+ s->cdlms[ich][ilms].lms_updates[recent + s->cdlms[ich][ilms].order >> 3] >>= 1;
+ /* XXX: recent + (s->cdlms[ich][ilms].order >> 4) ? */
+
+ if (s->cdlms[ich][ilms].recent == 0) {
+ /* XXX: This memcpy()s will probably fail if a fixed 32-bit buffer is used.
+ follow kshishkov's suggestion of using a union. */
+ memcpy(s->cdlms[ich][ilms].lms_prevvalues + s->cdlms[ich][ilms].order,
+ s->cdlms[ich][ilms].lms_prevvalues,
+ bps * s->cdlms[ich][ilms].order);
+ memcpy(s->cdlms[ich][ilms].lms_updates + s->cdlms[ich][ilms].order,
+ s->cdlms[ich][ilms].lms_updates,
+ bps * s->cdlms[ich][ilms].order);
+ s->cdlms[ich][ilms].recent = s->cdlms[ich][ilms].order;
+ }
+}
+
+static void use_high_update_speed(WmallDecodeCtx *s, int ich)
+{
+ int ilms, recent, icoef;
+ s->update_speed[ich] = 16;
+ for (ilms = s->cdlms_ttl[ich]; ilms >= 0; ilms--) {
+ recent = s->cdlms[ich][ilms].recent;
+ if (s->bV3RTM) {
+ for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
+ s->cdlms[ich][ilms].lms_updates[icoef + recent] *= 2;
+ } else {
+ for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
+ s->cdlms[ich][ilms].lms_updates[icoef] *= 2;
+ }
+ }
+}
+
+static void use_normal_update_speed(WmallDecodeCtx *s, int ich)
+{
+ int ilms, recent, icoef;
+ s->update_speed[ich] = 8;
+ for (ilms = s->cdlms_ttl[ich]; ilms >= 0; ilms--) {
+ recent = s->cdlms[ich][ilms].recent;
+ if (s->bV3RTM) {
+ for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
+ s->cdlms[ich][ilms].lms_updates[icoef + recent] /= 2;
+ } else {
+ for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
+ s->cdlms[ich][ilms].lms_updates[icoef] /= 2;
+ }
+ }
+}
+
/**
*@brief Decode a single subframe (block).
*@param s codec context
s->seekable_tile = get_bits1(&s->gb);
if(s->seekable_tile) {
- // XXX: 6.2.2 clear_codec_buffers()
+ clear_codec_buffers(s);
s->do_arith_coding = get_bits1(&s->gb);
if(s->do_arith_coding) {
s->movave_scaling = get_bits(&s->gb, 3);
s->quant_stepsize = get_bits(&s->gb, 8) + 1;
- // XXX: 6.2.2 reset_codec()
+ reset_codec(s);
}
rawpcm_tile = get_bits1(&s->gb);