2006-12-24 05:51:43 +01:00
|
|
|
/*
|
2007-11-02 07:40:42 +01:00
|
|
|
* Musepack decoder core
|
2006-12-24 05:51:43 +01:00
|
|
|
* Copyright (c) 2006 Konstantin Shishkov
|
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* This file is part of Libav.
|
2006-12-24 05:51:43 +01:00
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2006-12-24 05:51:43 +01:00
|
|
|
* 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.
|
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2006-12-24 05:51:43 +01:00
|
|
|
* 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
|
2011-03-18 18:35:10 +01:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2006-12-24 05:51:43 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 16:45:34 +02:00
|
|
|
* @file
|
|
|
|
* Musepack decoder core
|
2006-12-24 05:51:43 +01:00
|
|
|
* MPEG Audio Layer 1/2 -like codec with frames of 1152 samples
|
|
|
|
* divided into 32 subbands.
|
|
|
|
*/
|
|
|
|
|
2013-02-01 10:31:59 +01:00
|
|
|
#include "libavutil/attributes.h"
|
2006-12-24 05:51:43 +01:00
|
|
|
#include "avcodec.h"
|
2009-04-13 18:20:26 +02:00
|
|
|
#include "get_bits.h"
|
2011-05-16 17:52:01 +02:00
|
|
|
#include "mpegaudiodsp.h"
|
2006-12-24 05:51:43 +01:00
|
|
|
#include "mpegaudio.h"
|
|
|
|
|
2007-11-02 07:40:42 +01:00
|
|
|
#include "mpc.h"
|
2006-12-24 05:51:43 +01:00
|
|
|
#include "mpcdata.h"
|
|
|
|
|
2013-02-01 10:31:59 +01:00
|
|
|
av_cold void ff_mpc_init(void)
|
2006-12-24 05:51:43 +01:00
|
|
|
{
|
2011-05-17 14:07:08 +02:00
|
|
|
ff_mpa_synth_init_fixed(ff_mpa_synth_window_fixed);
|
2006-12-24 05:51:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process decoded Musepack data and produce PCM
|
|
|
|
*/
|
2012-08-28 15:11:45 +02:00
|
|
|
static void mpc_synth(MPCContext *c, int16_t **out, int channels)
|
2006-12-24 05:51:43 +01:00
|
|
|
{
|
|
|
|
int dither_state = 0;
|
|
|
|
int i, ch;
|
|
|
|
|
2010-11-21 21:42:06 +01:00
|
|
|
for(ch = 0; ch < channels; ch++){
|
2006-12-24 05:51:43 +01:00
|
|
|
for(i = 0; i < SAMPLES_PER_BAND; i++) {
|
2011-05-16 17:52:01 +02:00
|
|
|
ff_mpa_synth_filter_fixed(&c->mpadsp,
|
|
|
|
c->synth_buf[ch], &(c->synth_buf_offset[ch]),
|
2011-05-17 14:07:08 +02:00
|
|
|
ff_mpa_synth_window_fixed, &dither_state,
|
2012-08-28 15:11:45 +02:00
|
|
|
out[ch] + 32 * i, 1,
|
2006-12-24 05:51:43 +01:00
|
|
|
c->sb_samples[ch][i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-28 15:11:45 +02:00
|
|
|
void ff_mpc_dequantize_and_synth(MPCContext * c, int maxband, int16_t **out,
|
|
|
|
int channels)
|
2006-12-24 05:51:43 +01:00
|
|
|
{
|
2007-11-02 07:40:42 +01:00
|
|
|
int i, j, ch;
|
|
|
|
Band *bands = c->bands;
|
2006-12-24 05:51:43 +01:00
|
|
|
int off;
|
|
|
|
float mul;
|
|
|
|
|
|
|
|
/* dequantize */
|
|
|
|
memset(c->sb_samples, 0, sizeof(c->sb_samples));
|
|
|
|
off = 0;
|
2007-11-02 07:40:42 +01:00
|
|
|
for(i = 0; i <= maxband; i++, off += SAMPLES_PER_BAND){
|
2006-12-24 05:51:43 +01:00
|
|
|
for(ch = 0; ch < 2; ch++){
|
|
|
|
if(bands[i].res[ch]){
|
|
|
|
j = 0;
|
2012-03-10 23:28:08 +01:00
|
|
|
mul = mpc_CC[bands[i].res[ch] + 1] * mpc_SCF[bands[i].scf_idx[ch][0]+6];
|
2006-12-24 05:51:43 +01:00
|
|
|
for(; j < 12; j++)
|
2007-11-02 07:40:42 +01:00
|
|
|
c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off];
|
2012-03-10 23:28:08 +01:00
|
|
|
mul = mpc_CC[bands[i].res[ch] + 1] * mpc_SCF[bands[i].scf_idx[ch][1]+6];
|
2006-12-24 05:51:43 +01:00
|
|
|
for(; j < 24; j++)
|
2007-11-02 07:40:42 +01:00
|
|
|
c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off];
|
2012-03-10 23:28:08 +01:00
|
|
|
mul = mpc_CC[bands[i].res[ch] + 1] * mpc_SCF[bands[i].scf_idx[ch][2]+6];
|
2006-12-24 05:51:43 +01:00
|
|
|
for(; j < 36; j++)
|
2007-11-02 07:40:42 +01:00
|
|
|
c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off];
|
2006-12-24 05:51:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-28 15:11:45 +02:00
|
|
|
mpc_synth(c, out, channels);
|
2007-01-01 06:32:27 +01:00
|
|
|
}
|