Revision d6aa052d libavcodec/mlpdec.c

View differences:

libavcodec/mlpdec.c
139 139

  
140 140
} SubStream;
141 141

  
142
#define FIR 0
143
#define IIR 1
144

  
145
/** filter data */
146
typedef struct {
147
    //! number of taps in filter
148
    uint8_t     order;
149
    //! Right shift to apply to output of filter.
150
    uint8_t     shift;
151

  
152
    int32_t     coeff[MAX_FILTER_ORDER];
153
    int32_t     state[MAX_FILTER_ORDER];
154
} FilterParams;
155

  
142 156
typedef struct MLPDecodeContext {
143 157
    AVCodecContext *avctx;
144 158

  
......
158 172

  
159 173
    SubStream   substream[MAX_SUBSTREAMS];
160 174

  
161
    //@{
162
    /** filter data */
163
#define FIR 0
164
#define IIR 1
165
    //! number of taps in filter
166
    uint8_t     filter_order[MAX_CHANNELS][NUM_FILTERS];
167
    //! Right shift to apply to output of filter.
168
    uint8_t     filter_shift[MAX_CHANNELS][NUM_FILTERS];
169

  
170
    int32_t     filter_coeff[MAX_CHANNELS][NUM_FILTERS][MAX_FILTER_ORDER];
171
    int32_t     filter_state[MAX_CHANNELS][NUM_FILTERS][MAX_FILTER_ORDER];
172
    //@}
175
    FilterParams filter_params[MAX_CHANNELS][NUM_FILTERS];
173 176

  
174 177
    //@{
175 178
    /** sample data coding information */
......
520 523
    memset(s->quant_step_size, 0, sizeof(s->quant_step_size));
521 524

  
522 525
    for (ch = s->min_channel; ch <= s->max_channel; ch++) {
523
        m->filter_order[ch][FIR] = 0;
524
        m->filter_order[ch][IIR] = 0;
525
        m->filter_shift[ch][FIR] = 0;
526
        m->filter_shift[ch][IIR] = 0;
526
        m->filter_params[ch][FIR].order = 0;
527
        m->filter_params[ch][IIR].order = 0;
528
        m->filter_params[ch][FIR].shift = 0;
529
        m->filter_params[ch][IIR].shift = 0;
527 530

  
528 531
        /* Default audio coding is 24-bit raw PCM. */
529 532
        m->huff_offset     [ch] = 0;
......
544 547
static int read_filter_params(MLPDecodeContext *m, GetBitContext *gbp,
545 548
                              unsigned int channel, unsigned int filter)
546 549
{
550
    FilterParams *fp = &m->filter_params[channel][filter];
547 551
    const char fchar = filter ? 'I' : 'F';
548 552
    int i, order;
549 553

  
......
557 561
               fchar, order, MAX_FILTER_ORDER);
558 562
        return -1;
559 563
    }
560
    m->filter_order[channel][filter] = order;
564
    fp->order = order;
561 565

  
562 566
    if (order > 0) {
563 567
        int coeff_bits, coeff_shift;
564 568

  
565
        m->filter_shift[channel][filter] = get_bits(gbp, 4);
569
        fp->shift = get_bits(gbp, 4);
566 570

  
567 571
        coeff_bits  = get_bits(gbp, 5);
568 572
        coeff_shift = get_bits(gbp, 3);
......
580 584
        }
581 585

  
582 586
        for (i = 0; i < order; i++)
583
            m->filter_coeff[channel][filter][i] =
587
            fp->coeff[i] =
584 588
                    get_sbits(gbp, coeff_bits) << coeff_shift;
585 589

  
586 590
        if (get_bits1(gbp)) {
......
598 602
            /* TODO: Check validity of state data. */
599 603

  
600 604
            for (i = 0; i < order; i++)
601
                m->filter_state[channel][filter][i] =
605
                fp->state[i] =
602 606
                    get_sbits(gbp, state_bits) << state_shift;
603 607
        }
604 608
    }
......
689 693

  
690 694
    for (ch = s->min_channel; ch <= s->max_channel; ch++)
691 695
        if (get_bits1(gbp)) {
696
            FilterParams *fir = &m->filter_params[ch][FIR];
697
            FilterParams *iir = &m->filter_params[ch][IIR];
698

  
692 699
            if (s->param_presence_flags & PARAM_FIR)
693 700
                if (get_bits1(gbp))
694 701
                    if (read_filter_params(m, gbp, ch, FIR) < 0)
......
699 706
                    if (read_filter_params(m, gbp, ch, IIR) < 0)
700 707
                        return -1;
701 708

  
702
            if (m->filter_order[ch][FIR] && m->filter_order[ch][IIR] &&
703
                m->filter_shift[ch][FIR] != m->filter_shift[ch][IIR]) {
709
            if (fir->order && iir->order &&
710
                fir->shift != iir->shift) {
704 711
                av_log(m->avctx, AV_LOG_ERROR,
705 712
                       "FIR and IIR filters must use the same precision.\n");
706 713
                return -1;
......
710 717
             * FIR filter is considered. If only the IIR filter is employed,
711 718
             * the FIR filter precision is set to that of the IIR filter, so
712 719
             * that the filtering code can use it. */
713
            if (!m->filter_order[ch][FIR] && m->filter_order[ch][IIR])
714
                m->filter_shift[ch][FIR] = m->filter_shift[ch][IIR];
720
            if (!fir->order && iir->order)
721
                fir->shift = iir->shift;
715 722

  
716 723
            if (s->param_presence_flags & PARAM_HUFFOFFSET)
717 724
                if (get_bits1(gbp))
......
738 745
{
739 746
    SubStream *s = &m->substream[substr];
740 747
    int32_t filter_state_buffer[NUM_FILTERS][MAX_BLOCKSIZE + MAX_FILTER_ORDER];
741
    unsigned int filter_shift = m->filter_shift[channel][FIR];
748
    FilterParams *fp[NUM_FILTERS] = { &m->filter_params[channel][FIR],
749
                                      &m->filter_params[channel][IIR], };
750
    unsigned int filter_shift = fp[FIR]->shift;
742 751
    int32_t mask = MSB_MASK(s->quant_step_size[channel]);
743 752
    int index = MAX_BLOCKSIZE;
744 753
    int j, i;
745 754

  
746 755
    for (j = 0; j < NUM_FILTERS; j++) {
747 756
        memcpy(&   filter_state_buffer  [j][MAX_BLOCKSIZE],
748
               &m->filter_state[channel][j][0],
757
               &fp[j]->state[0],
749 758
               MAX_FILTER_ORDER * sizeof(int32_t));
750 759
    }
751 760

  
......
758 767
        /* TODO: Move this code to DSPContext? */
759 768

  
760 769
        for (j = 0; j < NUM_FILTERS; j++)
761
            for (order = 0; order < m->filter_order[channel][j]; order++)
770
            for (order = 0; order < fp[j]->order; order++)
762 771
                accum += (int64_t)filter_state_buffer[j][index + order] *
763
                        m->filter_coeff[channel][j][order];
772
                        fp[j]->coeff[order];
764 773

  
765 774
        accum  = accum >> filter_shift;
766 775
        result = (accum + residual) & mask;
......
774 783
    }
775 784

  
776 785
    for (j = 0; j < NUM_FILTERS; j++) {
777
        memcpy(&m->filter_state[channel][j][0],
786
        memcpy(&fp[j]->state[0],
778 787
               &   filter_state_buffer  [j][index],
779 788
               MAX_FILTER_ORDER * sizeof(int32_t));
780 789
    }

Also available in: Unified diff