#include "unary.h"
/**
- * @file libavcodec/wavpack.c
+ * @file
* WavPack lossless audio decoder
*/
float *dstfl = dst;
if(s->samples_left == s->samples)
- s->one = s->zero = s->zeroes = 0;
+ s->one = s->zero = s->zeroes = 0;
do{
L = wv_get_value(s, gb, 0, &last);
if(last) break;
B = s->decorr[i].samplesB[pos];
j = (pos + t) & 7;
}
- if(type != SAMPLE_FMT_S16){
+ if(type != AV_SAMPLE_FMT_S16){
L2 = L + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10);
R2 = R + ((s->decorr[i].weightB * (int64_t)B + 512) >> 10);
}else{
s->decorr[i].samplesA[j] = L = L2;
s->decorr[i].samplesB[j] = R = R2;
}else if(t == -1){
- if(type != SAMPLE_FMT_S16)
+ if(type != AV_SAMPLE_FMT_S16)
L2 = L + ((s->decorr[i].weightA * (int64_t)s->decorr[i].samplesA[0] + 512) >> 10);
else
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);
L = L2;
- if(type != SAMPLE_FMT_S16)
+ if(type != AV_SAMPLE_FMT_S16)
R2 = R + ((s->decorr[i].weightB * (int64_t)L2 + 512) >> 10);
else
R2 = R + ((s->decorr[i].weightB * L2 + 512) >> 10);
R = R2;
s->decorr[i].samplesA[0] = R;
}else{
- if(type != SAMPLE_FMT_S16)
+ if(type != AV_SAMPLE_FMT_S16)
R2 = R + ((s->decorr[i].weightB * (int64_t)s->decorr[i].samplesB[0] + 512) >> 10);
else
R2 = R + ((s->decorr[i].weightB * s->decorr[i].samplesB[0] + 512) >> 10);
s->decorr[i].samplesA[0] = R;
}
- if(type != SAMPLE_FMT_S16)
+ if(type != AV_SAMPLE_FMT_S16)
L2 = L + ((s->decorr[i].weightA * (int64_t)R2 + 512) >> 10);
else
L2 = L + ((s->decorr[i].weightA * R2 + 512) >> 10);
L += (R -= (L >> 1));
crc = (crc * 3 + L) * 3 + R;
- if(type == SAMPLE_FMT_FLT){
+ if(type == AV_SAMPLE_FMT_FLT){
*dstfl++ = wv_get_value_float(s, &crc_extra_bits, L);
*dstfl++ = wv_get_value_float(s, &crc_extra_bits, R);
- } else if(type == SAMPLE_FMT_S32){
+ } else if(type == AV_SAMPLE_FMT_S32){
*dst32++ = wv_get_value_integer(s, &crc_extra_bits, L);
*dst32++ = wv_get_value_integer(s, &crc_extra_bits, R);
} else {
s->samples_left -= count;
if(!s->samples_left){
- if(crc != s->CRC){
- av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
- return -1;
- }
- if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){
- av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
- return -1;
- }
- wv_reset_saved_context(s);
+ if(crc != s->CRC){
+ av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
+ return -1;
+ }
+ if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){
+ av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
+ return -1;
+ }
+ wv_reset_saved_context(s);
}else{
s->pos = pos;
s->sc.crc = crc;
float *dstfl = dst;
if(s->samples_left == s->samples)
- s->one = s->zero = s->zeroes = 0;
+ s->one = s->zero = s->zeroes = 0;
do{
T = wv_get_value(s, gb, 0, &last);
S = 0;
A = s->decorr[i].samplesA[pos];
j = (pos + t) & 7;
}
- if(type != SAMPLE_FMT_S16)
+ if(type != AV_SAMPLE_FMT_S16)
S = T + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10);
else
S = T + ((s->decorr[i].weightA * A + 512) >> 10);
pos = (pos + 1) & 7;
crc = crc * 3 + S;
- if(type == SAMPLE_FMT_FLT)
+ if(type == AV_SAMPLE_FMT_FLT)
*dstfl++ = wv_get_value_float(s, &crc_extra_bits, S);
- else if(type == SAMPLE_FMT_S32)
+ else if(type == AV_SAMPLE_FMT_S32)
*dst32++ = wv_get_value_integer(s, &crc_extra_bits, S);
else
*dst16++ = wv_get_value_integer(s, &crc_extra_bits, S);
count++;
- }while(!last && count < s->samples);
+ }while(!last && count < s->max_samples);
s->samples_left -= count;
if(!s->samples_left){
- if(crc != s->CRC){
- av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
- return -1;
- }
- if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){
- av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
- return -1;
- }
- wv_reset_saved_context(s);
+ if(crc != s->CRC){
+ av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
+ return -1;
+ }
+ if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){
+ av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
+ return -1;
+ }
+ wv_reset_saved_context(s);
}else{
s->pos = pos;
s->sc.crc = crc;
WavpackContext *s = avctx->priv_data;
s->avctx = avctx;
+ if (avctx->channels > 2) {
+ av_log(avctx, AV_LOG_ERROR, "Multichannel WavPack is not supported yet.\n");
+ return -1;
+ }
s->stereo = (avctx->channels == 2);
if(avctx->bits_per_coded_sample <= 16)
- avctx->sample_fmt = SAMPLE_FMT_S16;
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
else
- avctx->sample_fmt = SAMPLE_FMT_S32;
+ avctx->sample_fmt = AV_SAMPLE_FMT_S32;
avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
wv_reset_saved_context(s);
}
if(!s->samples_left){
- memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
- memset(s->ch, 0, sizeof(s->ch));
- s->extra_bits = 0;
- s->and = s->or = s->shift = 0;
- s->got_extra_bits = 0;
+ memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
+ memset(s->ch, 0, sizeof(s->ch));
+ s->extra_bits = 0;
+ s->and = s->or = s->shift = 0;
+ s->got_extra_bits = 0;
}
s->samples = AV_RL32(buf); buf += 4;
s->frame_flags = AV_RL32(buf); buf += 4;
if(s->frame_flags&0x80){
bpp = sizeof(float);
- avctx->sample_fmt = SAMPLE_FMT_FLT;
+ avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
} else if((s->frame_flags&0x03) <= 1){
bpp = 2;
- avctx->sample_fmt = SAMPLE_FMT_S16;
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
} else {
bpp = 4;
- avctx->sample_fmt = SAMPLE_FMT_S32;
+ avctx->sample_fmt = AV_SAMPLE_FMT_S32;
}
s->stereo_in = (s->frame_flags & WV_FALSE_STEREO) ? 0 : s->stereo;
s->joint = s->frame_flags & WV_JOINT_STEREO;
if(id & WP_IDF_ODD) buf++;
}
if(!s->samples_left){
- if(!got_terms){
- av_log(avctx, AV_LOG_ERROR, "No block with decorrelation terms\n");
- return -1;
- }
- if(!got_weights){
- av_log(avctx, AV_LOG_ERROR, "No block with decorrelation weights\n");
- return -1;
- }
- if(!got_samples){
- av_log(avctx, AV_LOG_ERROR, "No block with decorrelation samples\n");
- return -1;
- }
- if(!got_entropy){
- av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n");
- return -1;
- }
- if(s->hybrid && !got_hybrid){
- av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n");
- return -1;
- }
- if(!got_bs){
- av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n");
- return -1;
- }
- if(!got_float && avctx->sample_fmt == SAMPLE_FMT_FLT){
- av_log(avctx, AV_LOG_ERROR, "Float information not found\n");
- return -1;
- }
- if(s->got_extra_bits && avctx->sample_fmt != SAMPLE_FMT_FLT){
- const int size = get_bits_left(&s->gb_extra_bits);
- const int wanted = s->samples * s->extra_bits << s->stereo_in;
- if(size < wanted){
- av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n");
- s->got_extra_bits = 0;
+ if(!got_terms){
+ av_log(avctx, AV_LOG_ERROR, "No block with decorrelation terms\n");
+ return -1;
}
- }
- s->samples_left = s->samples;
+ if(!got_weights){
+ av_log(avctx, AV_LOG_ERROR, "No block with decorrelation weights\n");
+ return -1;
+ }
+ if(!got_samples){
+ av_log(avctx, AV_LOG_ERROR, "No block with decorrelation samples\n");
+ return -1;
+ }
+ if(!got_entropy){
+ av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n");
+ return -1;
+ }
+ if(s->hybrid && !got_hybrid){
+ av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n");
+ return -1;
+ }
+ if(!got_bs){
+ av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n");
+ return -1;
+ }
+ if(!got_float && avctx->sample_fmt == AV_SAMPLE_FMT_FLT){
+ av_log(avctx, AV_LOG_ERROR, "Float information not found\n");
+ return -1;
+ }
+ if(s->got_extra_bits && avctx->sample_fmt != AV_SAMPLE_FMT_FLT){
+ const int size = get_bits_left(&s->gb_extra_bits);
+ const int wanted = s->samples * s->extra_bits << s->stereo_in;
+ if(size < wanted){
+ av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n");
+ s->got_extra_bits = 0;
+ }
+ }
+ s->samples_left = s->samples;
}else{
init_get_bits(&s->gb, avpkt->data + s->sc.offset, s->sc.size);
skip_bits_long(&s->gb, s->sc.bits_used);
}
if(s->stereo_in){
- if(avctx->sample_fmt == SAMPLE_FMT_S16)
- samplecount = wv_unpack_stereo(s, &s->gb, samples, SAMPLE_FMT_S16);
- else if(avctx->sample_fmt == SAMPLE_FMT_S32)
- samplecount = wv_unpack_stereo(s, &s->gb, samples, SAMPLE_FMT_S32);
+ if(avctx->sample_fmt == AV_SAMPLE_FMT_S16)
+ samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_S16);
+ else if(avctx->sample_fmt == AV_SAMPLE_FMT_S32)
+ samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_S32);
else
- samplecount = wv_unpack_stereo(s, &s->gb, samples, SAMPLE_FMT_FLT);
+ samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_FLT);
}else{
- if(avctx->sample_fmt == SAMPLE_FMT_S16)
- samplecount = wv_unpack_mono(s, &s->gb, samples, SAMPLE_FMT_S16);
- else if(avctx->sample_fmt == SAMPLE_FMT_S32)
- samplecount = wv_unpack_mono(s, &s->gb, samples, SAMPLE_FMT_S32);
+ if(avctx->sample_fmt == AV_SAMPLE_FMT_S16)
+ samplecount = wv_unpack_mono(s, &s->gb, samples, AV_SAMPLE_FMT_S16);
+ else if(avctx->sample_fmt == AV_SAMPLE_FMT_S32)
+ samplecount = wv_unpack_mono(s, &s->gb, samples, AV_SAMPLE_FMT_S32);
else
- samplecount = wv_unpack_mono(s, &s->gb, samples, SAMPLE_FMT_FLT);
+ samplecount = wv_unpack_mono(s, &s->gb, samples, AV_SAMPLE_FMT_FLT);
- if(s->stereo && avctx->sample_fmt == SAMPLE_FMT_S16){
+ if(s->stereo && avctx->sample_fmt == AV_SAMPLE_FMT_S16){
int16_t *dst = (int16_t*)samples + samplecount * 2;
int16_t *src = (int16_t*)samples + samplecount;
int cnt = samplecount;
*--dst = *src;
}
samplecount *= 2;
- }else if(s->stereo && avctx->sample_fmt == SAMPLE_FMT_S32){
+ }else if(s->stereo && avctx->sample_fmt == AV_SAMPLE_FMT_S32){
int32_t *dst = (int32_t*)samples + samplecount * 2;
int32_t *src = (int32_t*)samples + samplecount;
int cnt = samplecount;
AVCodec wavpack_decoder = {
"wavpack",
- CODEC_TYPE_AUDIO,
+ AVMEDIA_TYPE_AUDIO,
CODEC_ID_WAVPACK,
sizeof(WavpackContext),
wavpack_decode_init,