Libav
|
00001 /* 00002 * Musepack decoder core 00003 * Copyright (c) 2006 Konstantin Shishkov 00004 * 00005 * This file is part of FFmpeg. 00006 * 00007 * FFmpeg is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * FFmpeg is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with FFmpeg; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00029 #include "avcodec.h" 00030 #include "get_bits.h" 00031 #include "dsputil.h" 00032 #include "mpegaudio.h" 00033 00034 #include "mpc.h" 00035 #include "mpcdata.h" 00036 00037 void ff_mpc_init(void) 00038 { 00039 ff_mpa_synth_init(ff_mpa_synth_window); 00040 } 00041 00045 static void mpc_synth(MPCContext *c, int16_t *out) 00046 { 00047 int dither_state = 0; 00048 int i, ch; 00049 OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr; 00050 00051 for(ch = 0; ch < 2; ch++){ 00052 samples_ptr = samples + ch; 00053 for(i = 0; i < SAMPLES_PER_BAND; i++) { 00054 ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]), 00055 ff_mpa_synth_window, &dither_state, 00056 samples_ptr, 2, 00057 c->sb_samples[ch][i]); 00058 samples_ptr += 64; 00059 } 00060 } 00061 for(i = 0; i < MPC_FRAME_SIZE*2; i++) 00062 *out++=samples[i]; 00063 } 00064 00065 void ff_mpc_dequantize_and_synth(MPCContext * c, int maxband, void *data) 00066 { 00067 int i, j, ch; 00068 Band *bands = c->bands; 00069 int off; 00070 float mul; 00071 00072 /* dequantize */ 00073 memset(c->sb_samples, 0, sizeof(c->sb_samples)); 00074 off = 0; 00075 for(i = 0; i <= maxband; i++, off += SAMPLES_PER_BAND){ 00076 for(ch = 0; ch < 2; ch++){ 00077 if(bands[i].res[ch]){ 00078 j = 0; 00079 mul = mpc_CC[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][0]]; 00080 for(; j < 12; j++) 00081 c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off]; 00082 mul = mpc_CC[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][1]]; 00083 for(; j < 24; j++) 00084 c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off]; 00085 mul = mpc_CC[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][2]]; 00086 for(; j < 36; j++) 00087 c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off]; 00088 } 00089 } 00090 if(bands[i].msf){ 00091 int t1, t2; 00092 for(j = 0; j < SAMPLES_PER_BAND; j++){ 00093 t1 = c->sb_samples[0][j][i]; 00094 t2 = c->sb_samples[1][j][i]; 00095 c->sb_samples[0][j][i] = t1 + t2; 00096 c->sb_samples[1][j][i] = t1 - t2; 00097 } 00098 } 00099 } 00100 00101 mpc_synth(c, data); 00102 }