ref: 73e51b3e94d4e9708fa1ede4b45dc56968a6f3ac
parent: ecb36a3323b0d222224546f818e7c701f67c2de7
author: Jean-Marc Valin <[email protected]>
date: Wed Dec 5 12:48:24 EST 2007
Converting the code to use the modes instead of global arrays.
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -31,6 +31,7 @@
#include <math.h>
#include "bands.h"
+#include "modes.h"
#include "vq.h"
#include "cwrs.h"
@@ -45,14 +46,16 @@
int pbank[] = {0, 4, 8, 12, 20, WAVEFORM_END, 128};
/* Compute the energy in each of the bands */
-void compute_bands(float *X, int B, float *bank)
+void compute_band_energies(const CELTMode *m, float *X, float *bank)
{
- int i;
+ int i, B;
+ const int *eBands = m->eBands;
+ B = m->nbMdctBlocks;
for (i=0;i<NBANDS;i++)
{
int j;
bank[i] = 1e-10;
- for (j=B*qbank[i];j<B*qbank[i+1];j++)
+ for (j=B*eBands[i];j<B*eBands[i+1];j++)
bank[i] += X[j]*X[j];
bank[i] = sqrt(bank[i]);
}
@@ -59,17 +62,19 @@
}
/* Normalise each band such that the energy is one. */
-void normalise_bands(float *X, int B, float *bank)
+void normalise_bands(const CELTMode *m, float *X, float *bank)
{
- int i;
+ int i, B;
+ const int *eBands = m->eBands;
+ B = m->nbMdctBlocks;
for (i=0;i<NBANDS;i++)
{
int j;
float x = 1.f/(1e-10+bank[i]);
- for (j=B*qbank[i];j<B*qbank[i+1];j++)
+ for (j=B*eBands[i];j<B*eBands[i+1];j++)
X[j] *= x;
}
- for (i=B*qbank[NBANDS];i<B*qbank[NBANDS+1];i++)
+ for (i=B*eBands[NBANDS];i<B*eBands[NBANDS+1];i++)
X[i] = 0;
}
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -32,14 +32,16 @@
#ifndef BANDS_H
#define BANDS_H
+#include "modes.h"
+
/* Number of constant-energy bands */
#define NBANDS 15
/* Number of bands only for the pitch prediction */
#define PBANDS 5
-void compute_bands(float *X, int B, float *bands);
+void compute_band_energies(const CELTMode *m, float *X, float *bands);
-void normalise_bands(float *X, int B, float *bands);
+void normalise_bands(const CELTMode *m, float *X, float *bands);
void denormalise_bands(float *X, int B, float *bands);
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -62,15 +62,17 @@
-CELTState *celt_encoder_new(int blockSize, int blocksPerFrame)
+CELTState *celt_encoder_new(const CELTMode *mode)
{
- int i, N;
- N = blockSize;
+ int i, N, B;
+ N = mode->mdctSize;
+ B = mode->nbMdctBlocks;
CELTState *st = celt_alloc(sizeof(CELTState));
- st->frame_size = blockSize * blocksPerFrame;
- st->block_size = blockSize;
- st->nb_blocks = blocksPerFrame;
+ st->mode = mode;
+ st->frame_size = B*N;
+ st->block_size = N;
+ st->nb_blocks = B;
mdct_init(&st->mdct_lookup, 2*N);
st->fft = spx_fft_init(MAX_PERIOD);
@@ -197,11 +199,12 @@
//haar1(P, B*N);
/* Band normalisation */
- compute_bands(X, B, bandE);
- normalise_bands(X, B, bandE);
+ compute_band_energies(st->mode, X, bandE);
+ normalise_bands(st->mode, X, bandE);
- compute_bands(P, B, bandEp);
- normalise_bands(P, B, bandEp);
+ //for (i=0;i<NBANDS;i++)printf("%f ", bandE[i]);printf("\n");
+ compute_band_energies(st->mode, P, bandEp);
+ normalise_bands(st->mode, P, bandEp);
/* Pitch prediction */
compute_pitch_gain(X, B, P, gains, bandE);
--- a/libcelt/celt.h
+++ b/libcelt/celt.h
@@ -35,9 +35,12 @@
struct CELTState_;
typedef struct CELTState_ CELTState;
+struct CELTMode_;
+typedef struct CELTMode_ CELTMode;
+extern const CELTMode const *celt_mode1;
-CELTState *celt_encoder_new(int blockSize, int blocksPerFrame);
+CELTState *celt_encoder_new(const CELTMode *mode);
void celt_encoder_destroy(CELTState *st);
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -55,3 +55,5 @@
pbank1, /**< pBands*/
qpulses1 /**< pulses */
};
+
+const CELTMode const *celt_mode1 = &mode1;
--- a/libcelt/modes.h
+++ b/libcelt/modes.h
@@ -32,7 +32,9 @@
#ifndef MODES_H
#define MODES_H
-typedef struct {
+#include "celt.h"
+
+struct CELTMode_ {
int frameSize;
int mdctSize;
int nbMdctBlocks;
@@ -44,6 +46,6 @@
const int *eBands;
const int *pBands;
const int *pulses;
-} CELTMode;
+};
#endif
--- a/libcelt/testcelt.c
+++ b/libcelt/testcelt.c
@@ -48,7 +48,7 @@
outFile = argv[2];
fout = fopen(outFile, "wb+");
- st = celt_encoder_new(FRAME_SIZE/NBLOCKS, NBLOCKS);
+ st = celt_encoder_new(celt_mode1);
while (!feof(fin))
{