Commit 44c56a16 authored by Mans Rullgard's avatar Mans Rullgard

flacdec: simplify sample buffer handling

Pass pointer to sample buffer instead of channel number to various
functions called from decode_subframe().  Also simplify a few
expressions within this function.
parent ea98507d
...@@ -204,11 +204,11 @@ static int get_metadata_size(const uint8_t *buf, int buf_size) ...@@ -204,11 +204,11 @@ static int get_metadata_size(const uint8_t *buf, int buf_size)
return buf_size - (buf_end - buf); return buf_size - (buf_end - buf);
} }
static int decode_residuals(FLACContext *s, int channel, int pred_order) static int decode_residuals(FLACContext *s, int32_t *decoded, int pred_order)
{ {
int i, tmp, partition, method_type, rice_order; int i, tmp, partition, method_type, rice_order;
int rice_bits, rice_esc; int rice_bits, rice_esc;
int sample = 0, samples; int samples;
method_type = get_bits(&s->gb, 2); method_type = get_bits(&s->gb, 2);
if (method_type > 1) { if (method_type > 1) {
...@@ -229,17 +229,17 @@ static int decode_residuals(FLACContext *s, int channel, int pred_order) ...@@ -229,17 +229,17 @@ static int decode_residuals(FLACContext *s, int channel, int pred_order)
rice_bits = 4 + method_type; rice_bits = 4 + method_type;
rice_esc = (1 << rice_bits) - 1; rice_esc = (1 << rice_bits) - 1;
sample= decoded += pred_order;
i= pred_order; i= pred_order;
for (partition = 0; partition < (1 << rice_order); partition++) { for (partition = 0; partition < (1 << rice_order); partition++) {
tmp = get_bits(&s->gb, rice_bits); tmp = get_bits(&s->gb, rice_bits);
if (tmp == rice_esc) { if (tmp == rice_esc) {
tmp = get_bits(&s->gb, 5); tmp = get_bits(&s->gb, 5);
for (; i < samples; i++, sample++) for (; i < samples; i++)
s->decoded[channel][sample] = get_sbits_long(&s->gb, tmp); *decoded++ = get_sbits_long(&s->gb, tmp);
} else { } else {
for (; i < samples; i++, sample++) { for (; i < samples; i++) {
s->decoded[channel][sample] = get_sr_golomb_flac(&s->gb, tmp, INT_MAX, 0); *decoded++ = get_sr_golomb_flac(&s->gb, tmp, INT_MAX, 0);
} }
} }
i= 0; i= 0;
...@@ -248,11 +248,10 @@ static int decode_residuals(FLACContext *s, int channel, int pred_order) ...@@ -248,11 +248,10 @@ static int decode_residuals(FLACContext *s, int channel, int pred_order)
return 0; return 0;
} }
static int decode_subframe_fixed(FLACContext *s, int channel, int pred_order, static int decode_subframe_fixed(FLACContext *s, int32_t *decoded,
int bps) int pred_order, int bps)
{ {
const int blocksize = s->blocksize; const int blocksize = s->blocksize;
int32_t *decoded = s->decoded[channel];
int a, b, c, d, i; int a, b, c, d, i;
/* warm up samples */ /* warm up samples */
...@@ -260,7 +259,7 @@ static int decode_subframe_fixed(FLACContext *s, int channel, int pred_order, ...@@ -260,7 +259,7 @@ static int decode_subframe_fixed(FLACContext *s, int channel, int pred_order,
decoded[i] = get_sbits_long(&s->gb, bps); decoded[i] = get_sbits_long(&s->gb, bps);
} }
if (decode_residuals(s, channel, pred_order) < 0) if (decode_residuals(s, decoded, pred_order) < 0)
return -1; return -1;
if (pred_order > 0) if (pred_order > 0)
...@@ -299,13 +298,12 @@ static int decode_subframe_fixed(FLACContext *s, int channel, int pred_order, ...@@ -299,13 +298,12 @@ static int decode_subframe_fixed(FLACContext *s, int channel, int pred_order,
return 0; return 0;
} }
static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order, static int decode_subframe_lpc(FLACContext *s, int32_t *decoded, int pred_order,
int bps) int bps)
{ {
int i; int i;
int coeff_prec, qlevel; int coeff_prec, qlevel;
int coeffs[32]; int coeffs[32];
int32_t *decoded = s->decoded[channel];
/* warm up samples */ /* warm up samples */
for (i = 0; i < pred_order; i++) { for (i = 0; i < pred_order; i++) {
...@@ -328,7 +326,7 @@ static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order, ...@@ -328,7 +326,7 @@ static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order,
coeffs[pred_order - i - 1] = get_sbits(&s->gb, coeff_prec); coeffs[pred_order - i - 1] = get_sbits(&s->gb, coeff_prec);
} }
if (decode_residuals(s, channel, pred_order) < 0) if (decode_residuals(s, decoded, pred_order) < 0)
return -1; return -1;
s->dsp.lpc(decoded, coeffs, pred_order, qlevel, s->blocksize); s->dsp.lpc(decoded, coeffs, pred_order, qlevel, s->blocksize);
...@@ -338,6 +336,7 @@ static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order, ...@@ -338,6 +336,7 @@ static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order,
static inline int decode_subframe(FLACContext *s, int channel) static inline int decode_subframe(FLACContext *s, int channel)
{ {
int32_t *decoded = s->decoded[channel];
int type, wasted = 0; int type, wasted = 0;
int bps = s->bps; int bps = s->bps;
int i, tmp; int i, tmp;
...@@ -380,15 +379,15 @@ static inline int decode_subframe(FLACContext *s, int channel) ...@@ -380,15 +379,15 @@ static inline int decode_subframe(FLACContext *s, int channel)
if (type == 0) { if (type == 0) {
tmp = get_sbits_long(&s->gb, bps); tmp = get_sbits_long(&s->gb, bps);
for (i = 0; i < s->blocksize; i++) for (i = 0; i < s->blocksize; i++)
s->decoded[channel][i] = tmp; decoded[i] = tmp;
} else if (type == 1) { } else if (type == 1) {
for (i = 0; i < s->blocksize; i++) for (i = 0; i < s->blocksize; i++)
s->decoded[channel][i] = get_sbits_long(&s->gb, bps); decoded[i] = get_sbits_long(&s->gb, bps);
} else if ((type >= 8) && (type <= 12)) { } else if ((type >= 8) && (type <= 12)) {
if (decode_subframe_fixed(s, channel, type & ~0x8, bps) < 0) if (decode_subframe_fixed(s, decoded, type & ~0x8, bps) < 0)
return -1; return -1;
} else if (type >= 32) { } else if (type >= 32) {
if (decode_subframe_lpc(s, channel, (type & ~0x20)+1, bps) < 0) if (decode_subframe_lpc(s, decoded, (type & ~0x20)+1, bps) < 0)
return -1; return -1;
} else { } else {
av_log(s->avctx, AV_LOG_ERROR, "invalid coding type\n"); av_log(s->avctx, AV_LOG_ERROR, "invalid coding type\n");
...@@ -398,7 +397,7 @@ static inline int decode_subframe(FLACContext *s, int channel) ...@@ -398,7 +397,7 @@ static inline int decode_subframe(FLACContext *s, int channel)
if (wasted) { if (wasted) {
int i; int i;
for (i = 0; i < s->blocksize; i++) for (i = 0; i < s->blocksize; i++)
s->decoded[channel][i] <<= wasted; decoded[i] <<= wasted;
} }
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment