mirror of
https://github.com/xiph/opus.git
synced 2025-06-03 17:17:42 +00:00
Converting the code to use the modes instead of global arrays.
This commit is contained in:
parent
ecb36a3323
commit
73e51b3e94
7 changed files with 40 additions and 23 deletions
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include <math.h>
|
||||
#include "bands.h"
|
||||
#include "modes.h"
|
||||
#include "vq.h"
|
||||
#include "cwrs.h"
|
||||
|
||||
|
@ -45,31 +46,35 @@ const int qpulses[NBANDS ] = {7, 5, 4, 4, 3, 3, 3, 4, 4, 4, -2, -1, -1, -1
|
|||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -62,15 +62,17 @@ struct CELTState_ {
|
|||
|
||||
|
||||
|
||||
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 @@ int celt_encode(CELTState *st, short *pcm)
|
|||
//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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -55,3 +55,5 @@ const CELTMode mode1 = {
|
|||
pbank1, /**< pBands*/
|
||||
qpulses1 /**< pulses */
|
||||
};
|
||||
|
||||
const CELTMode const *celt_mode1 = &mode1;
|
||||
|
|
|
@ -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 @@ typedef struct {
|
|||
const int *eBands;
|
||||
const int *pBands;
|
||||
const int *pulses;
|
||||
} CELTMode;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -48,7 +48,7 @@ int main(int argc, char *argv[])
|
|||
outFile = argv[2];
|
||||
fout = fopen(outFile, "wb+");
|
||||
|
||||
st = celt_encoder_new(FRAME_SIZE/NBLOCKS, NBLOCKS);
|
||||
st = celt_encoder_new(celt_mode1);
|
||||
|
||||
while (!feof(fin))
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue