2006-12-24 06:51:43 +02:00
|
|
|
/*
|
2007-11-02 08:40:42 +02:00
|
|
|
* Musepack decoder core
|
2006-12-24 06:51:43 +02:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 17:45:34 +03:00
|
|
|
* @file
|
|
|
|
* Musepack decoder core
|
2006-12-24 06:51:43 +02:00
|
|
|
* MPEG Audio Layer 1/2 -like codec with frames of 1152 samples
|
|
|
|
* divided into 32 subbands.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avcodec.h"
|
2009-04-13 19:20:26 +03:00
|
|
|
#include "get_bits.h"
|
2006-12-24 06:51:43 +02:00
|
|
|
#include "dsputil.h"
|
|
|
|
#include "mpegaudio.h"
|
|
|
|
|
2007-11-02 08:40:42 +02:00
|
|
|
#include "mpc.h"
|
2006-12-24 06:51:43 +02:00
|
|
|
#include "mpcdata.h"
|
|
|
|
|
2009-01-30 20:38:25 +02:00
|
|
|
void ff_mpc_init(void)
|
2006-12-24 06:51:43 +02:00
|
|
|
{
|
2009-10-19 20:21:02 +03:00
|
|
|
ff_mpa_synth_init(ff_mpa_synth_window);
|
2006-12-24 06:51:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process decoded Musepack data and produce PCM
|
|
|
|
*/
|
2010-11-21 22:42:06 +02:00
|
|
|
static void mpc_synth(MPCContext *c, int16_t *out, int channels)
|
2006-12-24 06:51:43 +02:00
|
|
|
{
|
|
|
|
int dither_state = 0;
|
|
|
|
int i, ch;
|
|
|
|
OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;
|
|
|
|
|
2010-11-21 22:42:06 +02:00
|
|
|
for(ch = 0; ch < channels; ch++){
|
2006-12-24 06:51:43 +02:00
|
|
|
samples_ptr = samples + ch;
|
|
|
|
for(i = 0; i < SAMPLES_PER_BAND; i++) {
|
|
|
|
ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),
|
2009-10-19 20:21:02 +03:00
|
|
|
ff_mpa_synth_window, &dither_state,
|
2010-11-21 22:42:06 +02:00
|
|
|
samples_ptr, channels,
|
2006-12-24 06:51:43 +02:00
|
|
|
c->sb_samples[ch][i]);
|
2010-11-21 22:42:06 +02:00
|
|
|
samples_ptr += 32 * channels;
|
2006-12-24 06:51:43 +02:00
|
|
|
}
|
|
|
|
}
|
2010-11-21 22:42:06 +02:00
|
|
|
for(i = 0; i < MPC_FRAME_SIZE*channels; i++)
|
2006-12-24 06:51:43 +02:00
|
|
|
*out++=samples[i];
|
|
|
|
}
|
|
|
|
|
2010-11-21 22:42:06 +02:00
|
|
|
void ff_mpc_dequantize_and_synth(MPCContext * c, int maxband, void *data, int channels)
|
2006-12-24 06:51:43 +02:00
|
|
|
{
|
2007-11-02 08:40:42 +02:00
|
|
|
int i, j, ch;
|
|
|
|
Band *bands = c->bands;
|
2006-12-24 06:51:43 +02:00
|
|
|
int off;
|
|
|
|
float mul;
|
|
|
|
|
|
|
|
/* dequantize */
|
|
|
|
memset(c->sb_samples, 0, sizeof(c->sb_samples));
|
|
|
|
off = 0;
|
2007-11-02 08:40:42 +02:00
|
|
|
for(i = 0; i <= maxband; i++, off += SAMPLES_PER_BAND){
|
2006-12-24 06:51:43 +02:00
|
|
|
for(ch = 0; ch < 2; ch++){
|
|
|
|
if(bands[i].res[ch]){
|
|
|
|
j = 0;
|
2007-11-02 08:40:42 +02:00
|
|
|
mul = mpc_CC[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][0]];
|
2006-12-24 06:51:43 +02:00
|
|
|
for(; j < 12; j++)
|
2007-11-02 08:40:42 +02:00
|
|
|
c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off];
|
|
|
|
mul = mpc_CC[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][1]];
|
2006-12-24 06:51:43 +02:00
|
|
|
for(; j < 24; j++)
|
2007-11-02 08:40:42 +02:00
|
|
|
c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off];
|
|
|
|
mul = mpc_CC[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][2]];
|
2006-12-24 06:51:43 +02:00
|
|
|
for(; j < 36; j++)
|
2007-11-02 08:40:42 +02:00
|
|
|
c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off];
|
2006-12-24 06:51:43 +02: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-21 22:42:06 +02:00
|
|
|
mpc_synth(c, data, channels);
|
2007-01-01 07:32:27 +02:00
|
|
|
}
|