Skip to content
Snippets Groups Projects
Commit 4841a0a0 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Intra-frame prediction

parent c4541ae7
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@
#include <math.h>
#include "bands.h"
#include "vq.h"
#include "cwrs.h"
const int qbank[NBANDS+2] = {0, 2, 4, 6, 8, 12, 16, 20, 24, 28, 36, 44, 52, 68, 84, 116, 128};
......@@ -144,15 +145,24 @@ void pitch_quant_bands(float *X, int B, float *P, float *gains)
void quant_bands(float *X, int B, float *P)
{
int i;
int i, j;
float norm[B*qbank[NBANDS+1]];
for (i=0;i<NBANDS;i++)
{
int q;
q =qpulses[i];
if (q) {
float n = sqrt(B*(qbank[i+1]-qbank[i]));
alg_quant2(X+B*qbank[i], B*(qbank[i+1]-qbank[i]), q, P+B*qbank[i]);
for (j=B*qbank[i];j<B*qbank[i+1];j++)
norm[j] = X[j] * n;
} else {
noise_quant(X+B*qbank[i], B*(qbank[i+1]-qbank[i]), q, P+B*qbank[i]);
float n = sqrt(B*(qbank[i+1]-qbank[i]));
copy_quant(X+B*qbank[i], B*(qbank[i+1]-qbank[i]), q, norm, B, qbank[i]);
for (j=B*qbank[i];j<B*qbank[i+1];j++)
norm[j] = X[j] * n;
//noise_quant(X+B*qbank[i], B*(qbank[i+1]-qbank[i]), q, P+B*qbank[i]);
}
}
for (i=B*qbank[NBANDS];i<B*qbank[NBANDS+1];i++)
......
......@@ -218,3 +218,39 @@ void noise_quant(float *x, int N, int K, float *p)
x[i] *= E;
}
}
/* Finds the right offset into Y and copy it */
void copy_quant(float *x, int N, int K, float *Y, int B, int N0)
{
int i,j;
int best=0;
float best_score=-1e15;
float E;
for (i=0;i<N0*B-N;i+=B)
{
int j;
float xy=0, yy=0;
float score;
for (j=0;j<N;j++)
{
xy += x[j]*Y[i+j];
yy += Y[i+j]*Y[i+j];
}
score = xy*xy/(.1*yy);
if (score > best_score)
{
best_score = score;
best = i;
}
}
//printf ("%d\n", best);
E = 1e-10;
for (j=0;j<N;j++)
{
x[j] = Y[best+j];
E += x[j]*x[j];
}
E = 1/sqrt(E);
for (j=0;j<N;j++)
x[j] *= E;
}
......@@ -44,5 +44,7 @@ void alg_quant2(float *x, int N, int K, float *p);
/* Just replace the band with noise of unit energy */
void noise_quant(float *x, int N, int K, float *p);
/* Finds the right offset into Y and copy it */
void copy_quant(float *x, int N, int K, float *Y, int B, int N0);
#endif /* VQ_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment