Mercurial > libavcodec.hg
comparison mlpdec.c @ 9567:d98ad4678fb0 libavcodec
mlpdec: Simplify filtering code by using only one counter variable.
author | ramiro |
---|---|
date | Sun, 26 Apr 2009 20:37:40 +0000 |
parents | b724134599eb |
children | 5e1d9508b62f |
comparison
equal
deleted
inserted
replaced
9566:9a3fddd31092 | 9567:d98ad4678fb0 |
---|---|
698 | 698 |
699 static void filter_channel(MLPDecodeContext *m, unsigned int substr, | 699 static void filter_channel(MLPDecodeContext *m, unsigned int substr, |
700 unsigned int channel) | 700 unsigned int channel) |
701 { | 701 { |
702 SubStream *s = &m->substream[substr]; | 702 SubStream *s = &m->substream[substr]; |
703 int32_t firbuf[MAX_BLOCKSIZE + MAX_FIR_ORDER]; | 703 int32_t fir_state_buffer[MAX_BLOCKSIZE + MAX_FIR_ORDER]; |
704 int32_t iirbuf[MAX_BLOCKSIZE + MAX_IIR_ORDER]; | 704 int32_t iir_state_buffer[MAX_BLOCKSIZE + MAX_IIR_ORDER]; |
705 int32_t *firbuf = fir_state_buffer + MAX_BLOCKSIZE; | |
706 int32_t *iirbuf = iir_state_buffer + MAX_BLOCKSIZE; | |
705 FilterParams *fir = &m->channel_params[channel].filter_params[FIR]; | 707 FilterParams *fir = &m->channel_params[channel].filter_params[FIR]; |
706 FilterParams *iir = &m->channel_params[channel].filter_params[IIR]; | 708 FilterParams *iir = &m->channel_params[channel].filter_params[IIR]; |
707 unsigned int filter_shift = fir->shift; | 709 unsigned int filter_shift = fir->shift; |
708 int32_t mask = MSB_MASK(s->quant_step_size[channel]); | 710 int32_t mask = MSB_MASK(s->quant_step_size[channel]); |
709 int index = MAX_BLOCKSIZE; | |
710 int i; | 711 int i; |
711 | 712 |
712 memcpy(&firbuf[index], fir->state, MAX_FIR_ORDER * sizeof(int32_t)); | 713 memcpy(firbuf, fir->state, MAX_FIR_ORDER * sizeof(int32_t)); |
713 memcpy(&iirbuf[index], iir->state, MAX_IIR_ORDER * sizeof(int32_t)); | 714 memcpy(iirbuf, iir->state, MAX_IIR_ORDER * sizeof(int32_t)); |
714 | 715 |
715 for (i = 0; i < s->blocksize; i++) { | 716 for (i = 0; i < s->blocksize; i++) { |
716 int32_t residual = m->sample_buffer[i + s->blockpos][channel]; | 717 int32_t residual = m->sample_buffer[i + s->blockpos][channel]; |
717 unsigned int order; | 718 unsigned int order; |
718 int64_t accum = 0; | 719 int64_t accum = 0; |
719 int32_t result; | 720 int32_t result; |
720 | 721 |
721 /* TODO: Move this code to DSPContext? */ | 722 /* TODO: Move this code to DSPContext? */ |
722 | 723 |
723 for (order = 0; order < fir->order; order++) | 724 for (order = 0; order < fir->order; order++) |
724 accum += (int64_t) firbuf[index + order] * fir->coeff[order]; | 725 accum += (int64_t) firbuf[order] * fir->coeff[order]; |
725 for (order = 0; order < iir->order; order++) | 726 for (order = 0; order < iir->order; order++) |
726 accum += (int64_t) iirbuf[index + order] * iir->coeff[order]; | 727 accum += (int64_t) iirbuf[order] * iir->coeff[order]; |
727 | 728 |
728 accum = accum >> filter_shift; | 729 accum = accum >> filter_shift; |
729 result = (accum + residual) & mask; | 730 result = (accum + residual) & mask; |
730 | 731 |
731 --index; | 732 *--firbuf = result; |
732 | 733 *--iirbuf = result - accum; |
733 firbuf[index] = result; | |
734 iirbuf[index] = result - accum; | |
735 | 734 |
736 m->sample_buffer[i + s->blockpos][channel] = result; | 735 m->sample_buffer[i + s->blockpos][channel] = result; |
737 } | 736 } |
738 | 737 |
739 memcpy(fir->state, &firbuf[index], MAX_FIR_ORDER * sizeof(int32_t)); | 738 memcpy(fir->state, firbuf, MAX_FIR_ORDER * sizeof(int32_t)); |
740 memcpy(iir->state, &iirbuf[index], MAX_IIR_ORDER * sizeof(int32_t)); | 739 memcpy(iir->state, iirbuf, MAX_IIR_ORDER * sizeof(int32_t)); |
741 } | 740 } |
742 | 741 |
743 /** Read a block of PCM residual data (or actual if no filtering active). */ | 742 /** Read a block of PCM residual data (or actual if no filtering active). */ |
744 | 743 |
745 static int read_block_data(MLPDecodeContext *m, GetBitContext *gbp, | 744 static int read_block_data(MLPDecodeContext *m, GetBitContext *gbp, |