87 case 16:
s->align *= 2;
93 case MKTAG(
'0',
'C',
'P',
'Y'):
97 case MKTAG(
'1',
'D',
'I',
'F'):
101 case MKTAG(
'2',
'S',
'L',
'P'):
102 case MKTAG(
'3',
'N',
'L',
'P'):
103 case MKTAG(
'4',
'A',
'L',
'P'):
104 case MKTAG(
'5',
'E',
'L',
'P'):
112 s->max_framesize =
s->nb_samples * 16;
124 unsigned z = (x << k) | y;
133 return (z & 1) ? ~((int)(z >> 1)) : z >> 1;
138 const int nb_samples =
s->nb_samples;
139 const int shift =
s->shift;
143 for (
int n = 0; n <
len; n++) {
144 s->samples[0][n] =
s->samples[0][nb_samples + n] >>
shift;
145 s->samples[1][n] =
s->pred[1][n] >>
shift;
148 for (
int n = 0; n <
len; n++) {
149 s->samples[0][n] =
s->samples[0][nb_samples + n] >>
shift;
150 s->samples[1][n] =
s->pred[0][n] >>
shift;
155 for (
int n = 0; n < nb_samples; n++)
156 s->samples[1][n +
len] += (
unsigned)
s->samples[0][n +
len];
158 for (
int n = 0; n <
len; n++) {
159 s->pred[0][n] =
s->samples[1][nb_samples + n];
160 s->pred[1][n] =
s->pred[0][n] - (unsigned)
s->samples[0][nb_samples + n];
168 const int bits =
s->align * 8;
174 for (
int n = 0; n <
s->nb_samples; n++) {
176 s->samples[ch][n] =
get_bits(gb, 8) - 0x80;
180 for (
int n = 0; n <
s->nb_samples; n++) {
192 int ch, finished, fill, correlated;
197 int *samples =
s->samples[ch];
204 if (block_type < 4 && block_type >= 0) {
211 switch (block_type) {
220 if ((
unsigned)
s->shift > 31) {
234 for (
int n = 0; n <
s->nb_samples; n++)
235 samples[n + 4] = fill;
239 for (
int n = 0; n <
s->nb_samples; n++)
244 for (
int n = 0; n <
s->nb_samples; n++)
245 samples[n + 4] =
get_srice(gb, k) + (samples[n + 3] - (unsigned)samples[n + 2]) * 3 +
250 for (
int n = 0; n <
s->nb_samples; n++)
251 samples[n + 4] =
get_srice(gb, k) + (samples[n + 3] * 2U - samples[n + 2]);
255 for (
int n = 0; n <
s->nb_samples; n++)
256 samples[n + 4] =
get_srice(gb, k) + (unsigned)samples[n + 3];
260 for (
int n = 0; n <
s->nb_samples; n++)
278 for (
int n = 0; n < 4; n++)
279 s->samples[0][n] =
s->samples[0][
s->nb_samples + n];
288 int ch, finished, fill, correlated, order;
293 int *samples =
s->samples[ch];
300 if (block_type < 5 && block_type >= 0) {
307 switch (block_type) {
313 if (
s->nb_samples > 570U) {
320 if ((
unsigned)
s->shift > 31) {
334 for (
int n = 0; n <
s->nb_samples; n++)
335 samples[n + 70] = fill;
339 for (
int n = 0; n <
s->nb_samples; n++)
344 for (
int n = 0; n <
s->nb_samples; n++)
345 samples[n + 70] =
get_srice(gb, k) + (samples[n + 69] - (unsigned)samples[n + 68]) * 3 +
350 for (
int n = 0; n <
s->nb_samples; n++)
351 samples[n + 70] =
get_srice(gb, k) + (samples[n + 69] * 2U - samples[n + 68]);
355 for (
int n = 0; n <
s->nb_samples; n++)
360 for (
int n = 0; n <
s->nb_samples; n++)
361 samples[n + 70] =
get_srice(gb, k) + (unsigned)samples[n + 69];
368 for (
int o = 0; o < order; o++)
370 for (
int n = 0; n <
s->nb_samples; n++) {
373 for (
int o = 0; o < order; o++)
374 sum +=
s->filter[ch][o] * (
unsigned)samples[n + 70 - o - 1];
376 samples[n + 70] =
get_srice(gb, k) + (unsigned)(sum >> 4);
394 for (
int n = 0; n < 70; n++)
395 s->samples[0][n] =
s->samples[0][
s->nb_samples + n];
405 s->ac_high = 0xffffu;
408 s->freq_range =
s->freqs[256];
416 return ((
s->freq_range - 1) + (
s->ac_value -
s->ac_low) * (
unsigned)
s->freq_range) /
417 ((
s->ac_high -
s->ac_low) + 1U);
427 s->range_high =
s->freqs[idx + 1];
428 s->range_low =
s->freqs[idx];
437 if (
s->ac_high <
s->ac_low)
440 range = (
s->ac_high -
s->ac_low) + 1;
441 s->ac_high = (
range * (unsigned)
s->range_high) /
s->freq_range +
s->ac_low - 1;
442 s->ac_low += (
range * (unsigned)
s->range_low) /
s->freq_range;
444 if (
s->ac_high <
s->ac_low)
448 if ((
s->ac_high & 0x8000) != (
s->ac_low & 0x8000)) {
449 if (((
s->ac_low & 0x4000) == 0) || ((
s->ac_high & 0x4000) != 0))
451 s->ac_value ^= 0x4000;
453 s->ac_high |= 0x4000;
456 s->ac_low =
s->ac_low * 2;
457 s->ac_high =
s->ac_high * 2 | 1;
458 if (
s->ac_high <
s->ac_low)
467 if (
s->ac_low >
s->ac_value ||
s->ac_high <
s->ac_value)
478 memset(
s->freqs, 0,
sizeof(
s->freqs));
480 for (
int n = 0; n < 256; n++)
481 s->freqs[n+1] =
s->model[n] +
s->freqs[n];
490 memset(
s->model, 0,
sizeof(
s->model));
496 while (start <= end) {
520 int ch, finished, fill, correlated, order = 0;
525 int *samples =
s->samples[ch];
526 int *ac_pred =
s->ac_pred;
527 int *ac_out =
s->ac_out;
533 memset(
s->ac_out, 0,
sizeof(
s->ac_out));
538 if (block_type >= 0 && block_type <= 7) {
545 if (block_type <= 2 || block_type == 6 || block_type == 13 ||
546 block_type == 14 || block_type == 15 || block_type == 19) {
550 for (
int o = 0; o < order; o++)
554 if (block_type >= 0 && block_type <= 7) {
555 for (
int n = 0; n <
s->nb_samples; n++)
558 for (
int n = 0; n <
s->nb_samples; n++)
562 if (block_type >= 13 && block_type <= 20) {
563 const int ac_size =
get_bits(gb, 12);
581 for (
int n = 0; n <
s->nb_samples; n++) {
584 ac_out[n] = ac - 0x80;
595 switch (block_type) {
601 if (
s->nb_samples > 570U) {
608 if ((
unsigned)
s->shift > 31) {
622 for (
int n = 0; n <
s->nb_samples; n++)
623 samples[n + 70] = fill;
627 for (
int n = 0; n <
s->nb_samples; n++)
633 for (
int n = 0; n <
s->nb_samples; n++)
634 samples[n + 70] += ac_out[n] + samples[n + 69] * 3U - samples[n + 68] * 3U + samples[n + 67];
639 for (
int n = 0; n < 70; n++) {
640 ac_pred[n] = samples[n];
644 for (
int n = 0; n <
s->nb_samples; n++) {
647 for (
int o = 0; o < order; o++)
648 sum +=
s->filter[ch][o] * (
unsigned)samples[n + 70 - o - 1];
650 samples[n + 70] += ac_out[n] + (unsigned)(sum >> 4);
653 for (
int n = 0; n < 70; n++)
654 samples[n] = ac_pred[n];
656 for (
int n = 0; n <
s->nb_samples; n++)
657 samples[n + 70] += ac_out[n] + samples[n + 69] * 3U - samples[n + 68] * 3U + samples[n + 67];
663 for (
int n = 0; n <
s->nb_samples; n++)
664 samples[n + 70] += ac_out[n] + samples[n + 69] * 2U - samples[n + 68];
669 for (
int n = 0; n <
s->nb_samples; n++)
670 samples[n + 70] += ac_out[n];
675 for (
int n = 0; n <
s->nb_samples; n++)
676 samples[n + 70] += ac_out[n] + (
unsigned)samples[n + 69];
681 for (
int n = 0; n < 70; n++) {
682 ac_pred[n] = samples[n];
686 for (
int n = 0; n <
s->nb_samples; n++) {
689 for (
int o = 0; o < order; o++)
690 sum +=
s->filter[ch][o] * (
unsigned)samples[n + 70 - o - 1];
692 samples[n + 70] += ac_out[n] + (unsigned)(sum >> 4);
695 for (
int n = 0; n < 70; n++)
696 samples[n] = ac_pred[n];
698 for (
int n = 0; n <
s->nb_samples; n++)
699 samples[n + 70] += samples[n + 69] * 2U - samples[n + 68];
705 for (
int n = 0; n < 70; n++) {
706 ac_pred[n] = samples[n];
710 for (
int n = 0; n <
s->nb_samples; n++) {
713 for (
int o = 0; o < order; o++)
714 sum +=
s->filter[ch][o] * (
unsigned)samples[n + 70 - o - 1];
716 samples[n + 70] += (unsigned)ac_out[n] + (sum >> 4);
719 for (
int n = 0; n < 70; n++)
720 samples[n] = ac_pred[n];
722 for (
int n = 0; n <
s->nb_samples; n++)
723 samples[n + 70] += (
unsigned)samples[n + 69];
729 for (
int n = 0; n <
s->nb_samples; n++) {
732 for (
int o = 0; o < order; o++)
733 sum +=
s->filter[ch][o] * (
unsigned)samples[n + 70 - o - 1];
735 samples[n + 70] += (unsigned)ac_out[n] + (sum >> 4);
753 for (
int n = 0; n < 70; n++)
754 s->samples[0][n] =
s->samples[0][
s->nb_samples + n];
765 int buf_size, input_buf_size;
769 if ((!
pkt->size && !
s->bitstream_size) ||
s->nb_samples == 0 ||
s->eof) {
774 buf_size =
FFMIN(
pkt->size,
s->max_framesize -
s->bitstream_size);
775 input_buf_size = buf_size;
777 memmove(
s->bitstream, &
s->bitstream[
s->bitstream_index],
s->bitstream_size);
778 s->bitstream_index = 0;
781 memcpy(&
s->bitstream[
s->bitstream_index +
s->bitstream_size],
pkt->data, buf_size);
782 buf = &
s->bitstream[
s->bitstream_index];
783 buf_size +=
s->bitstream_size;
784 s->bitstream_size = buf_size;
785 if (buf_size < s->max_framesize &&
pkt->data) {
787 return input_buf_size;
795 case MKTAG(
'0',
'C',
'P',
'Y'):
798 case MKTAG(
'1',
'D',
'I',
'F'):
801 case MKTAG(
'2',
'S',
'L',
'P'):
802 case MKTAG(
'3',
'N',
'L',
'P'):
803 case MKTAG(
'4',
'A',
'L',
'P'):
806 case MKTAG(
'5',
'E',
'L',
'P'):
821 s->bitstream_size = 0;
822 s->bitstream_index = 0;
828 frame->nb_samples =
s->nb_samples;
835 uint8_t *
dst = (uint8_t *)
frame->extended_data[ch];
836 const int *
src =
s->samples[ch] +
s->offset;
838 for (
int n = 0; n <
frame->nb_samples; n++)
839 dst[n] =
src[n] * (1U <<
s->shift) + 0x80U;
844 int16_t *
dst = (int16_t *)
frame->extended_data[ch];
845 const int *
src =
s->samples[ch] +
s->offset;
847 for (
int n = 0; n <
frame->nb_samples; n++)
848 dst[n] =
src[n] * (1U <<
s->shift);
855 if (
s->bitstream_size) {
856 s->bitstream_index += n;
857 s->bitstream_size -= n;
858 return input_buf_size;
869 s->bitstream_size = 0;
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_wavarc_decoder
Libavcodec external API header.
#define prob(name, subs,...)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define CODEC_SAMPLEFMTS(...)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
static const uint8_t bits[8]
bitstream reader API header.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int get_bits_left(GetBitContext *gb)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
static int shift(int a, int b)
static int32_t get_srice(GetBitContext *gb, int x)
static int ac_init(AVCodecContext *avctx, WavArcContext *s, GetBitContext *gb)
static unsigned get_urice(GetBitContext *gb, int k)
static uint16_t ac_get_prob(WavArcContext *s)
static int ac_normalize(AVCodecContext *avctx, WavArcContext *s, GetBitContext *gb)
static int decode_0cpy(AVCodecContext *avctx, WavArcContext *s, GetBitContext *gb)
static int decode_5elp(AVCodecContext *avctx, WavArcContext *s, GetBitContext *gb)
static int decode_1dif(AVCodecContext *avctx, WavArcContext *s, GetBitContext *gb)
static av_cold int wavarc_close(AVCodecContext *avctx)
static void do_stereo(WavArcContext *s, int ch, int correlated, int len)
static uint8_t ac_map_symbol(WavArcContext *s, uint16_t prob)
static void ac_init_model(WavArcContext *s)
static int decode_2slp(AVCodecContext *avctx, WavArcContext *s, GetBitContext *gb)
static av_cold int wavarc_init(AVCodecContext *avctx)
static int wavarc_decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *pkt)
static int get_srice(GetBitContext *gb, int k)
static int ac_read_model(AVCodecContext *avctx, WavArcContext *s, GetBitContext *gb)
#define MKTAG(a, b, c, d)
static av_const int sign_extend(int val, unsigned bits)
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
#define FF_ARRAY_ELEMS(a)
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
int sample_rate
samples per second
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.