Commit 040db452 authored by jmvalin's avatar jmvalin
Browse files

...


git-svn-id: http://svn.xiph.org/trunk/speex@3814 0101bb08-14d6-0310-b084-bc0e0c8e3800
parent c35f659a
......@@ -22,10 +22,25 @@
#include "speex_bits.h"
#include <stdio.h>
#include <stdlib.h>
#include "misc.h"
void speex_bits_init(SpeexBits *bits)
{
int i;
bits->bytes = speex_alloc(MAX_BYTES_PER_FRAME);
for (i=0;i<MAX_BYTES_PER_FRAME;i++)
bits->bytes[i]=0;
bits->nbBits=0;
bits->bytePtr=0;
bits->bitPtr=0;
}
void speex_bits_init_buffer(SpeexBits *bits, void *buff)
{
int i;
bits->bytes = buff;
for (i=0;i<MAX_BYTES_PER_FRAME;i++)
bits->bytes[i]=0;
bits->nbBits=0;
......@@ -35,6 +50,7 @@ void speex_bits_init(SpeexBits *bits)
void speex_bits_destroy(SpeexBits *bits)
{
speex_free(bits->bytes);
/* Will do something once the allocation is dynamic */
}
......
......@@ -266,9 +266,25 @@ void nb_encode(void *state, float *in, SpeexBits *bits)
syn_filt(st->exc, st->bw_lpc2, st->sw, st->frameSize, st->lpcSize);
/*Open-loop pitch*/
open_loop_nbest_pitch(st->sw, st->min_pitch, st->max_pitch, st->frameSize,
&ol_pitch, &ol_pitch_coef, 1, st->stack);
{
int nol_pitch[4];
float nol_pitch_coef[4];
open_loop_nbest_pitch(st->sw, st->min_pitch, st->max_pitch, st->frameSize,
nol_pitch, nol_pitch_coef, 4, st->stack);
ol_pitch=nol_pitch[0];
ol_pitch_coef = nol_pitch_coef[0];
for (i=1;i<4;i++)
{
if ((nol_pitch_coef[i] > .85*ol_pitch_coef) &&
(fabs(2*nol_pitch[i]-ol_pitch)<=2 || fabs(3*nol_pitch[i]-ol_pitch)<=4 ||
fabs(4*nol_pitch[i]-ol_pitch)<=6 || fabs(5*nol_pitch[i]-ol_pitch)<=8))
{
/*ol_pitch_coef=nol_pitch_coef[i];*/
ol_pitch = nol_pitch[i];
}
}
printf ("ol_pitch: %d %f\n", ol_pitch, ol_pitch_coef);
}
/*Compute "real" excitation*/
residue(st->frame, st->interp_lpc, st->exc, st->frameSize, st->lpcSize);
......@@ -547,7 +563,7 @@ void nb_encode(void *state, float *in, SpeexBits *bits)
ener /= ol_gain;
if (1)
if (0)
printf ("ener: %f %f %f\n", ener, ol_gain, ol_pitch_coef);
if (SUBMODE(have_subframe_gain))
......@@ -923,11 +939,28 @@ void nb_decode(void *state, SpeexBits *bits, float *out, int lost)
/*Fixed codebook contribution*/
SUBMODE(innovation_unquant)(innov, SUBMODE(innovation_params), st->subframeSize, bits, st->stack);
} else {
#if 1
float scale;
scale = 3*sqrt(1.2-ol_pitch_coef);
for (i=0;i<st->subframeSize;i++)
innov[i] = scale*((((float)rand())/RAND_MAX)-.5);
#else
static int tim=0;
float pitch_scale, noise_scale;
float voice=ol_pitch_coef;
if (voice>.9)
voice=.9;
noise_scale = sqrt(1.01-voice);
pitch_scale = sqrt(ol_pitch*voice);
for (i=0;i<st->subframeSize;i++)
innov[i] = 3*noise_scale*((((float)rand())/RAND_MAX)-.5);
while (tim<st->subframeSize)
{
innov[tim] += pitch_scale;
tim+=ol_pitch;
}
tim-=st->subframeSize;
#endif
}
if (st->count_lost)
......
......@@ -30,7 +30,7 @@ extern "C" {
/** Bit-packing data structure representing (part of) a bit-stream. */
typedef struct SpeexBits {
char bytes[MAX_BYTES_PER_FRAME];
char *bytes;
int nbBits;
int bytePtr;
int bitPtr;
......@@ -39,6 +39,9 @@ typedef struct SpeexBits {
/** Initializes and allocates resources for a SpeexBits struct */
void speex_bits_init(SpeexBits *bits);
/** Initializes SpeexBits struct using a pre-allocated buffer*/
void speex_bits_init_buffer(SpeexBits *bits, void *buff);
/** Frees all resources assiociated to a SpeexBits struct. Right now this does nothing since no resources are allocated, but this could change in the future.*/
void speex_bits_destroy(SpeexBits *bits);
......
......@@ -30,6 +30,8 @@ int main(int argc, char **argv)
speex_encoder_ctl(st, SPEEX_SET_VBR, &tmp);
tmp=10;
speex_encoder_ctl(st, SPEEX_SET_QUALITY, &tmp);
tmp=3;
speex_encoder_ctl(st, SPEEX_SET_COMPLEXITY, &tmp);
if (argc != 4 && argc != 3)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment