Prepare WavPack decoder to support floating point output.

Patch by Laurent Aimar (f-e-n-r-i-r .@.t. v=i=d=e=o=l=a=n .d.o.t. o=r=g)

Originally committed as revision 18753 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Laurent Aimar 2009-05-06 05:28:06 +00:00 committed by Kostya Shishkov
parent 778bc09bbe
commit cabb81113a
1 changed files with 17 additions and 17 deletions

View File

@ -357,7 +357,7 @@ static inline int wv_get_value_integer(WavpackContext *s, uint32_t *crc, int S)
return (((S + bit) << s->shift) - bit) << s->post_shift; return (((S + bit) << s->shift) - bit) << s->post_shift;
} }
static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *dst, const int hires) static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *dst, const int type)
{ {
int i, j, count = 0; int i, j, count = 0;
int last, t; int last, t;
@ -393,7 +393,7 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
B = s->decorr[i].samplesB[pos]; B = s->decorr[i].samplesB[pos];
j = (pos + t) & 7; j = (pos + t) & 7;
} }
if(hires){ if(type != SAMPLE_FMT_S16){
L2 = L + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10); L2 = L + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10);
R2 = R + ((s->decorr[i].weightB * (int64_t)B + 512) >> 10); R2 = R + ((s->decorr[i].weightB * (int64_t)B + 512) >> 10);
}else{ }else{
@ -405,13 +405,13 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
s->decorr[i].samplesA[j] = L = L2; s->decorr[i].samplesA[j] = L = L2;
s->decorr[i].samplesB[j] = R = R2; s->decorr[i].samplesB[j] = R = R2;
}else if(t == -1){ }else if(t == -1){
if(hires) if(type != SAMPLE_FMT_S16)
L2 = L + ((s->decorr[i].weightA * (int64_t)s->decorr[i].samplesA[0] + 512) >> 10); L2 = L + ((s->decorr[i].weightA * (int64_t)s->decorr[i].samplesA[0] + 512) >> 10);
else else
L2 = L + ((s->decorr[i].weightA * s->decorr[i].samplesA[0] + 512) >> 10); L2 = L + ((s->decorr[i].weightA * s->decorr[i].samplesA[0] + 512) >> 10);
UPDATE_WEIGHT_CLIP(s->decorr[i].weightA, s->decorr[i].delta, s->decorr[i].samplesA[0], L); UPDATE_WEIGHT_CLIP(s->decorr[i].weightA, s->decorr[i].delta, s->decorr[i].samplesA[0], L);
L = L2; L = L2;
if(hires) if(type != SAMPLE_FMT_S16)
R2 = R + ((s->decorr[i].weightB * (int64_t)L2 + 512) >> 10); R2 = R + ((s->decorr[i].weightB * (int64_t)L2 + 512) >> 10);
else else
R2 = R + ((s->decorr[i].weightB * L2 + 512) >> 10); R2 = R + ((s->decorr[i].weightB * L2 + 512) >> 10);
@ -419,7 +419,7 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
R = R2; R = R2;
s->decorr[i].samplesA[0] = R; s->decorr[i].samplesA[0] = R;
}else{ }else{
if(hires) if(type != SAMPLE_FMT_S16)
R2 = R + ((s->decorr[i].weightB * (int64_t)s->decorr[i].samplesB[0] + 512) >> 10); R2 = R + ((s->decorr[i].weightB * (int64_t)s->decorr[i].samplesB[0] + 512) >> 10);
else else
R2 = R + ((s->decorr[i].weightB * s->decorr[i].samplesB[0] + 512) >> 10); R2 = R + ((s->decorr[i].weightB * s->decorr[i].samplesB[0] + 512) >> 10);
@ -431,7 +431,7 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
s->decorr[i].samplesA[0] = R; s->decorr[i].samplesA[0] = R;
} }
if(hires) if(type != SAMPLE_FMT_S16)
L2 = L + ((s->decorr[i].weightA * (int64_t)R2 + 512) >> 10); L2 = L + ((s->decorr[i].weightA * (int64_t)R2 + 512) >> 10);
else else
L2 = L + ((s->decorr[i].weightA * R2 + 512) >> 10); L2 = L + ((s->decorr[i].weightA * R2 + 512) >> 10);
@ -445,7 +445,7 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
L += (R -= (L >> 1)); L += (R -= (L >> 1));
crc = (crc * 3 + L) * 3 + R; crc = (crc * 3 + L) * 3 + R;
if(hires){ if(type == SAMPLE_FMT_S32){
*dst32++ = wv_get_value_integer(s, &crc_extra_bits, L); *dst32++ = wv_get_value_integer(s, &crc_extra_bits, L);
*dst32++ = wv_get_value_integer(s, &crc_extra_bits, R); *dst32++ = wv_get_value_integer(s, &crc_extra_bits, R);
} else { } else {
@ -466,7 +466,7 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
return count * 2; return count * 2;
} }
static inline int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, void *dst, const int hires) static inline int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, void *dst, const int type)
{ {
int i, j, count = 0; int i, j, count = 0;
int last, t; int last, t;
@ -495,7 +495,7 @@ static inline int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, void *dst
A = s->decorr[i].samplesA[pos]; A = s->decorr[i].samplesA[pos];
j = (pos + t) & 7; j = (pos + t) & 7;
} }
if(hires) if(type != SAMPLE_FMT_S16)
S = T + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10); S = T + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10);
else else
S = T + ((s->decorr[i].weightA * A + 512) >> 10); S = T + ((s->decorr[i].weightA * A + 512) >> 10);
@ -505,7 +505,7 @@ static inline int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, void *dst
pos = (pos + 1) & 7; pos = (pos + 1) & 7;
crc = crc * 3 + S; crc = crc * 3 + S;
if(hires) if(type == SAMPLE_FMT_S32)
*dst32++ = wv_get_value_integer(s, &crc_extra_bits, S); *dst32++ = wv_get_value_integer(s, &crc_extra_bits, S);
else else
*dst16++ = wv_get_value_integer(s, &crc_extra_bits, S); *dst16++ = wv_get_value_integer(s, &crc_extra_bits, S);
@ -798,16 +798,16 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
} }
if(s->stereo_in){ if(s->stereo_in){
if(bpp == 2) if(avctx->sample_fmt == SAMPLE_FMT_S16)
samplecount = wv_unpack_stereo(s, &s->gb, samples, 0); samplecount = wv_unpack_stereo(s, &s->gb, samples, SAMPLE_FMT_S16);
else else
samplecount = wv_unpack_stereo(s, &s->gb, samples, 1); samplecount = wv_unpack_stereo(s, &s->gb, samples, SAMPLE_FMT_S32);
}else{ }else{
if(bpp == 2) if(avctx->sample_fmt == SAMPLE_FMT_S16)
samplecount = wv_unpack_mono(s, &s->gb, samples, 0); samplecount = wv_unpack_mono(s, &s->gb, samples, SAMPLE_FMT_S16);
else else
samplecount = wv_unpack_mono(s, &s->gb, samples, 1); samplecount = wv_unpack_mono(s, &s->gb, samples, SAMPLE_FMT_S32);
if(s->stereo && bpp == 2){ if(s->stereo && avctx->sample_fmt == SAMPLE_FMT_S16){
int16_t *dst = (int16_t*)samples + samplecount * 2; int16_t *dst = (int16_t*)samples + samplecount * 2;
int16_t *src = (int16_t*)samples + samplecount; int16_t *src = (int16_t*)samples + samplecount;
int cnt = samplecount; int cnt = samplecount;