libavcodec/mpc.c
185c7b6b
 /*
24e649af
  * Musepack decoder core
185c7b6b
  * Copyright (c) 2006 Konstantin Shishkov
  *
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
  * FFmpeg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /**
ba87f080
  * @file
  * Musepack decoder core
185c7b6b
  * MPEG Audio Layer 1/2 -like codec with frames of 1152 samples
  * divided into 32 subbands.
  */
 
6fee1b90
 #include "libavutil/attributes.h"
185c7b6b
 #include "avcodec.h"
9106a698
 #include "get_bits.h"
c4f5c2d6
 #include "mpegaudiodsp.h"
185c7b6b
 #include "mpegaudio.h"
 
24e649af
 #include "mpc.h"
185c7b6b
 #include "mpcdata.h"
 
6fee1b90
 av_cold void ff_mpc_init(void)
185c7b6b
 {
4bac1bbc
     ff_mpa_synth_init_fixed(ff_mpa_synth_window_fixed);
185c7b6b
 }
 
 /**
  * Process decoded Musepack data and produce PCM
  */
1a345903
 static void mpc_synth(MPCContext *c, int16_t **out, int channels)
185c7b6b
 {
     int dither_state = 0;
     int i, ch;
 
7d3829a8
     for(ch = 0;  ch < channels; ch++){
185c7b6b
         for(i = 0; i < SAMPLES_PER_BAND; i++) {
c4f5c2d6
             ff_mpa_synth_filter_fixed(&c->mpadsp,
                                 c->synth_buf[ch], &(c->synth_buf_offset[ch]),
4bac1bbc
                                 ff_mpa_synth_window_fixed, &dither_state,
1a345903
                                 out[ch] + 32 * i, 1,
185c7b6b
                                 c->sb_samples[ch][i]);
         }
     }
 }
 
1a345903
 void ff_mpc_dequantize_and_synth(MPCContext * c, int maxband, int16_t **out,
                                  int channels)
185c7b6b
 {
24e649af
     int i, j, ch;
     Band *bands = c->bands;
185c7b6b
     int off;
     float mul;
 
     /* dequantize */
     memset(c->sb_samples, 0, sizeof(c->sb_samples));
     off = 0;
24e649af
     for(i = 0; i <= maxband; i++, off += SAMPLES_PER_BAND){
185c7b6b
         for(ch = 0; ch < 2; ch++){
             if(bands[i].res[ch]){
                 j = 0;
b2a7c017
                 mul = (mpc_CC+1)[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][0] & 0xFF];
185c7b6b
                 for(; j < 12; j++)
24e649af
                     c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off];
b2a7c017
                 mul = (mpc_CC+1)[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][1] & 0xFF];
185c7b6b
                 for(; j < 24; j++)
24e649af
                     c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off];
b2a7c017
                 mul = (mpc_CC+1)[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][2] & 0xFF];
185c7b6b
                 for(; j < 36; j++)
24e649af
                     c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off];
185c7b6b
             }
         }
         if(bands[i].msf){
             int t1, t2;
             for(j = 0; j < SAMPLES_PER_BAND; j++){
                 t1 = c->sb_samples[0][j][i];
                 t2 = c->sb_samples[1][j][i];
                 c->sb_samples[0][j][i] = t1 + t2;
                 c->sb_samples[1][j][i] = t1 - t2;
             }
         }
     }
 
1a345903
     mpc_synth(c, out, channels);
aac88b53
 }