comparison mlpdec.c @ 9585:5e1d9508b62f libavcodec

mlpdec: Move MLP's filter_channel() to dsputils.
author ramiro
date Thu, 30 Apr 2009 12:30:05 +0000
parents d98ad4678fb0
children de33a215fd84
comparison
equal deleted inserted replaced
9584:e30999f7a631 9585:5e1d9508b62f
25 */ 25 */
26 26
27 #include <stdint.h> 27 #include <stdint.h>
28 28
29 #include "avcodec.h" 29 #include "avcodec.h"
30 #include "dsputil.h"
30 #include "libavutil/intreadwrite.h" 31 #include "libavutil/intreadwrite.h"
31 #include "get_bits.h" 32 #include "get_bits.h"
32 #include "libavutil/crc.h" 33 #include "libavutil/crc.h"
33 #include "parser.h" 34 #include "parser.h"
34 #include "mlp_parser.h" 35 #include "mlp_parser.h"
142 int filter_changed[MAX_CHANNELS][NUM_FILTERS]; 143 int filter_changed[MAX_CHANNELS][NUM_FILTERS];
143 144
144 int8_t noise_buffer[MAX_BLOCKSIZE_POW2]; 145 int8_t noise_buffer[MAX_BLOCKSIZE_POW2];
145 int8_t bypassed_lsbs[MAX_BLOCKSIZE][MAX_CHANNELS]; 146 int8_t bypassed_lsbs[MAX_BLOCKSIZE][MAX_CHANNELS];
146 int32_t sample_buffer[MAX_BLOCKSIZE][MAX_CHANNELS]; 147 int32_t sample_buffer[MAX_BLOCKSIZE][MAX_CHANNELS];
148
149 DSPContext dsp;
147 } MLPDecodeContext; 150 } MLPDecodeContext;
148 151
149 static VLC huff_vlc[3]; 152 static VLC huff_vlc[3];
150 153
151 /** Initialize static data, constant between all invocations of the codec. */ 154 /** Initialize static data, constant between all invocations of the codec. */
229 232
230 init_static(); 233 init_static();
231 m->avctx = avctx; 234 m->avctx = avctx;
232 for (substr = 0; substr < MAX_SUBSTREAMS; substr++) 235 for (substr = 0; substr < MAX_SUBSTREAMS; substr++)
233 m->substream[substr].lossless_check_data = 0xffffffff; 236 m->substream[substr].lossless_check_data = 0xffffffff;
237 dsputil_init(&m->dsp, avctx);
234 238
235 return 0; 239 return 0;
236 } 240 }
237 241
238 /** Read a major sync info header - contains high level information about 242 /** Read a major sync info header - contains high level information about
706 int32_t *iirbuf = iir_state_buffer + MAX_BLOCKSIZE; 710 int32_t *iirbuf = iir_state_buffer + MAX_BLOCKSIZE;
707 FilterParams *fir = &m->channel_params[channel].filter_params[FIR]; 711 FilterParams *fir = &m->channel_params[channel].filter_params[FIR];
708 FilterParams *iir = &m->channel_params[channel].filter_params[IIR]; 712 FilterParams *iir = &m->channel_params[channel].filter_params[IIR];
709 unsigned int filter_shift = fir->shift; 713 unsigned int filter_shift = fir->shift;
710 int32_t mask = MSB_MASK(s->quant_step_size[channel]); 714 int32_t mask = MSB_MASK(s->quant_step_size[channel]);
711 int i;
712 715
713 memcpy(firbuf, fir->state, MAX_FIR_ORDER * sizeof(int32_t)); 716 memcpy(firbuf, fir->state, MAX_FIR_ORDER * sizeof(int32_t));
714 memcpy(iirbuf, iir->state, MAX_IIR_ORDER * sizeof(int32_t)); 717 memcpy(iirbuf, iir->state, MAX_IIR_ORDER * sizeof(int32_t));
715 718
716 for (i = 0; i < s->blocksize; i++) { 719 m->dsp.mlp_filter_channel(firbuf, fir->coeff, fir->order,
717 int32_t residual = m->sample_buffer[i + s->blockpos][channel]; 720 iirbuf, iir->coeff, iir->order,
718 unsigned int order; 721 filter_shift, mask, s->blocksize,
719 int64_t accum = 0; 722 &m->sample_buffer[s->blockpos][channel]);
720 int32_t result; 723
721 724 memcpy(fir->state, firbuf - s->blocksize, MAX_FIR_ORDER * sizeof(int32_t));
722 /* TODO: Move this code to DSPContext? */ 725 memcpy(iir->state, iirbuf - s->blocksize, MAX_IIR_ORDER * sizeof(int32_t));
723
724 for (order = 0; order < fir->order; order++)
725 accum += (int64_t) firbuf[order] * fir->coeff[order];
726 for (order = 0; order < iir->order; order++)
727 accum += (int64_t) iirbuf[order] * iir->coeff[order];
728
729 accum = accum >> filter_shift;
730 result = (accum + residual) & mask;
731
732 *--firbuf = result;
733 *--iirbuf = result - accum;
734
735 m->sample_buffer[i + s->blockpos][channel] = result;
736 }
737
738 memcpy(fir->state, firbuf, MAX_FIR_ORDER * sizeof(int32_t));
739 memcpy(iir->state, iirbuf, MAX_IIR_ORDER * sizeof(int32_t));
740 } 726 }
741 727
742 /** Read a block of PCM residual data (or actual if no filtering active). */ 728 /** Read a block of PCM residual data (or actual if no filtering active). */
743 729
744 static int read_block_data(MLPDecodeContext *m, GetBitContext *gbp, 730 static int read_block_data(MLPDecodeContext *m, GetBitContext *gbp,