Re-organize spreading/folding constants.
These were stored internally in one order and in the bitstream in a different order. Both used bare constants, making it unclear what either actually meant. This changes them to use the same order, gives them named constants, and renames all the "fold" decision stuff to "spread" instead, since that is what it is really controlling.
This commit is contained in:
parent
cd84e3d0f4
commit
320cf2e2cd
4 changed files with 37 additions and 41 deletions
|
@ -282,7 +282,7 @@ static void stereo_merge(celt_norm *X, celt_norm *Y, celt_word16 mid, celt_word1
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Decide whether we should spread the pulses in the current frame */
|
/* Decide whether we should spread the pulses in the current frame */
|
||||||
int folding_decision(const CELTMode *m, celt_norm *X, int *average, int *last_decision, int end, int _C, int M)
|
int spreading_decision(const CELTMode *m, celt_norm *X, int *average, int last_decision, int end, int _C, int M)
|
||||||
{
|
{
|
||||||
int i, c, N0;
|
int i, c, N0;
|
||||||
int sum = 0, nbBands=0;
|
int sum = 0, nbBands=0;
|
||||||
|
@ -293,7 +293,7 @@ int folding_decision(const CELTMode *m, celt_norm *X, int *average, int *last_de
|
||||||
N0 = M*m->shortMdctSize;
|
N0 = M*m->shortMdctSize;
|
||||||
|
|
||||||
if (M*(eBands[end]-eBands[end-1]) <= 8)
|
if (M*(eBands[end]-eBands[end-1]) <= 8)
|
||||||
return 0;
|
return SPREAD_NONE;
|
||||||
c=0; do {
|
c=0; do {
|
||||||
for (i=0;i<end;i++)
|
for (i=0;i<end;i++)
|
||||||
{
|
{
|
||||||
|
@ -327,23 +327,18 @@ int folding_decision(const CELTMode *m, celt_norm *X, int *average, int *last_de
|
||||||
sum = (sum+*average)>>1;
|
sum = (sum+*average)>>1;
|
||||||
*average = sum;
|
*average = sum;
|
||||||
/* Hysteresis */
|
/* Hysteresis */
|
||||||
sum = (3*sum + ((*last_decision<<7) + 64) + 2)>>2;
|
sum = (3*sum + (((3-last_decision)<<7) + 64) + 2)>>2;
|
||||||
/* decision and last_decision do not use the same encoding */
|
|
||||||
if (sum < 80)
|
if (sum < 80)
|
||||||
{
|
{
|
||||||
decision = 2;
|
decision = SPREAD_AGGRESSIVE;
|
||||||
*last_decision = 0;
|
|
||||||
} else if (sum < 256)
|
} else if (sum < 256)
|
||||||
{
|
{
|
||||||
decision = 1;
|
decision = SPREAD_NORMAL;
|
||||||
*last_decision = 1;
|
|
||||||
} else if (sum < 384)
|
} else if (sum < 384)
|
||||||
{
|
{
|
||||||
decision = 3;
|
decision = SPREAD_LIGHT;
|
||||||
*last_decision = 2;
|
|
||||||
} else {
|
} else {
|
||||||
decision = 0;
|
decision = SPREAD_NONE;
|
||||||
*last_decision = 3;
|
|
||||||
}
|
}
|
||||||
return decision;
|
return decision;
|
||||||
}
|
}
|
||||||
|
@ -828,7 +823,7 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_
|
||||||
int j;
|
int j;
|
||||||
if (lowband != NULL && resynth)
|
if (lowband != NULL && resynth)
|
||||||
{
|
{
|
||||||
if (spread==2 && B<=1)
|
if (spread==SPREAD_AGGRESSIVE && B<=1)
|
||||||
{
|
{
|
||||||
/* Noise */
|
/* Noise */
|
||||||
for (j=0;j<N;j++)
|
for (j=0;j<N;j++)
|
||||||
|
@ -903,7 +898,7 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_
|
||||||
|
|
||||||
void quant_all_bands(int encode, const CELTMode *m, int start, int end,
|
void quant_all_bands(int encode, const CELTMode *m, int start, int end,
|
||||||
celt_norm *_X, celt_norm *_Y, const celt_ener *bandE, int *pulses,
|
celt_norm *_X, celt_norm *_Y, const celt_ener *bandE, int *pulses,
|
||||||
int shortBlocks, int fold, int dual_stereo, int intensity, int *tf_res, int resynth,
|
int shortBlocks, int spread, int dual_stereo, int intensity, int *tf_res, int resynth,
|
||||||
int total_bits, void *ec, int LM, int codedBands)
|
int total_bits, void *ec, int LM, int codedBands)
|
||||||
{
|
{
|
||||||
int i, balance;
|
int i, balance;
|
||||||
|
@ -1028,14 +1023,14 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end,
|
||||||
}
|
}
|
||||||
if (dual_stereo)
|
if (dual_stereo)
|
||||||
{
|
{
|
||||||
quant_band(encode, m, i, X, NULL, N, b/2, fold, B, intensity, tf_change,
|
quant_band(encode, m, i, X, NULL, N, b/2, spread, B, intensity, tf_change,
|
||||||
effective_lowband != -1 ? norm+effective_lowband : NULL, resynth, ec, &remaining_bits, LM,
|
effective_lowband != -1 ? norm+effective_lowband : NULL, resynth, ec, &remaining_bits, LM,
|
||||||
norm+M*eBands[i], bandE, 0, &seed, Q15ONE, lowband_scratch);
|
norm+M*eBands[i], bandE, 0, &seed, Q15ONE, lowband_scratch);
|
||||||
quant_band(encode, m, i, Y, NULL, N, b/2, fold, B, intensity, tf_change,
|
quant_band(encode, m, i, Y, NULL, N, b/2, spread, B, intensity, tf_change,
|
||||||
effective_lowband != -1 ? norm2+effective_lowband : NULL, resynth, ec, &remaining_bits, LM,
|
effective_lowband != -1 ? norm2+effective_lowband : NULL, resynth, ec, &remaining_bits, LM,
|
||||||
norm2+M*eBands[i], bandE, 0, &seed, Q15ONE, lowband_scratch);
|
norm2+M*eBands[i], bandE, 0, &seed, Q15ONE, lowband_scratch);
|
||||||
} else {
|
} else {
|
||||||
quant_band(encode, m, i, X, Y, N, b, fold, B, intensity, tf_change,
|
quant_band(encode, m, i, X, Y, N, b, spread, B, intensity, tf_change,
|
||||||
effective_lowband != -1 ? norm+effective_lowband : NULL, resynth, ec, &remaining_bits, LM,
|
effective_lowband != -1 ? norm+effective_lowband : NULL, resynth, ec, &remaining_bits, LM,
|
||||||
norm+M*eBands[i], bandE, 0, &seed, Q15ONE, lowband_scratch);
|
norm+M*eBands[i], bandE, 0, &seed, Q15ONE, lowband_scratch);
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,12 @@ void normalise_bands(const CELTMode *m, const celt_sig * restrict freq, celt_nor
|
||||||
*/
|
*/
|
||||||
void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig * restrict freq, const celt_ener *bands, int end, int _C, int M);
|
void denormalise_bands(const CELTMode *m, const celt_norm * restrict X, celt_sig * restrict freq, const celt_ener *bands, int end, int _C, int M);
|
||||||
|
|
||||||
int folding_decision(const CELTMode *m, celt_norm *X, int *average, int *last_decision, int end, int _C, int M);
|
#define SPREAD_NONE (0)
|
||||||
|
#define SPREAD_LIGHT (1)
|
||||||
|
#define SPREAD_NORMAL (2)
|
||||||
|
#define SPREAD_AGGRESSIVE (3)
|
||||||
|
|
||||||
|
int spreading_decision(const CELTMode *m, celt_norm *X, int *average, int last_decision, int end, int _C, int M);
|
||||||
|
|
||||||
#ifdef MEASURE_NORM_MSE
|
#ifdef MEASURE_NORM_MSE
|
||||||
void measure_norm_mse(const CELTMode *m, float *X, float *X0, float *bandE, float *bandE0, int M, int N, int C);
|
void measure_norm_mse(const CELTMode *m, float *X, float *X0, float *bandE, float *bandE0, int M, int N, int C);
|
||||||
|
|
|
@ -77,7 +77,7 @@ struct CELTEncoder {
|
||||||
#define ENCODER_RESET_START frame_max
|
#define ENCODER_RESET_START frame_max
|
||||||
|
|
||||||
celt_word32 frame_max;
|
celt_word32 frame_max;
|
||||||
int fold_decision;
|
int spread_decision;
|
||||||
int delayedIntra;
|
int delayedIntra;
|
||||||
int tonal_average;
|
int tonal_average;
|
||||||
int lastCodedBands;
|
int lastCodedBands;
|
||||||
|
@ -155,7 +155,7 @@ CELTEncoder *celt_encoder_init(CELTEncoder *st, const CELTMode *mode, int channe
|
||||||
st->force_intra = 0;
|
st->force_intra = 0;
|
||||||
st->delayedIntra = 1;
|
st->delayedIntra = 1;
|
||||||
st->tonal_average = 256;
|
st->tonal_average = 256;
|
||||||
st->fold_decision = 1;
|
st->spread_decision = SPREAD_NORMAL;
|
||||||
st->complexity = 5;
|
st->complexity = 5;
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
|
@ -719,7 +719,6 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
|
||||||
#endif
|
#endif
|
||||||
int i, c, N;
|
int i, c, N;
|
||||||
int bits;
|
int bits;
|
||||||
int has_fold=1;
|
|
||||||
ec_byte_buffer buf;
|
ec_byte_buffer buf;
|
||||||
ec_enc _enc;
|
ec_enc _enc;
|
||||||
VARDECL(celt_sig, in);
|
VARDECL(celt_sig, in);
|
||||||
|
@ -950,17 +949,17 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
|
||||||
{
|
{
|
||||||
if (st->complexity == 0)
|
if (st->complexity == 0)
|
||||||
{
|
{
|
||||||
has_fold = 0;
|
st->spread_decision = SPREAD_NONE;
|
||||||
st->fold_decision = 3;
|
|
||||||
} else {
|
} else {
|
||||||
has_fold = 1;
|
st->spread_decision = SPREAD_NORMAL;
|
||||||
st->fold_decision = 1;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
has_fold = folding_decision(st->mode, X, &st->tonal_average, &st->fold_decision, effEnd, C, M);
|
st->spread_decision = spreading_decision(st->mode, X, &st->tonal_average, st->spread_decision, effEnd, C, M);
|
||||||
}
|
}
|
||||||
ec_enc_bit_prob(enc, has_fold>>1, 8192);
|
/* Probs: NONE: 21.875%, LIGHT: 6.25%, NORMAL: 65.625%, AGGRESSIVE: 6.25% */
|
||||||
ec_enc_bit_prob(enc, has_fold&1, (has_fold>>1) ? 32768 : 49152);
|
ec_enc_bit_prob(enc, st->spread_decision>>1, 18432);
|
||||||
|
ec_enc_bit_prob(enc, st->spread_decision&1,
|
||||||
|
(st->spread_decision>>1) ? 5699 : 14564);
|
||||||
|
|
||||||
ALLOC(offsets, st->mode->nbEBands, int);
|
ALLOC(offsets, st->mode->nbEBands, int);
|
||||||
|
|
||||||
|
@ -1144,7 +1143,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
|
||||||
|
|
||||||
/* Residual quantisation */
|
/* Residual quantisation */
|
||||||
quant_all_bands(1, st->mode, st->start, st->end, X, C==2 ? X+N : NULL,
|
quant_all_bands(1, st->mode, st->start, st->end, X, C==2 ? X+N : NULL,
|
||||||
bandE, pulses, shortBlocks, has_fold, dual_stereo, intensity, tf_res, resynth,
|
bandE, pulses, shortBlocks, st->spread_decision, dual_stereo, intensity, tf_res, resynth,
|
||||||
nbCompressedBytes*8, enc, LM, codedBands);
|
nbCompressedBytes*8, enc, LM, codedBands);
|
||||||
|
|
||||||
quant_energy_finalise(st->mode, st->start, st->end, bandE, oldBandE, error, fine_quant, fine_priority, nbCompressedBytes*8-ec_enc_tell(enc, 0), enc, C);
|
quant_energy_finalise(st->mode, st->start, st->end, bandE, oldBandE, error, fine_quant, fine_priority, nbCompressedBytes*8-ec_enc_tell(enc, 0), enc, C);
|
||||||
|
@ -1388,7 +1387,7 @@ int celt_encoder_ctl(CELTEncoder * restrict st, int request, ...)
|
||||||
((char*)&st->ENCODER_RESET_START - (char*)st));
|
((char*)&st->ENCODER_RESET_START - (char*)st));
|
||||||
st->vbr_offset = 0;
|
st->vbr_offset = 0;
|
||||||
st->delayedIntra = 1;
|
st->delayedIntra = 1;
|
||||||
st->fold_decision = 1;
|
st->spread_decision = SPREAD_NORMAL;
|
||||||
st->tonal_average = QCONST16(1.f,8);
|
st->tonal_average = QCONST16(1.f,8);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1695,7 +1694,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
int c, i, N;
|
int c, i, N;
|
||||||
int has_fold;
|
int spread_decision;
|
||||||
int bits;
|
int bits;
|
||||||
ec_dec _dec;
|
ec_dec _dec;
|
||||||
ec_byte_buffer buf;
|
ec_byte_buffer buf;
|
||||||
|
@ -1824,8 +1823,8 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
|
||||||
ALLOC(tf_res, st->mode->nbEBands, int);
|
ALLOC(tf_res, st->mode->nbEBands, int);
|
||||||
tf_decode(st->start, st->end, C, isTransient, tf_res, LM, dec);
|
tf_decode(st->start, st->end, C, isTransient, tf_res, LM, dec);
|
||||||
|
|
||||||
has_fold = ec_dec_bit_prob(dec, 8192)<<1;
|
spread_decision = ec_dec_bit_prob(dec, 18432)<<1;
|
||||||
has_fold |= ec_dec_bit_prob(dec, (has_fold>>1) ? 32768 : 49152);
|
spread_decision |= ec_dec_bit_prob(dec, (spread_decision>>1) ? 5699 : 14564);
|
||||||
|
|
||||||
ALLOC(pulses, st->mode->nbEBands, int);
|
ALLOC(pulses, st->mode->nbEBands, int);
|
||||||
ALLOC(offsets, st->mode->nbEBands, int);
|
ALLOC(offsets, st->mode->nbEBands, int);
|
||||||
|
@ -1868,7 +1867,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
|
||||||
|
|
||||||
/* Decode fixed codebook */
|
/* Decode fixed codebook */
|
||||||
quant_all_bands(0, st->mode, st->start, st->end, X, C==2 ? X+N : NULL,
|
quant_all_bands(0, st->mode, st->start, st->end, X, C==2 ? X+N : NULL,
|
||||||
NULL, pulses, shortBlocks, has_fold, dual_stereo, intensity, tf_res, 1,
|
NULL, pulses, shortBlocks, spread_decision, dual_stereo, intensity, tf_res, 1,
|
||||||
len*8, dec, LM, codedBands);
|
len*8, dec, LM, codedBands);
|
||||||
|
|
||||||
unquant_energy_finalise(st->mode, st->start, st->end, bandE, oldBandE,
|
unquant_energy_finalise(st->mode, st->start, st->end, bandE, oldBandE,
|
||||||
|
|
11
libcelt/vq.c
11
libcelt/vq.c
|
@ -39,6 +39,7 @@
|
||||||
#include "vq.h"
|
#include "vq.h"
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
#include "os_support.h"
|
#include "os_support.h"
|
||||||
|
#include "bands.h"
|
||||||
#include "rate.h"
|
#include "rate.h"
|
||||||
|
|
||||||
#ifndef M_PI
|
#ifndef M_PI
|
||||||
|
@ -71,6 +72,7 @@ static void exp_rotation1(celt_norm *X, int len, int stride, celt_word16 c, celt
|
||||||
|
|
||||||
static void exp_rotation(celt_norm *X, int len, int dir, int stride, int K, int spread)
|
static void exp_rotation(celt_norm *X, int len, int dir, int stride, int K, int spread)
|
||||||
{
|
{
|
||||||
|
static const int SPREAD_FACTOR[3]={5,10,15};
|
||||||
int i;
|
int i;
|
||||||
celt_word16 c, s;
|
celt_word16 c, s;
|
||||||
celt_word16 gain, theta;
|
celt_word16 gain, theta;
|
||||||
|
@ -84,14 +86,9 @@ static void exp_rotation(celt_norm *X, int len, int dir, int stride, int K, int
|
||||||
X[14] = 1;
|
X[14] = 1;
|
||||||
K=5;
|
K=5;
|
||||||
}*/
|
}*/
|
||||||
if (2*K>=len || spread==0)
|
if (2*K>=len || spread==SPREAD_NONE)
|
||||||
return;
|
return;
|
||||||
if (spread==1)
|
factor = SPREAD_FACTOR[spread-1];
|
||||||
factor=10;
|
|
||||||
else if (spread==2)
|
|
||||||
factor=5;
|
|
||||||
else
|
|
||||||
factor=15;
|
|
||||||
|
|
||||||
gain = celt_div((celt_word32)MULT16_16(Q15_ONE,len),(celt_word32)(len+factor*K));
|
gain = celt_div((celt_word32)MULT16_16(Q15_ONE,len),(celt_word32)(len+factor*K));
|
||||||
/* FIXME: Make that HALF16 instead of HALF32 */
|
/* FIXME: Make that HALF16 instead of HALF32 */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue