diff options
author | Mashiat Sarker Shakkhar <shahriman_ams@yahoo.com> | 2011-11-06 03:02:41 +0600 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-11-11 03:26:48 +0100 |
commit | 80fa79a306c6be1dd4ed0fb4df8c582bb2f74fe5 (patch) | |
tree | f565010a0a33df234be2550d275ba92657652bec | |
parent | afd930dca23adad09ffbf6f9ff35b7258047895a (diff) | |
download | ffmpeg-80fa79a306c6be1dd4ed0fb4df8c582bb2f74fe5.tar.gz |
Implement lms_update()
(cherry picked from commit 17219c79360bc2bdaf3e7f47178af42fade140a8)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavcodec/wmalosslessdec.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c index 8f7f290548..a6c6365f03 100644 --- a/libavcodec/wmalosslessdec.c +++ b/libavcodec/wmalosslessdec.c @@ -774,6 +774,55 @@ static int lms_predict(WmallDecodeCtx *s, int ich, int ilms) 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; + } +} + /** *@brief Decode a single subframe (block). *@param s codec context |