Commit 1fa8654c authored by jmvalin's avatar jmvalin
Browse files

New very high quality modes for narrowband and wideband by using a double

codebook


git-svn-id: http://svn.xiph.org/trunk/speex@3859 0101bb08-14d6-0310-b084-bc0e0c8e3800
parent 601fff37
......@@ -189,6 +189,29 @@ unsigned int speex_bits_unpack_unsigned(SpeexBits *bits, int nbBits)
return d;
}
unsigned int speex_bits_peek_unsigned(SpeexBits *bits, int nbBits)
{
unsigned int d=0;
int bitPtr, bytePtr;
char *bytes;
bitPtr=bits->bitPtr;
bytePtr=bits->bytePtr;
bytes = bits->bytes;
while(nbBits)
{
d<<=1;
d |= (bytes[bytePtr]>>(7-bitPtr))&1;
bitPtr++;
if (bitPtr==8)
{
bitPtr=0;
bytePtr++;
}
nbBits--;
}
return d;
}
int speex_bits_peek(SpeexBits *bits)
{
return (bits->bytes[bits->bytePtr]>>(7-bits->bitPtr))&1;
......
......@@ -369,6 +369,7 @@ int lost)
gain[2] = gain_cdbk[gain_index*12+2];
if (lost)
{
#if 0
float gain_sum;
/*Put everything in one tap*/
gain[1]+=gain[0]+gain[2];
......@@ -381,6 +382,16 @@ int lost)
gain[i]*=fact;
}
/*gain[1]=.8;*/
#else
float gain_sum;
gain_sum = fabs(gain[0])+fabs(gain[1])+fabs(gain[2]);
if (gain_sum>.85)
{
float fact = .85/gain_sum;
for (i=0;i<3;i++)
gain[i]*=fact;
}
#endif
}
*pitch_val = pitch;
......
......@@ -127,11 +127,12 @@ static split_cb_params split_cb_high_lbr = {
5, /*shape_bits*/
};
/* 2150 bps "vocoder-like" mode for comfort noise */
static SpeexSubmode nb_submode1 = {
0,
1,
1,
0,
/* LSP quantization */
lsp_quant_lbr,
lsp_unquant_lbr,
......@@ -147,10 +148,12 @@ static SpeexSubmode nb_submode1 = {
43
};
/* 5.95 kbps very low bit-rate mode */
static SpeexSubmode nb_submode2 = {
0,
0,
0,
0,
/*LSP quantization*/
lsp_quant_lbr,
lsp_unquant_lbr,
......@@ -167,11 +170,12 @@ static SpeexSubmode nb_submode2 = {
119
};
/* 8 kbps low bit-rate mode */
static SpeexSubmode nb_submode3 = {
-1,
0,
1,
0,
/*LSP quantization*/
lsp_quant_lbr,
lsp_unquant_lbr,
......@@ -188,10 +192,12 @@ static SpeexSubmode nb_submode3 = {
160
};
/* 11 kbps medium bit-rate mode */
static SpeexSubmode nb_submode4 = {
-1,
0,
1,
0,
/*LSP quantization*/
lsp_quant_lbr,
lsp_unquant_lbr,
......@@ -208,10 +214,12 @@ static SpeexSubmode nb_submode4 = {
220
};
/* 15 kbps high bit-rate mode */
static SpeexSubmode nb_submode5 = {
-1,
0,
3,
0,
/*LSP quantization*/
lsp_quant_nb,
lsp_unquant_nb,
......@@ -228,10 +236,12 @@ static SpeexSubmode nb_submode5 = {
300
};
/* 18.2 high bit-rate mode */
static SpeexSubmode nb_submode6 = {
-1,
0,
3,
0,
/*LSP quantization*/
lsp_quant_nb,
lsp_unquant_nb,
......@@ -248,6 +258,28 @@ static SpeexSubmode nb_submode6 = {
364
};
/* 24.6 kbps high bit-rate mode */
static SpeexSubmode nb_submode7 = {
-1,
0,
3,
1,
/*LSP quantization*/
lsp_quant_nb,
lsp_unquant_nb,
/*Pitch quantization*/
pitch_search_3tap,
pitch_unquant_3tap,
&ltp_params_nb,
/*Innovation quantization*/
split_cb_search_nogain,
split_cb_nogain_unquant,
&split_cb_nb,
0.65, 0.65, 0,
492
};
/* Default mode for narrowband */
static SpeexNBMode nb_mode = {
......@@ -262,7 +294,7 @@ static SpeexNBMode nb_mode = {
.005, /*lag_factor*/
1.0001, /*lpc_floor*/
0.0, /*preemph*/
{NULL, &nb_submode1, &nb_submode2, &nb_submode3, &nb_submode4, &nb_submode5, &nb_submode6, NULL,
{NULL, &nb_submode1, &nb_submode2, &nb_submode3, &nb_submode4, &nb_submode5, &nb_submode6, &nb_submode7,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
5
};
......@@ -290,6 +322,7 @@ static SpeexSubmode wb_submode1 = {
0,
0,
1,
0,
/*LSP quantization*/
lsp_quant_high,
lsp_unquant_high,
......@@ -311,6 +344,7 @@ static SpeexSubmode wb_submode2 = {
0,
0,
1,
0,
/*LSP quantization*/
lsp_quant_high,
lsp_unquant_high,
......@@ -332,6 +366,7 @@ static SpeexSubmode wb_submode3 = {
0,
0,
1,
0,
/*LSP quantization*/
lsp_quant_high,
lsp_unquant_high,
......@@ -348,6 +383,27 @@ static SpeexSubmode wb_submode3 = {
192
};
static SpeexSubmode wb_submode4 = {
0,
0,
1,
1,
/*LSP quantization*/
lsp_quant_high,
lsp_unquant_high,
/*Pitch quantization*/
NULL,
NULL,
NULL,
/*Innovation quantization*/
split_cb_search_shape_sign,
split_cb_shape_sign_unquant,
&split_cb_high,
0, 0, -1,
352
};
/* Split-band wideband CELP mode*/
SpeexSBMode sb_wb_mode = {
......@@ -361,7 +417,7 @@ SpeexSBMode sb_wb_mode = {
.002, /*lag_factor*/
1.0001, /*lpc_floor*/
0.0, /*preemph*/
{NULL, &wb_submode1, &wb_submode2, &wb_submode3, NULL, NULL, NULL, NULL},
{NULL, &wb_submode1, &wb_submode2, &wb_submode3, &wb_submode4, NULL, NULL, NULL},
3
};
......
......@@ -59,6 +59,7 @@ typedef struct SpeexSubmode {
int lbr_pitch;
int forced_pitch_gain;
int have_subframe_gain;
int double_codebook;
/*LSP functions*/
lsp_quant_func lsp_quant;
lsp_unquant_func lsp_unquant;
......
......@@ -622,6 +622,23 @@ void nb_encode(void *state, float *in, SpeexBits *bits)
} else {
fprintf(stderr, "No fixed codebook\n");
}
if (SUBMODE(double_codebook)) {
float *innov2 = PUSH(st->stack, st->subframeSize);
for (i=0;i<st->subframeSize;i++)
innov2[i]=0;
for (i=0;i<st->subframeSize;i++)
target[i]*=2.2;
SUBMODE(innovation_quant)(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,
SUBMODE(innovation_params), st->lpcSize, st->subframeSize,
innov2, bits, st->stack, st->complexity);
for (i=0;i<st->subframeSize;i++)
innov2[i]*=ener*(1/2.2);
for (i=0;i<st->subframeSize;i++)
exc[i] += innov2[i];
POP(st->stack);
}
/*POP(st->stack);*/
for (i=0;i<st->subframeSize;i++)
target[i]*=ener;
......@@ -979,6 +996,19 @@ void nb_decode(void *state, SpeexBits *bits, float *out, int lost)
for (i=0;i<st->subframeSize;i++)
exc[i]+=innov[i];
if (SUBMODE(double_codebook))
{
float *innov2 = PUSH(st->stack, st->subframeSize);
for (i=0;i<st->subframeSize;i++)
innov2[i]=0;
SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, bits, st->stack);
for (i=0;i<st->subframeSize;i++)
innov2[i]*=ener*(1/2.2);
for (i=0;i<st->subframeSize;i++)
exc[i] += innov2[i];
POP(st->stack);
}
/*POP(st->stack);*/
}
......@@ -1063,8 +1093,10 @@ void nb_encoder_ctl(void *state, int request, void *ptr)
st->submodeID = 4;
else if (quality<=8)
st->submodeID = 5;
else if (quality<=10)
else if (quality<=9)
st->submodeID = 6;
else if (quality<=10)
st->submodeID = 7;
else
fprintf(stderr, "Unknown nb_ctl quality: %d\n", quality);
}
......
......@@ -41,7 +41,6 @@
#define SUBMODE(x) st->submodes[st->submodeID]->x
#define QMF_ORDER 64
static float h0[64] = {
3.596189e-05, -0.0001123515,
......@@ -263,12 +262,14 @@ void sb_encode(void *state, float *in, SpeexBits *bits)
/* Compute the two sub-bands by filtering with h0 and h1*/
fir_mem(in, h0, st->x0, st->full_frame_size, QMF_ORDER, st->h0_mem);
fir_mem(in, h1, st->x1, st->full_frame_size, QMF_ORDER, st->h1_mem);
/* Down-sample x0 and x1 */
for (i=0;i<st->frame_size;i++)
{
st->x0d[i]=st->x0[i<<1];
st->x1d[i]=st->x1[i<<1];
}
for (i=0;i<st->frame_size;i++)
st->x0d[i]=st->x0[i<<1];
/* Encode the narrowband part*/
nb_encode(st->st_low, st->x0d, bits);
......@@ -276,19 +277,10 @@ void sb_encode(void *state, float *in, SpeexBits *bits)
speex_bits_pack(bits, st->submodeID, SB_SUBMODE_BITS);
/* High-band buffering / sync with low band */
#if 0
for (i=0;i<st->frame_size;i++)
{
/*st->excBuf[i]=st->exc[i];*/
st->high[i]=st->high[st->frame_size+i];
st->high[st->frame_size+i]=st->x1d[i];
}
#else
for (i=0;i<st->windowSize-st->frame_size;i++)
st->high[i] = st->high[st->frame_size+i];
for (i=0;i<st->frame_size;i++)
st->high[st->windowSize-st->frame_size+i]=st->x1d[i];
#endif
speex_move(st->excBuf, st->excBuf+st->frame_size, (st->bufSize-st->frame_size)*sizeof(float));
......@@ -546,6 +538,23 @@ void sb_encode(void *state, float *in, SpeexBits *bits)
for (i=0;i<st->subframeSize;i++)
exc[i] += innov[i]*scale;
if (SUBMODE(double_codebook)) {
float *innov2 = PUSH(st->stack, st->subframeSize);
for (i=0;i<st->subframeSize;i++)
innov2[i]=0;
for (i=0;i<st->subframeSize;i++)
target[i]*=2.5;
SUBMODE(innovation_quant)(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,
SUBMODE(innovation_params), st->lpcSize, st->subframeSize,
innov2, bits, st->stack, st->complexity);
for (i=0;i<st->subframeSize;i++)
innov2[i]*=scale*(1/2.5);
for (i=0;i<st->subframeSize;i++)
exc[i] += innov2[i];
POP(st->stack);
}
if (0) {
float en=0;
for (i=0;i<st->subframeSize;i++)
......@@ -644,7 +653,6 @@ void *sb_decoder_init(SpeexMode *m)
st->interp_qlpc = speex_alloc((st->lpcSize+1)*sizeof(float));
st->mem_sp = speex_alloc(st->lpcSize*sizeof(float));
return st;
}
......@@ -816,6 +824,20 @@ void sb_decode(void *state, SpeexBits *bits, float *out, int lost)
bits, st->stack);
for (i=0;i<st->subframeSize;i++)
exc[i]*=scale;
if (SUBMODE(double_codebook)) {
float *innov2 = PUSH(st->stack, st->subframeSize);
for (i=0;i<st->subframeSize;i++)
innov2[i]=0;
SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize,
bits, st->stack);
for (i=0;i<st->subframeSize;i++)
innov2[i]*=scale*(1/2.5);
for (i=0;i<st->subframeSize;i++)
exc[i] += innov2[i];
POP(st->stack);
}
}
syn_filt_mem(exc, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, st->mem_sp);
......@@ -835,7 +857,6 @@ void sb_decode(void *state, SpeexBits *bits, float *out, int lost)
for (i=0;i<st->full_frame_size;i++)
out[i]=2*(st->y0[i]-st->y1[i]);
for (i=0;i<st->lpcSize;i++)
st->old_qlsp[i] = st->qlsp[i];
......@@ -910,11 +931,17 @@ void sb_encoder_ctl(void *state, int request, void *ptr)
st->submodeID = 2;
break;
case 8:
case 9:
case 10:
nb_mode=6;
st->submodeID = 3;
break;
case 9:
nb_mode=7;
st->submodeID = 3;
break;
case 10:
nb_mode=7;
st->submodeID = 4;
break;
default:
fprintf(stderr, "Unknown sb_ctl quality: %d\n", quality);
}
......
......@@ -70,9 +70,11 @@ unsigned int speex_bits_unpack_unsigned(SpeexBits *bits, int nbBits);
int speex_bits_nbytes(SpeexBits *bits);
unsigned int speex_bits_peek_unsigned(SpeexBits *bits, int nbBits);
int speex_bits_peek(SpeexBits *bits);
void speex_bits_advance(SpeexBits *bits, int n);
void speex_bits_advance(SpeexBits *bits, int n);
#ifdef __cplusplus
}
......
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