aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2011-10-09 13:16:14 -0400
committerJustin Ruggles <justin.ruggles@gmail.com>2011-10-26 11:50:16 -0400
commite739d35156c85b3ccae4fdacd368933f0408227a (patch)
tree9c4ccaac5ba988b7ae405c14b76af4ab7f89d6b7
parentd251c85dcea29b04cb577837be441d81c9e90876 (diff)
downloadffmpeg-e739d35156c85b3ccae4fdacd368933f0408227a.tar.gz
alacdec: split stereo decorrelation into a separate function.
It is identical for 16-bit and 24-bit, so there is no need to have duplicate code.
-rw-r--r--libavcodec/alac.c77
1 files changed, 28 insertions, 49 deletions
diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index ce1244fc18..96b25e0086 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -298,33 +298,33 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer,
}
}
-static void reconstruct_stereo_16(int32_t *buffer[MAX_CHANNELS],
- int16_t *buffer_out,
- int numchannels, int numsamples,
- uint8_t interlacing_shift,
- uint8_t interlacing_leftweight)
+static void decorrelate_stereo(int32_t *buffer[MAX_CHANNELS],
+ int numchannels, int numsamples,
+ uint8_t interlacing_shift,
+ uint8_t interlacing_leftweight)
{
int i;
- /* weighted interlacing */
- if (interlacing_leftweight) {
- for (i = 0; i < numsamples; i++) {
- int32_t a, b;
-
- a = buffer[0][i];
- b = buffer[1][i];
+ for (i = 0; i < numsamples; i++) {
+ int32_t a, b;
- a -= (b * interlacing_leftweight) >> interlacing_shift;
- b += a;
+ a = buffer[0][i];
+ b = buffer[1][i];
- buffer_out[i*numchannels] = b;
- buffer_out[i*numchannels + 1] = a;
- }
+ a -= (b * interlacing_leftweight) >> interlacing_shift;
+ b += a;
- return;
+ buffer[0][i] = b;
+ buffer[1][i] = a;
}
+}
+
+static void reconstruct_stereo_16(int32_t *buffer[MAX_CHANNELS],
+ int16_t *buffer_out,
+ int numchannels, int numsamples)
+{
+ int i;
- /* otherwise basic interlacing took place */
for (i = 0; i < numsamples; i++) {
int16_t left, right;
@@ -340,32 +340,10 @@ static void decorrelate_stereo_24(int32_t *buffer[MAX_CHANNELS],
int32_t *buffer_out,
int32_t *extra_bits_buffer[MAX_CHANNELS],
int extra_bits,
- int numchannels, int numsamples,
- uint8_t interlacing_shift,
- uint8_t interlacing_leftweight)
+ int numchannels, int numsamples)
{
int i;
- /* weighted interlacing */
- if (interlacing_leftweight) {
- for (i = 0; i < numsamples; i++) {
- int32_t a, b;
-
- a = buffer[0][i];
- b = buffer[1][i];
-
- a -= (b * interlacing_leftweight) >> interlacing_shift;
- b += a;
-
- if (extra_bits) {
- b = (b << extra_bits) | extra_bits_buffer[0][i];
- a = (a << extra_bits) | extra_bits_buffer[1][i];
- }
-
- buffer_out[i * numchannels] = b << 8;
- buffer_out[i * numchannels + 1] = a << 8;
- }
- } else {
for (i = 0; i < numsamples; i++) {
int32_t left, right;
@@ -380,7 +358,6 @@ static void decorrelate_stereo_24(int32_t *buffer[MAX_CHANNELS],
buffer_out[i * numchannels] = left << 8;
buffer_out[i * numchannels + 1] = right << 8;
}
- }
}
static int alac_decode_frame(AVCodecContext *avctx,
@@ -539,15 +516,19 @@ static int alac_decode_frame(AVCodecContext *avctx,
if (get_bits(&alac->gb, 3) != 7)
av_log(avctx, AV_LOG_ERROR, "Error : Wrong End Of Frame\n");
+ if (channels == 2 && interlacing_leftweight) {
+ decorrelate_stereo(alac->outputsamples_buffer, alac->numchannels,
+ outputsamples, interlacing_shift,
+ interlacing_leftweight);
+ }
+
switch(alac->setinfo_sample_size) {
case 16:
if (channels == 2) {
reconstruct_stereo_16(alac->outputsamples_buffer,
(int16_t*)outbuffer,
alac->numchannels,
- outputsamples,
- interlacing_shift,
- interlacing_leftweight);
+ outputsamples);
} else {
int i;
for (i = 0; i < outputsamples; i++) {
@@ -562,9 +543,7 @@ static int alac_decode_frame(AVCodecContext *avctx,
alac->extra_bits_buffer,
alac->extra_bits,
alac->numchannels,
- outputsamples,
- interlacing_shift,
- interlacing_leftweight);
+ outputsamples);
} else {
int i;
for (i = 0; i < outputsamples; i++)