mirror of
https://github.com/xiph/opus.git
synced 2025-06-06 07:21:03 +00:00
Removing original freq-domain pitch code
This commit is contained in:
parent
294863bbea
commit
9319e3e6df
6 changed files with 10 additions and 241 deletions
|
@ -15,18 +15,16 @@ lib_LTLIBRARIES = libcelt.la
|
|||
|
||||
# Sources for compilation in the library
|
||||
libcelt_la_SOURCES = bands.c celt.c cwrs.c ecintrin.h entcode.c \
|
||||
entdec.c entenc.c header.c kfft_single.c kiss_fft.c kiss_fftr.c laplace.c mdct.c \
|
||||
modes.c pitch.c psy.c quant_bands.c rangedec.c rangeenc.c rate.c \
|
||||
entdec.c entenc.c header.c kiss_fft.c laplace.c mdct.c \
|
||||
modes.c pitch.c quant_bands.c rangedec.c rangeenc.c rate.c \
|
||||
vq.c
|
||||
|
||||
#noinst_HEADERS =
|
||||
|
||||
libcelt_la_LDFLAGS = -version-info @CELT_LT_CURRENT@:@CELT_LT_REVISION@:@CELT_LT_AGE@
|
||||
|
||||
noinst_HEADERS = _kiss_fft_guts.h arch.h bands.h fixed_c5x.h fixed_c6x.h \
|
||||
cwrs.h ecintrin.h entcode.h entdec.h entenc.h fixed_generic.h float_cast.h \
|
||||
kfft_double.h kfft_single.h kiss_fft.h kiss_fftr.h laplace.h mdct.h mfrngcod.h \
|
||||
mathops.h modes.h os_support.h pitch.h psy.h \
|
||||
kfft_double.h kiss_fft.h laplace.h mdct.h mfrngcod.h \
|
||||
mathops.h modes.h os_support.h pitch.h \
|
||||
quant_bands.h rate.h stack_alloc.h vq.h
|
||||
|
||||
noinst_PROGRAMS = testcelt dump_modes
|
||||
|
|
|
@ -446,8 +446,6 @@ static celt_uint32 ncwrs_urow(unsigned _n,unsigned _k,celt_uint32 *_u){
|
|||
return _u[_k]+_u[_k+1];
|
||||
}
|
||||
|
||||
#ifndef SMALL_FOOTPRINT
|
||||
|
||||
/*Returns the _i'th combination of _k elements (at most 32767) chosen from a
|
||||
set of size 1 with associated sign bits.
|
||||
_y: Returns the vector of pulses.*/
|
||||
|
@ -457,6 +455,8 @@ static inline void cwrsi1(int _k,celt_uint32 _i,int *_y){
|
|||
_y[0]=_k+s^s;
|
||||
}
|
||||
|
||||
#ifndef SMALL_FOOTPRINT
|
||||
|
||||
/*Returns the _i'th combination of _k elements (at most 32767) chosen from a
|
||||
set of size 2 with associated sign bits.
|
||||
_y: Returns the vector of pulses.*/
|
||||
|
|
|
@ -83,16 +83,6 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
|
|||
fprintf(file, "#endif\n");
|
||||
fprintf(file, "\n");
|
||||
|
||||
fprintf(file, "#ifndef DEF_PSY%d\n", mode->Fs);
|
||||
fprintf(file, "#define DEF_PSY%d\n", mode->Fs);
|
||||
fprintf (file, "static const celt_word16 psy_decayR_%d[%d] = {\n", mode->Fs, MAX_PERIOD/2);
|
||||
for (j=0;j<MAX_PERIOD/2;j++)
|
||||
fprintf (file, WORD16 ", ", mode->psy.decayR[j]);
|
||||
fprintf (file, "};\n");
|
||||
fprintf(file, "#endif\n");
|
||||
fprintf(file, "\n");
|
||||
|
||||
|
||||
fprintf(file, "#ifndef DEF_ALLOC_VECTORS%d_%d\n", mode->Fs, mode->mdctSize);
|
||||
fprintf(file, "#define DEF_ALLOC_VECTORS%d_%d\n", mode->Fs, mode->mdctSize);
|
||||
fprintf (file, "static const celt_int16 allocVectors%d_%d[%d] = {\n", mode->Fs, mode->mdctSize, mode->nbEBands*mode->nbAllocVectors);
|
||||
|
@ -114,8 +104,8 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
|
|||
int k;
|
||||
if (j==0 || (mode->bits[j] != mode->bits[j-1]))
|
||||
{
|
||||
fprintf (file, "static const celt_int16 allocCache_band%d_%d_%d[MAX_PULSES] = {\n", j, mode->Fs, mode->mdctSize);
|
||||
for (k=0;k<MAX_PULSES;k++)
|
||||
fprintf (file, "static const celt_int16 allocCache_band%d_%d_%d[MAX_PSEUDO] = {\n", j, mode->Fs, mode->mdctSize);
|
||||
for (k=0;k<MAX_PSEUDO;k++)
|
||||
fprintf (file, "%2d, ", mode->bits[j][k]);
|
||||
fprintf (file, "};\n");
|
||||
} else {
|
||||
|
@ -145,13 +135,11 @@ void dump_modes(FILE *file, CELTMode **modes, int nb_modes)
|
|||
fprintf(file, "allocVectors%d_%d,\t/* allocVectors */\n", mode->Fs, mode->mdctSize);
|
||||
fprintf(file, "allocCache%d_%d,\t/* bits */\n", mode->Fs, mode->mdctSize);
|
||||
fprintf(file, "{%d, 0, 0},\t/* mdct */\n", 2*mode->mdctSize);
|
||||
fprintf(file, "0,\t/* fft */\n");
|
||||
fprintf(file, "window%d,\t/* window */\n", mode->overlap);
|
||||
fprintf(file, "%d,\t/* nbShortMdcts */\n", mode->nbShortMdcts);
|
||||
fprintf(file, "%d,\t/* shortMdctSize */\n", mode->shortMdctSize);
|
||||
fprintf(file, "{%d, 0, 0},\t/* shortMdct */\n", 2*mode->mdctSize);
|
||||
fprintf(file, "window%d,\t/* shortWindow */\n", mode->overlap);
|
||||
fprintf(file, "{psy_decayR_%d},\t/* psy */\n", mode->Fs);
|
||||
fprintf(file, "0,\t/* prob */\n");
|
||||
fprintf(file, "0x%x,\t/* marker */\n", 0xa110ca7e);
|
||||
fprintf(file, "};\n");
|
||||
|
|
|
@ -367,16 +367,9 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error)
|
|||
if (mode->bits==NULL)
|
||||
goto failure;
|
||||
|
||||
#ifndef SHORTCUTS
|
||||
psydecay_init(&mode->psy, MAX_PERIOD/2, mode->Fs);
|
||||
if (mode->psy.decayR==NULL)
|
||||
goto failure;
|
||||
#endif
|
||||
|
||||
#endif /* !STATIC_MODES */
|
||||
|
||||
mdct_init(&mode->mdct, 2*mode->mdctSize);
|
||||
mode->fft = pitch_state_alloc(MAX_PERIOD);
|
||||
|
||||
mode->shortMdctSize = mode->mdctSize/mode->nbShortMdcts;
|
||||
mdct_init(&mode->shortMdct, 2*mode->shortMdctSize);
|
||||
|
@ -384,7 +377,7 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error)
|
|||
mode->prob = quant_prob_alloc(mode);
|
||||
if ((mode->mdct.trig==NULL) || (mode->shortMdct.trig==NULL)
|
||||
#ifndef ENABLE_TI_DSPLIB55
|
||||
|| (mode->mdct.kfft==NULL) || (mode->fft==NULL) || (mode->shortMdct.kfft==NULL)
|
||||
|| (mode->mdct.kfft==NULL) || (mode->shortMdct.kfft==NULL)
|
||||
#endif
|
||||
|| (mode->prob==NULL))
|
||||
goto failure;
|
||||
|
@ -442,13 +435,9 @@ void celt_mode_destroy(CELTMode *mode)
|
|||
|
||||
celt_free((celt_word16*)mode->window);
|
||||
|
||||
#ifndef SHORTCUTS
|
||||
psydecay_clear(&mode->psy);
|
||||
#endif
|
||||
#endif
|
||||
mdct_clear(&mode->mdct);
|
||||
mdct_clear(&mode->shortMdct);
|
||||
pitch_state_free(mode->fft);
|
||||
quant_prob_free(mode->prob);
|
||||
mode->marker_end = MODEFREED;
|
||||
celt_free((CELTMode *)mode);
|
||||
|
|
|
@ -98,7 +98,6 @@ struct CELTMode {
|
|||
|
||||
/* Stuff that could go in the {en,de}coder, but we save space this way */
|
||||
mdct_lookup mdct;
|
||||
kiss_fftr_cfg fft;
|
||||
|
||||
const celt_word16 *window;
|
||||
|
||||
|
@ -107,8 +106,6 @@ struct CELTMode {
|
|||
mdct_lookup shortMdct;
|
||||
const celt_word16 *shortWindow;
|
||||
|
||||
struct PsyDecay psy;
|
||||
|
||||
int *prob;
|
||||
celt_uint32 marker_end;
|
||||
};
|
||||
|
|
205
libcelt/pitch.c
205
libcelt/pitch.c
|
@ -40,214 +40,11 @@
|
|||
#include "config.h"
|
||||
#endif
|
||||
|
||||
/*#include "_kiss_fft_guts.h"
|
||||
#include "kiss_fftr.h"*/
|
||||
#include "kfft_single.h"
|
||||
|
||||
#include "pitch.h"
|
||||
#include "psy.h"
|
||||
#include "os_support.h"
|
||||
#include "mathops.h"
|
||||
#include "modes.h"
|
||||
#include "stack_alloc.h"
|
||||
|
||||
kiss_fftr_cfg pitch_state_alloc(int max_lag)
|
||||
{
|
||||
return real16_fft_alloc(max_lag);
|
||||
}
|
||||
|
||||
void pitch_state_free(kiss_fftr_cfg st)
|
||||
{
|
||||
real16_fft_free(st);
|
||||
}
|
||||
|
||||
#ifdef FIXED_POINT
|
||||
static void normalise16(celt_word16 *x, int len, celt_word16 val)
|
||||
{
|
||||
int i;
|
||||
celt_word16 maxabs;
|
||||
maxabs = celt_maxabs16(x,len);
|
||||
if (maxabs > val)
|
||||
{
|
||||
int shift = 0;
|
||||
while (maxabs > val)
|
||||
{
|
||||
maxabs >>= 1;
|
||||
shift++;
|
||||
}
|
||||
if (shift==0)
|
||||
return;
|
||||
i=0;
|
||||
do{
|
||||
x[i] = SHR16(x[i], shift);
|
||||
} while (++i<len);
|
||||
} else {
|
||||
int shift=0;
|
||||
if (maxabs == 0)
|
||||
return;
|
||||
val >>= 1;
|
||||
while (maxabs < val)
|
||||
{
|
||||
val >>= 1;
|
||||
shift++;
|
||||
}
|
||||
if (shift==0)
|
||||
return;
|
||||
i=0;
|
||||
do{
|
||||
x[i] = SHL16(x[i], shift);
|
||||
} while (++i<len);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define normalise16(x,len,val)
|
||||
#endif
|
||||
|
||||
#define INPUT_SHIFT 15
|
||||
|
||||
void find_spectral_pitch(const CELTMode *m, kiss_fftr_cfg fft, const struct PsyDecay *decay, const celt_sig * restrict x, const celt_sig * restrict y, const celt_word16 * restrict window, celt_word16 * restrict spectrum, int len, int max_pitch, int *pitch, int _C)
|
||||
{
|
||||
int c, i;
|
||||
VARDECL(celt_word16, _X);
|
||||
VARDECL(celt_word16, _Y);
|
||||
const celt_word16 * restrict wptr;
|
||||
#ifndef SHORTCUTS
|
||||
VARDECL(celt_mask, curve);
|
||||
#endif
|
||||
celt_word16 * restrict X, * restrict Y;
|
||||
celt_word16 * restrict Xptr, * restrict Yptr;
|
||||
const celt_sig * restrict yptr;
|
||||
int n2;
|
||||
int L2;
|
||||
const int C = CHANNELS(_C);
|
||||
const int overlap = OVERLAP(m);
|
||||
const int lag = MAX_PERIOD;
|
||||
SAVE_STACK;
|
||||
n2 = lag>>1;
|
||||
L2 = len>>1;
|
||||
ALLOC(_X, lag, celt_word16);
|
||||
X = _X;
|
||||
#ifndef SHORTCUTS
|
||||
ALLOC(curve, n2, celt_mask);
|
||||
#endif
|
||||
CELT_MEMSET(X,0,lag);
|
||||
/* Sum all channels of the current frame and copy into X in bit-reverse order */
|
||||
for (c=0;c<C;c++)
|
||||
{
|
||||
const celt_sig * restrict xptr = &x[c];
|
||||
for (i=0;i<L2;i++)
|
||||
{
|
||||
X[2*BITREV(fft,i)] += SHR32(*xptr,INPUT_SHIFT);
|
||||
xptr += C;
|
||||
X[2*BITREV(fft,i)+1] += SHR32(*xptr,INPUT_SHIFT);
|
||||
xptr += C;
|
||||
}
|
||||
}
|
||||
/* Applying the window in the bit-reverse domain. It's a bit weird, but it
|
||||
can help save memory */
|
||||
wptr = window;
|
||||
for (i=0;i<overlap>>1;i++)
|
||||
{
|
||||
X[2*BITREV(fft,i)] = MULT16_16_Q15(wptr[0], X[2*BITREV(fft,i)]);
|
||||
X[2*BITREV(fft,i)+1] = MULT16_16_Q15(wptr[1], X[2*BITREV(fft,i)+1]);
|
||||
X[2*BITREV(fft,L2-i-1)] = MULT16_16_Q15(wptr[1], X[2*BITREV(fft,L2-i-1)]);
|
||||
X[2*BITREV(fft,L2-i-1)+1] = MULT16_16_Q15(wptr[0], X[2*BITREV(fft,L2-i-1)+1]);
|
||||
wptr += 2;
|
||||
}
|
||||
normalise16(X, lag, 8192);
|
||||
/*for (i=0;i<lag;i++) printf ("%d ", X[i]);printf ("\n");*/
|
||||
/* Forward real FFT (in-place) */
|
||||
real16_fft_inplace(fft, X, lag);
|
||||
|
||||
if (spectrum)
|
||||
{
|
||||
for (i=0;i<lag/4;i++)
|
||||
{
|
||||
spectrum[2*i] = X[4*i];
|
||||
spectrum[2*i+1] = X[4*i+1];
|
||||
}
|
||||
}
|
||||
#ifndef SHORTCUTS
|
||||
compute_masking(decay, X, curve, lag);
|
||||
#endif
|
||||
|
||||
/* Deferred allocation to reduce peak stack usage */
|
||||
ALLOC(_Y, lag, celt_word16);
|
||||
Y = _Y;
|
||||
yptr = &y[0];
|
||||
/* Copy first channel of the past audio into Y in bit-reverse order */
|
||||
for (i=0;i<n2;i++)
|
||||
{
|
||||
Y[2*BITREV(fft,i)] = SHR32(*yptr,INPUT_SHIFT);
|
||||
yptr += C;
|
||||
Y[2*BITREV(fft,i)+1] = SHR32(*yptr,INPUT_SHIFT);
|
||||
yptr += C;
|
||||
}
|
||||
/* Add remaining channels into Y in bit-reverse order */
|
||||
for (c=1;c<C;c++)
|
||||
{
|
||||
yptr = &y[c];
|
||||
for (i=0;i<n2;i++)
|
||||
{
|
||||
Y[2*BITREV(fft,i)] += SHR32(*yptr,INPUT_SHIFT);
|
||||
yptr += C;
|
||||
Y[2*BITREV(fft,i)+1] += SHR32(*yptr,INPUT_SHIFT);
|
||||
yptr += C;
|
||||
}
|
||||
}
|
||||
normalise16(Y, lag, 8192);
|
||||
/* Forward real FFT (in-place) */
|
||||
real16_fft_inplace(fft, Y, lag);
|
||||
|
||||
/* Compute cross-spectrum using the inverse masking curve as weighting */
|
||||
Xptr = &X[2];
|
||||
Yptr = &Y[2];
|
||||
for (i=1;i<n2;i++)
|
||||
{
|
||||
celt_word16 Xr, Xi, n;
|
||||
/* weight = 1/sqrt(curve) */
|
||||
Xr = Xptr[0];
|
||||
Xi = Xptr[1];
|
||||
#ifdef SHORTCUTS
|
||||
/*n = SHR32(32767,(celt_ilog2(EPSILON+curve[i])>>1));*/
|
||||
n = 1+(8192>>(celt_ilog2(1+MULT16_16(Xr,Xr)+MULT16_16(Xi,Xi))>>1));
|
||||
/* Pre-multiply X by n, so we can keep everything in 16 bits */
|
||||
Xr = MULT16_16_16(n, Xr);
|
||||
Xi = MULT16_16_16(n, Xi);
|
||||
#else
|
||||
{
|
||||
celt_word32 t;
|
||||
#ifdef FIXED_POINT
|
||||
int k;
|
||||
#endif
|
||||
t = EPSILON+curve[i];
|
||||
#ifdef FIXED_POINT
|
||||
k = celt_ilog2(t)>>1;
|
||||
#endif
|
||||
t = VSHR32(t, (k-7)<<1);
|
||||
n = celt_rsqrt_norm(t);
|
||||
/* Pre-multiply X by n, so we can keep everything in 16 bits */
|
||||
Xr = EXTRACT16(PSHR32(MULT16_16(n, Xr),3+k));
|
||||
Xi = EXTRACT16(PSHR32(MULT16_16(n, Xi),3+k));
|
||||
}
|
||||
#endif
|
||||
/* Cross-spectrum between X and conj(Y) */
|
||||
*Xptr++ = ADD16(MULT16_16_Q15(Xr, Yptr[0]), MULT16_16_Q15(Xi,Yptr[1]));
|
||||
*Xptr++ = SUB16(MULT16_16_Q15(Xr, Yptr[1]), MULT16_16_Q15(Xi,Yptr[0]));
|
||||
Yptr += 2;
|
||||
}
|
||||
/*printf ("\n");*/
|
||||
X[0] = X[1] = 0;
|
||||
/*for (i=0;i<lag;i++) printf ("%d ", X[i]);printf ("\n");*/
|
||||
normalise16(X, lag, 50);
|
||||
/* Inverse half-complex to real FFT gives us the correlation */
|
||||
real16_ifft(fft, X, Y, lag);
|
||||
|
||||
/* The peak in the correlation gives us the pitch */
|
||||
*pitch = find_max16(Y, max_pitch);
|
||||
/*printf ("%d ", *pitch);*/
|
||||
RESTORE_STACK;
|
||||
}
|
||||
#include "mathops.h"
|
||||
|
||||
void find_best_pitch(celt_word32 *xcorr, celt_word32 maxcorr, celt_word16 *y, int yshift, int len, int max_pitch, int best_pitch[2])
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue