Propagating perceptual weighting around (not used yet).
This commit is contained in:
parent
36d78e6f74
commit
46014ca49a
6 changed files with 21 additions and 12 deletions
|
@ -214,7 +214,7 @@ void pitch_quant_bands(const CELTMode *m, float *X, float *P, float *gains)
|
|||
P[i] = 0;
|
||||
}
|
||||
|
||||
void quant_bands(const CELTMode *m, float *X, float *P, ec_enc *enc)
|
||||
void quant_bands(const CELTMode *m, float *X, float *P, float *W, ec_enc *enc)
|
||||
{
|
||||
int i, j, B;
|
||||
const int *eBands = m->eBands;
|
||||
|
@ -227,14 +227,14 @@ void quant_bands(const CELTMode *m, float *X, float *P, ec_enc *enc)
|
|||
q = m->nbPulses[i];
|
||||
if (q>0) {
|
||||
float n = sqrt(B*(eBands[i+1]-eBands[i]));
|
||||
alg_quant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], 0.7, enc);
|
||||
alg_quant(X+B*eBands[i], W+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], 0.7, enc);
|
||||
for (j=B*eBands[i];j<B*eBands[i+1];j++)
|
||||
norm[j] = X[j] * n;
|
||||
//printf ("%f ", log2(ncwrs64(B*(eBands[i+1]-eBands[i]), q))/(B*(eBands[i+1]-eBands[i])));
|
||||
//printf ("%f ", log2(ncwrs64(B*(eBands[i+1]-eBands[i]), q)));
|
||||
} else {
|
||||
float n = sqrt(B*(eBands[i+1]-eBands[i]));
|
||||
copy_quant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), -q, norm, B, eBands[i], enc);
|
||||
copy_quant(X+B*eBands[i], W+B*eBands[i], B*(eBands[i+1]-eBands[i]), -q, norm, B, eBands[i], enc);
|
||||
for (j=B*eBands[i];j<B*eBands[i+1];j++)
|
||||
norm[j] = X[j] * n;
|
||||
//printf ("%f ", (1+log2(eBands[i]-(eBands[i+1]-eBands[i]))+log2(ncwrs64(B*(eBands[i+1]-eBands[i]), -q)))/(B*(eBands[i+1]-eBands[i])));
|
||||
|
|
|
@ -47,7 +47,7 @@ void compute_pitch_gain(const CELTMode *m, float *X, float *P, float *gains, flo
|
|||
|
||||
void pitch_quant_bands(const CELTMode *m, float *X, float *P, float *gains);
|
||||
|
||||
void quant_bands(const CELTMode *m, float *X, float *P, ec_enc *enc);
|
||||
void quant_bands(const CELTMode *m, float *X, float *P, float *W, ec_enc *enc);
|
||||
|
||||
void unquant_bands(const CELTMode *m, float *X, float *P, ec_dec *dec);
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "probenc.h"
|
||||
#include "quant_pitch.h"
|
||||
#include "quant_bands.h"
|
||||
#include "psy.h"
|
||||
|
||||
#define MAX_PERIOD 1024
|
||||
|
||||
|
@ -50,6 +51,7 @@ struct CELTEncoder {
|
|||
int block_size;
|
||||
int nb_blocks;
|
||||
int channels;
|
||||
int Fs;
|
||||
|
||||
ec_byte_buffer buf;
|
||||
ec_enc enc;
|
||||
|
@ -83,6 +85,7 @@ CELTEncoder *celt_encoder_new(const CELTMode *mode)
|
|||
st->frame_size = B*N;
|
||||
st->block_size = N;
|
||||
st->nb_blocks = B;
|
||||
st->Fs = 44100;
|
||||
|
||||
ec_byte_writeinit(&st->buf);
|
||||
ec_enc_init(&st->enc,&st->buf);
|
||||
|
@ -207,6 +210,7 @@ int celt_encode(CELTEncoder *st, short *pcm)
|
|||
|
||||
float X[B*C*N]; /**< Interleaved signal MDCTs */
|
||||
float P[B*C*N]; /**< Interleaved pitch MDCTs*/
|
||||
float mask[B*C*N]; /**< Masking curve */
|
||||
float bandE[st->mode->nbEBands];
|
||||
float gains[st->mode->nbPBands];
|
||||
int pitch_index;
|
||||
|
@ -228,6 +232,11 @@ int celt_encode(CELTEncoder *st, short *pcm)
|
|||
/* Compute MDCTs */
|
||||
compute_mdcts(&st->mdct_lookup, st->window, in, X, N, B, C);
|
||||
|
||||
compute_masking(X, mask, B*C*N, st->Fs);
|
||||
/* Invert and stretch the mask to length of X */
|
||||
for (i=B*C*N-1;i>=0;i--)
|
||||
mask[i] = 1/(1+mask[i>>1]);
|
||||
|
||||
/* Pitch analysis */
|
||||
for (c=0;c<C;c++)
|
||||
{
|
||||
|
@ -286,7 +295,7 @@ int celt_encode(CELTEncoder *st, short *pcm)
|
|||
sum += X[i]*X[i];
|
||||
printf ("%f\n", sum);*/
|
||||
/* Residual quantisation */
|
||||
quant_bands(st->mode, X, P, &st->enc);
|
||||
quant_bands(st->mode, X, P, mask, &st->enc);
|
||||
|
||||
if (0) {//This is just for debugging
|
||||
ec_enc_done(&st->enc);
|
||||
|
|
|
@ -52,8 +52,8 @@ int main(int argc, char *argv[])
|
|||
outFile = argv[2];
|
||||
fout = fopen(outFile, "wb+");
|
||||
|
||||
enc = celt_encoder_new(celt_mode2);
|
||||
dec = celt_decoder_new(celt_mode2);
|
||||
enc = celt_encoder_new(celt_mode1);
|
||||
dec = celt_decoder_new(celt_mode1);
|
||||
|
||||
while (!feof(fin))
|
||||
{
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
/* Improved algebraic pulse-base quantiser. The signal x is replaced by the sum of the pitch
|
||||
a combination of pulses such that its norm is still equal to 1. The only difference with
|
||||
the quantiser above is that the search is more complete. */
|
||||
void alg_quant(float *x, int N, int K, float *p, float alpha, ec_enc *enc)
|
||||
void alg_quant(float *x, float *W, int N, int K, float *p, float alpha, ec_enc *enc)
|
||||
{
|
||||
int L = 3;
|
||||
//float tata[200];
|
||||
|
@ -223,7 +223,7 @@ void alg_quant(float *x, int N, int K, float *p, float alpha, ec_enc *enc)
|
|||
static const float pg[5] = {1.f, .6f, .45f, 0.35f, 0.25f};
|
||||
|
||||
/* Finds the right offset into Y and copy it */
|
||||
void copy_quant(float *x, int N, int K, float *Y, int B, int N0, ec_enc *enc)
|
||||
void copy_quant(float *x, float *W, int N, int K, float *Y, int B, int N0, ec_enc *enc)
|
||||
{
|
||||
int i,j;
|
||||
int best=0;
|
||||
|
@ -287,7 +287,7 @@ void copy_quant(float *x, int N, int K, float *Y, int B, int N0, ec_enc *enc)
|
|||
E = .8/sqrt(E);
|
||||
for (j=0;j<N;j++)
|
||||
P[j] *= E;
|
||||
alg_quant(x, N, K, P, 0, enc);
|
||||
alg_quant(x, W, N, K, P, 0, enc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,12 +39,12 @@
|
|||
/* Algebraic pulse-base quantiser. The signal x is replaced by the sum of the pitch
|
||||
a combination of pulses such that its norm is still equal to 1. The only difference with
|
||||
the quantiser above is that the search is more complete. */
|
||||
void alg_quant(float *x, int N, int K, float *p, float alpha, ec_enc *enc);
|
||||
void alg_quant(float *x, float *W, int N, int K, float *p, float alpha, ec_enc *enc);
|
||||
|
||||
void alg_unquant(float *x, int N, int K, float *p, float alpha, ec_dec *dec);
|
||||
|
||||
/* Finds the right offset into Y and copy it */
|
||||
void copy_quant(float *x, int N, int K, float *Y, int B, int N0, ec_enc *enc);
|
||||
void copy_quant(float *x, float *W, int N, int K, float *Y, int B, int N0, ec_enc *enc);
|
||||
|
||||
void copy_unquant(float *x, int N, int K, float *Y, int B, int N0, ec_dec *dec);
|
||||
#endif /* VQ_H */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue