comparison mlpdec.c @ 9280:e3eff8a463ec libavcodec

mlpdec: Split filter_state_buffer into [fi]irbuf and fp to [fi]ir.
author ramiro
date Mon, 30 Mar 2009 03:05:38 +0000
parents b65ab36734f8
children 19a7de05b1ae
comparison
equal deleted inserted replaced
9279:b65ab36734f8 9280:e3eff8a463ec
650 650
651 static void filter_channel(MLPDecodeContext *m, unsigned int substr, 651 static void filter_channel(MLPDecodeContext *m, unsigned int substr,
652 unsigned int channel) 652 unsigned int channel)
653 { 653 {
654 SubStream *s = &m->substream[substr]; 654 SubStream *s = &m->substream[substr];
655 int32_t filter_state_buffer[NUM_FILTERS][MAX_BLOCKSIZE + MAX_FIR_ORDER]; 655 int32_t firbuf[MAX_BLOCKSIZE + MAX_FIR_ORDER];
656 FilterParams *fp[NUM_FILTERS] = { &m->channel_params[channel].filter_params[FIR], 656 int32_t iirbuf[MAX_BLOCKSIZE + MAX_IIR_ORDER];
657 &m->channel_params[channel].filter_params[IIR], }; 657 FilterParams *fir = &m->channel_params[channel].filter_params[FIR];
658 unsigned int filter_shift = fp[FIR]->shift; 658 FilterParams *iir = &m->channel_params[channel].filter_params[IIR];
659 unsigned int filter_shift = fir->shift;
659 int32_t mask = MSB_MASK(s->quant_step_size[channel]); 660 int32_t mask = MSB_MASK(s->quant_step_size[channel]);
660 int index = MAX_BLOCKSIZE; 661 int index = MAX_BLOCKSIZE;
661 int i; 662 int i;
662 663
663 memcpy(&filter_state_buffer[FIR][MAX_BLOCKSIZE], &fp[FIR]->state[0], 664 memcpy(&firbuf[MAX_BLOCKSIZE], &fir->state[0],
664 MAX_FIR_ORDER * sizeof(int32_t)); 665 MAX_FIR_ORDER * sizeof(int32_t));
665 memcpy(&filter_state_buffer[IIR][MAX_BLOCKSIZE], &fp[IIR]->state[0], 666 memcpy(&iirbuf[MAX_BLOCKSIZE], &iir->state[0],
666 MAX_IIR_ORDER * sizeof(int32_t)); 667 MAX_IIR_ORDER * sizeof(int32_t));
667 668
668 for (i = 0; i < s->blocksize; i++) { 669 for (i = 0; i < s->blocksize; i++) {
669 int32_t residual = m->sample_buffer[i + s->blockpos][channel]; 670 int32_t residual = m->sample_buffer[i + s->blockpos][channel];
670 unsigned int order; 671 unsigned int order;
671 int64_t accum = 0; 672 int64_t accum = 0;
672 int32_t result; 673 int32_t result;
673 674
674 /* TODO: Move this code to DSPContext? */ 675 /* TODO: Move this code to DSPContext? */
675 676
676 for (order = 0; order < fp[FIR]->order; order++) 677 for (order = 0; order < fir->order; order++)
677 accum += (int64_t)filter_state_buffer[FIR][index + order] * 678 accum += (int64_t)firbuf[index + order] *
678 fp[FIR]->coeff[order]; 679 fir->coeff[order];
679 for (order = 0; order < fp[IIR]->order; order++) 680 for (order = 0; order < iir->order; order++)
680 accum += (int64_t)filter_state_buffer[IIR][index + order] * 681 accum += (int64_t)iirbuf[index + order] *
681 fp[IIR]->coeff[order]; 682 iir->coeff[order];
682 683
683 accum = accum >> filter_shift; 684 accum = accum >> filter_shift;
684 result = (accum + residual) & mask; 685 result = (accum + residual) & mask;
685 686
686 --index; 687 --index;
687 688
688 filter_state_buffer[FIR][index] = result; 689 firbuf[index] = result;
689 filter_state_buffer[IIR][index] = result - accum; 690 iirbuf[index] = result - accum;
690 691
691 m->sample_buffer[i + s->blockpos][channel] = result; 692 m->sample_buffer[i + s->blockpos][channel] = result;
692 } 693 }
693 694
694 memcpy(&fp[FIR]->state[0], &filter_state_buffer[FIR][index], 695 memcpy(&fir->state[0], &firbuf[index],
695 MAX_FIR_ORDER * sizeof(int32_t)); 696 MAX_FIR_ORDER * sizeof(int32_t));
696 memcpy(&fp[IIR]->state[0], &filter_state_buffer[IIR][index], 697 memcpy(&iir->state[0], &iirbuf[index],
697 MAX_IIR_ORDER * sizeof(int32_t)); 698 MAX_IIR_ORDER * sizeof(int32_t));
698 } 699 }
699 700
700 /** Read a block of PCM residual data (or actual if no filtering active). */ 701 /** Read a block of PCM residual data (or actual if no filtering active). */
701 702