[xiph-cvs] cvs commit: speex/libspeex modes.c modes.h sb_celp.c sb_celp.h vbr.c vbr.h
Jean-Marc Valin
jm at xiph.org
Fri Nov 29 21:24:41 PST 2002
jm 02/11/30 00:24:41
Modified: libspeex modes.c modes.h sb_celp.c sb_celp.h vbr.c vbr.h
Log:
Ultra-wideband VBR seems to work. Also, fixed a bug for wideband VBR.
Revision Changes Path
1.89 +7 -2 speex/libspeex/modes.c
Index: modes.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/modes.c,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -r1.88 -r1.89
--- modes.c 14 Nov 2002 04:49:14 -0000 1.88
+++ modes.c 30 Nov 2002 05:24:41 -0000 1.89
@@ -40,6 +40,7 @@
#include "cb_search.h"
#include "sb_celp.h"
#include "nb_celp.h"
+#include "vbr.h"
SpeexMode *speex_mode_list[SPEEX_NB_MODES] = {&speex_nb_mode, &speex_wb_mode, &speex_uwb_mode};
@@ -446,7 +447,9 @@
{NULL, &wb_submode1, &wb_submode2, &wb_submode3, &wb_submode4, NULL, NULL, NULL},
3,
{0, 1, 2, 3, 4, 5, 5, 6, 6, 7, 7},
- {0, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4}
+ {0, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4},
+ vbr_hb_thresh,
+ 5
};
@@ -487,7 +490,9 @@
{NULL, &wb_submode1, NULL, NULL, NULL, NULL, NULL, NULL},
1,
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
- {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
+ {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+ vbr_uhb_thresh,
+ 2
};
<p><p>1.40 +2 -1 speex/libspeex/modes.h
Index: modes.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/modes.h,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- modes.h 28 Nov 2002 06:32:50 -0000 1.39
+++ modes.h 30 Nov 2002 05:24:41 -0000 1.40
@@ -137,7 +137,8 @@
int defaultSubmode; /**< Default sub-mode to use when encoding */
int low_quality_map[11]; /**< Mode corresponding to each quality setting */
int quality_map[11]; /**< Mode corresponding to each quality setting */
-
+ float (*vbr_thresh)[11];
+ int nb_modes;
} SpeexSBMode;
<p><p>1.98 +20 -24 speex/libspeex/sb_celp.c
Index: sb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.c,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -r1.97 -r1.98
--- sb_celp.c 27 Nov 2002 20:36:41 -0000 1.97
+++ sb_celp.c 30 Nov 2002 05:24:41 -0000 1.98
@@ -220,6 +220,7 @@
st->vbr_quality = 8;
st->vbr_enabled = 0;
+ st->relative_quality=0;
st->complexity=2;
speex_decoder_ctl(st->st_low, SPEEX_GET_SAMPLING_RATE, &st->sampling_rate);
@@ -282,9 +283,11 @@
void *stack;
float *mem, *innov, *syn_resp;
float *low_pi_gain, *low_exc, *low_innov;
+ SpeexSBMode *mode;
st = (SBEncState*)state;
stack=st->stack;
+ mode = (SpeexSBMode*)(st->mode->mode);
/* Compute the two sub-bands by filtering with h0 and h1*/
qmf_decomp(in, h0, st->x0d, st->x1d, st->full_frame_size, QMF_ORDER, st->h0_mem, stack);
@@ -349,49 +352,39 @@
if (st->vbr_enabled){
float e_low=0, e_high=0;
float ratio;
- float low_qual;
for (i=0;i<st->frame_size;i++)
{
e_low += st->x0d[i]* st->x0d[i];
e_high += st->high[i]* st->high[i];
}
ratio = log((1+e_high)/(1+e_low));
- speex_encoder_ctl(st->st_low, SPEEX_GET_RELATIVE_QUALITY, &low_qual);
+ speex_encoder_ctl(st->st_low, SPEEX_GET_RELATIVE_QUALITY, &st->relative_quality);
if (ratio<-4)
ratio=-4;
if (ratio>2)
ratio=2;
/*if (ratio>-2)*/
- low_qual+=1.0*(ratio+2);
- /*{
- int high_mode=2;
- if (low_qual>10)
- high_mode=4;
- else if (low_qual>7.5)
- high_mode=3;
- else if (low_qual>5)
- high_mode=2;
- speex_encoder_ctl(st, SPEEX_SET_HIGH_MODE, &high_mode);
- }*/
- {
- int mode;
- mode = 4;
- while (mode)
+ st->relative_quality+=1.0*(ratio+2);
+ {
+ int modeid;
+ modeid = mode->nb_modes-1;
+ while (modeid)
{
int v1;
float thresh;
v1=(int)floor(st->vbr_quality);
if (v1==10)
- thresh = vbr_nb_thresh[mode][v1];
+ thresh = mode->vbr_thresh[modeid][v1];
else
- thresh = (st->vbr_quality-v1)*vbr_hb_thresh[mode][v1+1] + (1+v1-st->vbr_quality)*vbr_hb_thresh[mode][v1];
- if (low_qual > thresh)
+ thresh = (st->vbr_quality-v1) * mode->vbr_thresh[modeid][v1+1] +
+ (1+v1-st->vbr_quality) * mode->vbr_thresh[modeid][v1];
+ if (st->relative_quality > thresh)
break;
- mode--;
+ modeid--;
}
- /*fprintf (stderr, "%f %d\n", low_qual, mode);*/
- speex_encoder_ctl(state, SPEEX_SET_HIGH_MODE, &mode);
- /*fprintf (stderr, "%d %d\n", st->submodeID, mode);*/
+ /*fprintf (stderr, "%f %d\n", low_qual, modeid);*/
+ speex_encoder_ctl(state, SPEEX_SET_HIGH_MODE, &modeid);
+ /*fprintf (stderr, "%d %d\n", st->submodeID, modeid);*/
}
/*fprintf (stderr, "%f %f\n", ratio, low_qual);*/
}
@@ -1086,6 +1079,9 @@
for (i=0;i<st->frame_size;i++)
e[2*i]=2*st->exc[i];
}
+ break;
+ case SPEEX_GET_RELATIVE_QUALITY:
+ (*(float*)ptr)=st->relative_quality;
break;
default:
fprintf(stderr, "Unknown nb_ctl request: %d\n", request);
<p><p>1.32 +1 -0 speex/libspeex/sb_celp.h
Index: sb_celp.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- sb_celp.h 15 Nov 2002 06:26:50 -0000 1.31
+++ sb_celp.h 30 Nov 2002 05:24:41 -0000 1.32
@@ -92,6 +92,7 @@
float vbr_quality; /**< Quality setting for VBR encoding */
int vbr_enabled; /**< 1 for enabling VBR, 0 otherwise */
+ float relative_quality;
SpeexSubmode **submodes;
int submodeID;
<p><p>1.13 +7 -2 speex/libspeex/vbr.c
Index: vbr.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/vbr.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- vbr.c 27 Nov 2002 02:54:34 -0000 1.12
+++ vbr.c 30 Nov 2002 05:24:41 -0000 1.13
@@ -60,9 +60,14 @@
float vbr_hb_thresh[5][11]={
{-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}, /* silence */
{ 3.9, 2.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0}, /* 2 kbps */
- {11.0, 11.0, 9.9, 9.0, 8.0, 7.0, 6.5, 6.0, 5.0, 4.0, 2.0}, /* 6 kbps */
- {11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 9.5, 8.5, 8.0, 6.5, 4.0}, /* 10 kbps */
+ {11.0, 11.0, 9.5, 8.5, 7.5, 6.5, 6.0, 5.0, 4.0, 3.0, 1.0}, /* 6 kbps */
+ {11.0, 11.0, 11.0, 11.0, 11.0, 9.5, 8.7, 8.0, 7.0, 6.5, 4.0}, /* 10 kbps */
{11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 9.8, 7.5, 5.5} /* 18 kbps */
+};
+
+float vbr_uhb_thresh[2][11]={
+ {-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}, /* silence */
+ { 3.9, 2.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0} /* 2 kbps */
};
void vbr_init(VBRState *vbr)
<p><p>1.9 +1 -0 speex/libspeex/vbr.h
Index: vbr.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/vbr.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- vbr.h 27 Nov 2002 02:54:34 -0000 1.8
+++ vbr.h 30 Nov 2002 05:24:41 -0000 1.9
@@ -40,6 +40,7 @@
extern float vbr_nb_thresh[8][11];
extern float vbr_hb_thresh[5][11];
+extern float vbr_uhb_thresh[2][11];
typedef struct VBRState {
float energy_alpha;
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list