shithub: opus-tools

Download patch

ref: 5ef6b751253691f4278e14ccb40ae8aab0716726
parent: 90c1db18ed80da5949fb69106f4324dce6e4e842
author: Gregory Maxwell <[email protected]>
date: Thu Jul 12 08:43:53 EDT 2012

Remove requirements for lrintf/fminf/fmaxf, avoid alloca.h usage on win32.

--- a/configure.ac
+++ b/configure.ac
@@ -255,6 +255,8 @@
 
 AC_CHECK_FUNCS([lrintf])
 AC_CHECK_FUNCS([lrint])
+AC_CHECK_FUNCS([fminf])
+AC_CHECK_FUNCS([fmaxf])
 AC_CHECK_FUNCS([__malloc_hook])
 
 AC_CHECK_SIZEOF(short)
--- a/src/opusdec.c
+++ b/src/opusdec.c
@@ -57,6 +57,12 @@
 #endif
 #include <math.h>
 
+#ifdef HAVE_LRINTF
+# define float2int(x) lrintf(x)
+#else
+# define float2int(flt) ((int)(floor(.5+flt)))
+#endif
+
 #ifdef _WIN32
 #define I64FORMAT "I64d"
 #else
@@ -120,6 +126,14 @@
   return rngseed;
 }
 
+#ifndef HAVE_FMINF
+# define fminf(_x,_y) ((_x)<(_y)?(_x):(_y))
+#endif
+
+#ifndef HAVE_FMAXF
+# define fmaxf(_x,_y) ((_x)>(_y)?(_x):(_y))
+#endif
+
 /* This implements a 16 bit quantization with full triangular dither
    and IIR noise shaping. The noise shaping filters were designed by
    Sebastian Gesemann based on the LAME ATH curves with flattening
@@ -179,7 +193,7 @@
       if (mute>16)r=0;
       /*Clamp in float out of paranoia that the input will be >96dBFS and wrap if the
         integer is clamped.*/
-      _o[pos+c] = si = lrintf(fmaxf(-32768,fminf(s + r,32767)));
+      _o[pos+c] = si = float2int(fmaxf(-32768,fminf(s + r,32767)));
       /*Including clipping in the noise shaping is generally disastrous:
         the futile effort to restore the clipped energy results in more clipping.
         However, small amounts-- at the level which could normally be created by
@@ -521,7 +535,7 @@
        shape_dither_toshort(shapemem,out,output,out_len,channels);
      }else{
        for (i=0;i<(int)out_len*channels;i++)
-         out[i]=(short)lrintf(fmax(-32768,fmin(output[i]*32768.f,32767)));
+         out[i]=(short)float2int(fmaxf(-32768,fminf(output[i]*32768.f,32767)));
      }
      if ((le_short(1)!=1)&&file){
        for (i=0;i<(int)out_len*channels;i++)
--- a/src/stack_alloc.h
+++ b/src/stack_alloc.h
@@ -35,17 +35,13 @@
 #ifndef STACK_ALLOC_H
 #define STACK_ALLOC_H
 
-#include <alloca.h>
-
-#ifdef USE_ALLOCA
-# ifdef WIN32
-#  include <malloc.h>
+#ifdef WIN32
+# include <malloc.h>
+#else
+#ifdef HAVE_ALLOCA_H
+#  include <alloca.h>
 # else
-#  ifdef HAVE_ALLOCA_H
-#   include <alloca.h>
-#  else
-#   include <stdlib.h>
-#  endif
+#  include <stdlib.h>
 # endif
 #endif