shithub: opus

Download patch

ref: 0b405d1170122c859faab435405666506d52fa2e
parent: 4305ab6bfbd23dcf83ca40af67ef7542fa63f71a
author: Jean-Marc Valin <[email protected]>
date: Thu Feb 3 20:03:42 EST 2011

Making encoder-side clipping optional

--- a/libcelt/arch.h
+++ b/libcelt/arch.h
@@ -225,7 +225,7 @@
 #define DIV32(a,b)     (((celt_word32)(a))/(celt_word32)(b))
 #define PDIV32(a,b)     (((celt_word32)(a))/(celt_word32)(b))
 
-#define SCALEIN(a)	(MAX16(-2, MIN16(2,a))*CELT_SIG_SCALE)
+#define SCALEIN(a)	((a)*CELT_SIG_SCALE)
 #define SCALEOUT(a)	((a)*(1/CELT_SIG_SCALE))
 
 #endif /* !FIXED_POINT */
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -104,6 +104,7 @@
    int stream_channels;
    
    int force_intra;
+   int clip;
    int disable_pf;
    int complexity;
    int upsample;
@@ -230,6 +231,7 @@
    st->start = 0;
    st->end = st->mode->effEBands;
    st->constrained_vbr = 1;
+   st->clip = 1;
 
    st->bitrate = 255000*channels;
    st->vbr = 0;
@@ -1025,6 +1027,10 @@
             celt_sig x, tmp;
 
             x = SCALEIN(*pcmp);
+#ifndef FIXED_POINT
+            if (st->clip)
+               x = MAX32(-65536.f, MIN32(65536.f,x));
+#endif
             if (++count==st->upsample)
             {
                count=0;
@@ -1755,6 +1761,12 @@
          st->delayedIntra = 1;
          st->spread_decision = SPREAD_NORMAL;
          st->tonal_average = QCONST16(1.f,8);
+      }
+      break;
+      case CELT_SET_INPUT_CLIPPING_REQUEST:
+      {
+         celt_int32 value = va_arg(ap, celt_int32);
+         st->clip = value;
       }
       break;
       default:
--- a/libcelt/celt.h
+++ b/libcelt/celt.h
@@ -105,6 +105,9 @@
 #define CELT_SET_VBR_REQUEST 12
 #define CELT_SET_VBR(x)       CELT_SET_VBR_REQUEST, _celt_check_int(x)
 
+#define CELT_SET_INPUT_CLIPPING_REQUEST    14
+#define CELT_SET_INPUT_CLIPPING(x) CELT_SET_INPUT_CLIPPING_REQUEST, _celt_check_int(x)
+
 #define CELT_SET_START_BAND_REQUEST    10000
 #define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, _celt_check_int(x)