[xiph-cvs] cvs commit: speex/libspeex nb_celp.c nb_celp.h sb_celp.c sb_celp.h
Jean-Marc Valin
jm at xiph.org
Sat Dec 14 22:45:43 PST 2002
jm 02/12/15 01:45:43
Modified: libspeex nb_celp.c nb_celp.h sb_celp.c sb_celp.h
Log:
ABR seems to work for wideband too...
Revision Changes Path
1.96 +0 -1 speex/libspeex/nb_celp.c
Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -r1.95 -r1.96
--- nb_celp.c 15 Dec 2002 06:01:45 -0000 1.95
+++ nb_celp.c 15 Dec 2002 06:45:43 -0000 1.96
@@ -1479,7 +1479,6 @@
vbr_qual=i;
if (vbr_qual<0)
vbr_qual=0;
- fprintf (stderr, "%f\n", vbr_qual);
speex_encoder_ctl(st, SPEEX_SET_VBR_QUALITY, &vbr_qual);
st->abr_count=0;
st->abr_drift=0;
<p><p>1.41 +1 -1 speex/libspeex/nb_celp.h
Index: nb_celp.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.h,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- nb_celp.h 15 Dec 2002 06:01:45 -0000 1.40
+++ nb_celp.h 15 Dec 2002 06:45:43 -0000 1.41
@@ -103,7 +103,7 @@
float relative_quality; /**< Relative quality that will be needed by VBR */
int vbr_enabled; /**< 1 for enabling VBR, 0 otherwise */
int vad_enabled; /**< 1 for enabling VAD, 0 otherwise */
- int abr_enabled; /**< 1 for enabling ABR, 0 otherwise */
+ int abr_enabled; /**< ABR setting (in bps), 0 if off */
float abr_drift;
float abr_drift2;
float abr_count;
<p><p>1.103 +60 -0 speex/libspeex/sb_celp.c
Index: sb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.c,v
retrieving revision 1.102
retrieving revision 1.103
diff -u -r1.102 -r1.103
--- sb_celp.c 13 Dec 2002 22:59:27 -0000 1.102
+++ sb_celp.c 15 Dec 2002 06:45:43 -0000 1.103
@@ -221,6 +221,7 @@
st->vbr_quality = 8;
st->vbr_enabled = 0;
st->vad_enabled = 0;
+ st->abr_enabled = 0;
st->relative_quality=0;
st->complexity=2;
@@ -353,6 +354,27 @@
if (st->vbr_enabled || st->vad_enabled){
float e_low=0, e_high=0;
float ratio;
+ if (st->abr_enabled)
+ {
+ float qual_change=0;
+ if (st->abr_drift2 * st->abr_drift > 0)
+ {
+ /* Only adapt if long-term and short-term drift are the same sign */
+ qual_change = -.00001*st->abr_drift/(1+st->abr_count);
+ if (qual_change>.1)
+ qual_change=.1;
+ if (qual_change<-.1)
+ qual_change=-.1;
+ }
+ st->vbr_quality += qual_change;
+ if (st->vbr_quality>10)
+ st->vbr_quality=10;
+ if (st->vbr_quality<0)
+ st->vbr_quality=0;
+ /*printf ("%f %f\n", st->abr_drift, st->vbr_quality);*/
+ }
+
+
for (i=0;i<st->frame_size;i++)
{
e_low += st->x0d[i]* st->x0d[i];
@@ -387,6 +409,15 @@
/*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);*/
+ if (st->abr_enabled)
+ {
+ int bitrate;
+ speex_encoder_ctl(state, SPEEX_GET_BITRATE, &bitrate);
+ st->abr_drift+=(bitrate-st->abr_enabled);
+ st->abr_drift2 = .95*st->abr_drift2 + .05*(bitrate-st->abr_enabled);
+ st->abr_count += 1.0;
+ }
+
} else {
/* VAD only */
int modeid;
@@ -1107,6 +1138,35 @@
speex_encoder_ctl(state, SPEEX_SET_QUALITY, &q);
break;
}
+ case SPEEX_SET_ABR:
+ st->abr_enabled = (*(int*)ptr);
+ st->vbr_enabled = 1;
+ speex_encoder_ctl(st->st_low, SPEEX_SET_VBR, &st->vbr_enabled);
+ {
+ int i=10, rate, target;
+ float vbr_qual;
+ target = (*(int*)ptr);
+ while (i>=0)
+ {
+ speex_encoder_ctl(st, SPEEX_SET_QUALITY, &i);
+ speex_encoder_ctl(st, SPEEX_GET_BITRATE, &rate);
+ if (rate <= target)
+ break;
+ i--;
+ }
+ vbr_qual=i;
+ if (vbr_qual<0)
+ vbr_qual=0;
+ speex_encoder_ctl(st, SPEEX_SET_VBR_QUALITY, &vbr_qual);
+ st->abr_count=0;
+ st->abr_drift=0;
+ st->abr_drift2=0;
+ }
+
+ break;
+ case SPEEX_GET_ABR:
+ (*(int*)ptr) = st->abr_enabled;
+ break;
case SPEEX_SET_QUALITY:
{
int nb_qual;
<p><p>1.35 +4 -0 speex/libspeex/sb_celp.h
Index: sb_celp.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- sb_celp.h 13 Dec 2002 01:47:24 -0000 1.34
+++ sb_celp.h 15 Dec 2002 06:45:43 -0000 1.35
@@ -92,6 +92,10 @@
float vbr_quality; /**< Quality setting for VBR encoding */
int vbr_enabled; /**< 1 for enabling VBR, 0 otherwise */
+ int abr_enabled; /**< ABR setting (in bps), 0 if off */
+ float abr_drift;
+ float abr_drift2;
+ float abr_count;
int vad_enabled; /**< 1 for enabling VAD, 0 otherwise */
float relative_quality;
<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