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.
This commit is contained in:
Justin Ruggles 2011-10-09 13:16:14 -04:00
parent d251c85dce
commit e739d35156
1 changed files with 28 additions and 49 deletions

View File

@ -298,16 +298,13 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer,
} }
} }
static void reconstruct_stereo_16(int32_t *buffer[MAX_CHANNELS], static void decorrelate_stereo(int32_t *buffer[MAX_CHANNELS],
int16_t *buffer_out,
int numchannels, int numsamples, int numchannels, int numsamples,
uint8_t interlacing_shift, uint8_t interlacing_shift,
uint8_t interlacing_leftweight) uint8_t interlacing_leftweight)
{ {
int i; int i;
/* weighted interlacing */
if (interlacing_leftweight) {
for (i = 0; i < numsamples; i++) { for (i = 0; i < numsamples; i++) {
int32_t a, b; int32_t a, b;
@ -317,14 +314,17 @@ static void reconstruct_stereo_16(int32_t *buffer[MAX_CHANNELS],
a -= (b * interlacing_leftweight) >> interlacing_shift; a -= (b * interlacing_leftweight) >> interlacing_shift;
b += a; b += a;
buffer_out[i*numchannels] = b; buffer[0][i] = b;
buffer_out[i*numchannels + 1] = a; buffer[1][i] = a;
}
} }
return; 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++) { for (i = 0; i < numsamples; i++) {
int16_t left, right; int16_t left, right;
@ -340,32 +340,10 @@ static void decorrelate_stereo_24(int32_t *buffer[MAX_CHANNELS],
int32_t *buffer_out, int32_t *buffer_out,
int32_t *extra_bits_buffer[MAX_CHANNELS], int32_t *extra_bits_buffer[MAX_CHANNELS],
int extra_bits, int extra_bits,
int numchannels, int numsamples, int numchannels, int numsamples)
uint8_t interlacing_shift,
uint8_t interlacing_leftweight)
{ {
int i; 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++) { for (i = 0; i < numsamples; i++) {
int32_t left, right; int32_t left, right;
@ -381,7 +359,6 @@ static void decorrelate_stereo_24(int32_t *buffer[MAX_CHANNELS],
buffer_out[i * numchannels + 1] = right << 8; buffer_out[i * numchannels + 1] = right << 8;
} }
} }
}
static int alac_decode_frame(AVCodecContext *avctx, static int alac_decode_frame(AVCodecContext *avctx,
void *outbuffer, int *outputsize, void *outbuffer, int *outputsize,
@ -539,15 +516,19 @@ static int alac_decode_frame(AVCodecContext *avctx,
if (get_bits(&alac->gb, 3) != 7) if (get_bits(&alac->gb, 3) != 7)
av_log(avctx, AV_LOG_ERROR, "Error : Wrong End Of Frame\n"); 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) { switch(alac->setinfo_sample_size) {
case 16: case 16:
if (channels == 2) { if (channels == 2) {
reconstruct_stereo_16(alac->outputsamples_buffer, reconstruct_stereo_16(alac->outputsamples_buffer,
(int16_t*)outbuffer, (int16_t*)outbuffer,
alac->numchannels, alac->numchannels,
outputsamples, outputsamples);
interlacing_shift,
interlacing_leftweight);
} else { } else {
int i; int i;
for (i = 0; i < outputsamples; 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_buffer,
alac->extra_bits, alac->extra_bits,
alac->numchannels, alac->numchannels,
outputsamples, outputsamples);
interlacing_shift,
interlacing_leftweight);
} else { } else {
int i; int i;
for (i = 0; i < outputsamples; i++) for (i = 0; i < outputsamples; i++)