Merge remote-tracking branch 'qatar/master'
* qatar/master: mpegaudioenc: Move some static tables to MpegAudioContext Conflicts: libavcodec/mpegaudioenc.c libavcodec/mpegaudiotab.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
commit
43bf4297e4
@ -64,6 +64,16 @@ typedef struct MpegAudioContext {
|
|||||||
unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT];
|
unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT];
|
||||||
int sblimit; /* number of used subbands */
|
int sblimit; /* number of used subbands */
|
||||||
const unsigned char *alloc_table;
|
const unsigned char *alloc_table;
|
||||||
|
int16_t filter_bank[512];
|
||||||
|
int scale_factor_table[64];
|
||||||
|
unsigned char scale_diff_table[128];
|
||||||
|
#ifdef USE_FLOATS
|
||||||
|
float scale_factor_inv_table[64];
|
||||||
|
#else
|
||||||
|
int8_t scale_factor_shift[64];
|
||||||
|
unsigned short scale_factor_mult[64];
|
||||||
|
#endif
|
||||||
|
unsigned short total_quant_bits[17]; /* total number of bits per allocation group */
|
||||||
} MpegAudioContext;
|
} MpegAudioContext;
|
||||||
|
|
||||||
static av_cold int MPA_encode_init(AVCodecContext *avctx)
|
static av_cold int MPA_encode_init(AVCodecContext *avctx)
|
||||||
@ -139,24 +149,24 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
|
|||||||
#if WFRAC_BITS != 16
|
#if WFRAC_BITS != 16
|
||||||
v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);
|
v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);
|
||||||
#endif
|
#endif
|
||||||
filter_bank[i] = v;
|
s->filter_bank[i] = v;
|
||||||
if ((i & 63) != 0)
|
if ((i & 63) != 0)
|
||||||
v = -v;
|
v = -v;
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
filter_bank[512 - i] = v;
|
s->filter_bank[512 - i] = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=0;i<64;i++) {
|
for(i=0;i<64;i++) {
|
||||||
v = (int)(exp2((3 - i) / 3.0) * (1 << 20));
|
v = (int)(exp2((3 - i) / 3.0) * (1 << 20));
|
||||||
if (v <= 0)
|
if (v <= 0)
|
||||||
v = 1;
|
v = 1;
|
||||||
scale_factor_table[i] = v;
|
s->scale_factor_table[i] = v;
|
||||||
#ifdef USE_FLOATS
|
#ifdef USE_FLOATS
|
||||||
scale_factor_inv_table[i] = exp2(-(3 - i) / 3.0) / (float)(1 << 20);
|
s->scale_factor_inv_table[i] = exp2(-(3 - i) / 3.0) / (float)(1 << 20);
|
||||||
#else
|
#else
|
||||||
#define P 15
|
#define P 15
|
||||||
scale_factor_shift[i] = 21 - P - (i / 3);
|
s->scale_factor_shift[i] = 21 - P - (i / 3);
|
||||||
scale_factor_mult[i] = (1 << P) * exp2((i % 3) / 3.0);
|
s->scale_factor_mult[i] = (1 << P) * exp2((i % 3) / 3.0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
for(i=0;i<128;i++) {
|
for(i=0;i<128;i++) {
|
||||||
@ -171,7 +181,7 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
|
|||||||
v = 3;
|
v = 3;
|
||||||
else
|
else
|
||||||
v = 4;
|
v = 4;
|
||||||
scale_diff_table[i] = v;
|
s->scale_diff_table[i] = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=0;i<17;i++) {
|
for(i=0;i<17;i++) {
|
||||||
@ -180,7 +190,7 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
|
|||||||
v = -v;
|
v = -v;
|
||||||
else
|
else
|
||||||
v = v * 3;
|
v = v * 3;
|
||||||
total_quant_bits[i] = 12 * v;
|
s->total_quant_bits[i] = 12 * v;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -327,7 +337,7 @@ static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
|
|||||||
|
|
||||||
/* filter */
|
/* filter */
|
||||||
p = s->samples_buf[ch] + offset;
|
p = s->samples_buf[ch] + offset;
|
||||||
q = filter_bank;
|
q = s->filter_bank;
|
||||||
/* maxsum = 23169 */
|
/* maxsum = 23169 */
|
||||||
for(i=0;i<64;i++) {
|
for(i=0;i<64;i++) {
|
||||||
sum = p[0*64] * q[0*64];
|
sum = p[0*64] * q[0*64];
|
||||||
@ -361,7 +371,8 @@ static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
|
|||||||
s->samples_offset[ch] = offset;
|
s->samples_offset[ch] = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void compute_scale_factors(unsigned char scale_code[SBLIMIT],
|
static void compute_scale_factors(MpegAudioContext *s,
|
||||||
|
unsigned char scale_code[SBLIMIT],
|
||||||
unsigned char scale_factors[SBLIMIT][3],
|
unsigned char scale_factors[SBLIMIT][3],
|
||||||
int sb_samples[3][12][SBLIMIT],
|
int sb_samples[3][12][SBLIMIT],
|
||||||
int sblimit)
|
int sblimit)
|
||||||
@ -388,7 +399,7 @@ static void compute_scale_factors(unsigned char scale_code[SBLIMIT],
|
|||||||
use at most 2 compares to find the index */
|
use at most 2 compares to find the index */
|
||||||
index = (21 - n) * 3 - 3;
|
index = (21 - n) * 3 - 3;
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
while (vmax <= scale_factor_table[index+1])
|
while (vmax <= s->scale_factor_table[index+1])
|
||||||
index++;
|
index++;
|
||||||
} else {
|
} else {
|
||||||
index = 0; /* very unlikely case of overflow */
|
index = 0; /* very unlikely case of overflow */
|
||||||
@ -398,7 +409,7 @@ static void compute_scale_factors(unsigned char scale_code[SBLIMIT],
|
|||||||
}
|
}
|
||||||
|
|
||||||
av_dlog(NULL, "%2d:%d in=%x %x %d\n",
|
av_dlog(NULL, "%2d:%d in=%x %x %d\n",
|
||||||
j, i, vmax, scale_factor_table[index], index);
|
j, i, vmax, s->scale_factor_table[index], index);
|
||||||
/* store the scale factor */
|
/* store the scale factor */
|
||||||
av_assert2(index >=0 && index <= 63);
|
av_assert2(index >=0 && index <= 63);
|
||||||
sf[i] = index;
|
sf[i] = index;
|
||||||
@ -406,8 +417,8 @@ static void compute_scale_factors(unsigned char scale_code[SBLIMIT],
|
|||||||
|
|
||||||
/* compute the transmission factor : look if the scale factors
|
/* compute the transmission factor : look if the scale factors
|
||||||
are close enough to each other */
|
are close enough to each other */
|
||||||
d1 = scale_diff_table[sf[0] - sf[1] + 64];
|
d1 = s->scale_diff_table[sf[0] - sf[1] + 64];
|
||||||
d2 = scale_diff_table[sf[1] - sf[2] + 64];
|
d2 = s->scale_diff_table[sf[1] - sf[2] + 64];
|
||||||
|
|
||||||
/* handle the 25 cases */
|
/* handle the 25 cases */
|
||||||
switch(d1 * 5 + d2) {
|
switch(d1 * 5 + d2) {
|
||||||
@ -557,12 +568,12 @@ static void compute_bit_allocation(MpegAudioContext *s,
|
|||||||
if (subband_status[max_ch][max_sb] == SB_NOTALLOCATED) {
|
if (subband_status[max_ch][max_sb] == SB_NOTALLOCATED) {
|
||||||
/* nothing was coded for this band: add the necessary bits */
|
/* nothing was coded for this band: add the necessary bits */
|
||||||
incr = 2 + nb_scale_factors[s->scale_code[max_ch][max_sb]] * 6;
|
incr = 2 + nb_scale_factors[s->scale_code[max_ch][max_sb]] * 6;
|
||||||
incr += total_quant_bits[alloc[1]];
|
incr += s->total_quant_bits[alloc[1]];
|
||||||
} else {
|
} else {
|
||||||
/* increments bit allocation */
|
/* increments bit allocation */
|
||||||
b = bit_alloc[max_ch][max_sb];
|
b = bit_alloc[max_ch][max_sb];
|
||||||
incr = total_quant_bits[alloc[b + 1]] -
|
incr = s->total_quant_bits[alloc[b + 1]] -
|
||||||
total_quant_bits[alloc[b]];
|
s->total_quant_bits[alloc[b]];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_frame_size + incr <= max_frame_size) {
|
if (current_frame_size + incr <= max_frame_size) {
|
||||||
@ -676,15 +687,15 @@ static void encode_frame(MpegAudioContext *s,
|
|||||||
#ifdef USE_FLOATS
|
#ifdef USE_FLOATS
|
||||||
{
|
{
|
||||||
float a;
|
float a;
|
||||||
a = (float)sample * scale_factor_inv_table[s->scale_factors[ch][i][k]];
|
a = (float)sample * s->scale_factor_inv_table[s->scale_factors[ch][i][k]];
|
||||||
q[m] = (int)((a + 1.0) * steps * 0.5);
|
q[m] = (int)((a + 1.0) * steps * 0.5);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
int q1, e, shift, mult;
|
int q1, e, shift, mult;
|
||||||
e = s->scale_factors[ch][i][k];
|
e = s->scale_factors[ch][i][k];
|
||||||
shift = scale_factor_shift[e];
|
shift = s->scale_factor_shift[e];
|
||||||
mult = scale_factor_mult[e];
|
mult = s->scale_factor_mult[e];
|
||||||
|
|
||||||
/* normalize to P bits */
|
/* normalize to P bits */
|
||||||
if (shift < 0)
|
if (shift < 0)
|
||||||
@ -739,7 +750,7 @@ static int MPA_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(i=0;i<s->nb_channels;i++) {
|
for(i=0;i<s->nb_channels;i++) {
|
||||||
compute_scale_factors(s->scale_code[i], s->scale_factors[i],
|
compute_scale_factors(s, s->scale_code[i], s->scale_factors[i],
|
||||||
s->sb_samples[i], s->sblimit);
|
s->sb_samples[i], s->sblimit);
|
||||||
}
|
}
|
||||||
for(i=0;i<s->nb_channels;i++) {
|
for(i=0;i<s->nb_channels;i++) {
|
||||||
|
@ -79,20 +79,6 @@ static const int bitinv32[32] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static int16_t filter_bank[512];
|
|
||||||
|
|
||||||
static int scale_factor_table[64];
|
|
||||||
#ifdef USE_FLOATS
|
|
||||||
static float scale_factor_inv_table[64];
|
|
||||||
#else
|
|
||||||
static int8_t scale_factor_shift[64];
|
|
||||||
static unsigned short scale_factor_mult[64];
|
|
||||||
#endif
|
|
||||||
static unsigned char scale_diff_table[128];
|
|
||||||
|
|
||||||
/* total number of bits per allocation group */
|
|
||||||
static unsigned short total_quant_bits[17];
|
|
||||||
|
|
||||||
/* signal to noise ratio of each quantification step (could be
|
/* signal to noise ratio of each quantification step (could be
|
||||||
computed from quant_steps[]). The values are dB multiplied by 10
|
computed from quant_steps[]). The values are dB multiplied by 10
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user