diff --git a/build_tools/menuselect-deps.in b/build_tools/menuselect-deps.in
index f724fe3aee1796147757616f36591efe93656389..aa76d56100efd8b60075ecc630d0754b3906758d 100644
--- a/build_tools/menuselect-deps.in
+++ b/build_tools/menuselect-deps.in
@@ -32,6 +32,7 @@ PRI=@PBX_PRI@
 RADIUS=@PBX_RADIUS@
 SPEEX=@PBX_SPEEX@
 SPEEXDSP=@PBX_SPEEXDSP@
+SPEEX_PREPROCESS=@PBX_SPEEX_PREPROCESS@
 SQLITE3=@PBX_SQLITE3@
 SQLITE=@PBX_SQLITE@
 SS7=@PBX_SS7@
diff --git a/codecs/codec_speex.c b/codecs/codec_speex.c
index 035f9958bf6b38b6db162aeae4995082994ee2b4..49469318287b69a45758fa5d6ba9ecf7ba6f93ae 100644
--- a/codecs/codec_speex.c
+++ b/codecs/codec_speex.c
@@ -32,6 +32,7 @@
 
 /*** MODULEINFO
 	<depend>speex</depend>
+	<depend>speex_preprocess</depend>
 	<use>speexdsp</use>
  ***/
 
diff --git a/configure b/configure
index 2627f05c5bad1c67ff76159c1749abc5fcd52efc..d0478dcd3216087a7959069491ec9187d73020fa 100755
--- a/configure
+++ b/configure
@@ -963,6 +963,7 @@ OPENH323_INCDIR
 OPENH323_LIBDIR
 OPENH323_SUFFIX
 OPENH323_BUILD
+PBX_SPEEX_PREPROCESS
 CONFIG_GMIME
 PBX_ZAPTEL_VLDTMF
 PBX_ZAPTEL_ECHOCANPARAMS
@@ -41742,6 +41743,272 @@ _ACEOF
 fi
 
 
+# See if the main speex library contains the preprocess functions
+
+if test "x${PBX_SPEEX_PREPROCESS}" != "x1" -a "${USE_SPEEX_PREPROCESS}" != "no"; then
+   pbxlibdir=""
+   # if --with-SPEEX_PREPROCESS=DIR has been specified, use it.
+   if test "x${SPEEX_PREPROCESS_DIR}" != "x"; then
+      if test -d ${SPEEX_PREPROCESS_DIR}/lib; then
+      	 pbxlibdir="-L${SPEEX_PREPROCESS_DIR}/lib"
+      else
+      	 pbxlibdir="-L${SPEEX_PREPROCESS_DIR}"
+      fi
+   fi
+   pbxfuncname="speex/speex.h"
+   if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
+      AST_SPEEX_PREPROCESS_FOUND=yes
+   else
+      as_ac_Lib=`echo "ac_cv_lib_speex_preprocess_ctl_${pbxfuncname}" | $as_tr_sh`
+{ echo "$as_me:$LINENO: checking for ${pbxfuncname} in -lspeex_preprocess_ctl" >&5
+echo $ECHO_N "checking for ${pbxfuncname} in -lspeex_preprocess_ctl... $ECHO_C" >&6; }
+if { as_var=$as_ac_Lib; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lspeex_preprocess_ctl ${pbxlibdir}  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ${pbxfuncname} ();
+int
+main ()
+{
+return ${pbxfuncname} ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  eval "$as_ac_Lib=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	eval "$as_ac_Lib=no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+ac_res=`eval echo '${'$as_ac_Lib'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+if test `eval echo '${'$as_ac_Lib'}'` = yes; then
+  AST_SPEEX_PREPROCESS_FOUND=yes
+else
+  AST_SPEEX_PREPROCESS_FOUND=no
+fi
+
+   fi
+
+   # now check for the header.
+   if test "${AST_SPEEX_PREPROCESS_FOUND}" = "yes"; then
+      SPEEX_PREPROCESS_LIB="${pbxlibdir} -lspeex_preprocess_ctl "
+      # if --with-SPEEX_PREPROCESS=DIR has been specified, use it.
+      if test "x${SPEEX_PREPROCESS_DIR}" != "x"; then
+	 SPEEX_PREPROCESS_INCLUDE="-I${SPEEX_PREPROCESS_DIR}/include"
+      fi
+      SPEEX_PREPROCESS_INCLUDE="${SPEEX_PREPROCESS_INCLUDE} "
+      if test "x-lm" = "x" ; then	# no header, assume found
+         SPEEX_PREPROCESS_HEADER_FOUND="1"
+      else				# check for the header
+         saved_cppflags="${CPPFLAGS}"
+         CPPFLAGS="${CPPFLAGS} ${SPEEX_PREPROCESS_INCLUDE} "
+	 if test "${ac_cv_header__lm+set}" = set; then
+  { echo "$as_me:$LINENO: checking for -lm" >&5
+echo $ECHO_N "checking for -lm... $ECHO_C" >&6; }
+if test "${ac_cv_header__lm+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_header__lm" >&5
+echo "${ECHO_T}$ac_cv_header__lm" >&6; }
+else
+  # Is the header compilable?
+{ echo "$as_me:$LINENO: checking -lm usability" >&5
+echo $ECHO_N "checking -lm usability... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <-lm>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_header_compiler=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ echo "$as_me:$LINENO: checking -lm presence" >&5
+echo $ECHO_N "checking -lm presence... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <-lm>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+
+rm -f conftest.err conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: -lm: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: -lm: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: -lm: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: -lm: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: -lm: present but cannot be compiled" >&5
+echo "$as_me: WARNING: -lm: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: -lm:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: -lm:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: -lm: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: -lm: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: -lm:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: -lm:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: -lm: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: -lm: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: -lm: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: -lm: in the future, the compiler will take precedence" >&2;}
+    ( cat <<\_ASBOX
+## ------------------------------- ##
+## Report this to www.asterisk.org ##
+## ------------------------------- ##
+_ASBOX
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+{ echo "$as_me:$LINENO: checking for -lm" >&5
+echo $ECHO_N "checking for -lm... $ECHO_C" >&6; }
+if test "${ac_cv_header__lm+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_header__lm=$ac_header_preproc
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_header__lm" >&5
+echo "${ECHO_T}$ac_cv_header__lm" >&6; }
+
+fi
+if test $ac_cv_header__lm = yes; then
+  SPEEX_PREPROCESS_HEADER_FOUND=1
+else
+  SPEEX_PREPROCESS_HEADER_FOUND=0
+fi
+
+
+         CPPFLAGS="${saved_cppflags}"
+      fi
+      if test "x${SPEEX_PREPROCESS_HEADER_FOUND}" = "x0" ; then
+         SPEEX_PREPROCESS_LIB=""
+         SPEEX_PREPROCESS_INCLUDE=""
+      else
+         if test "x${pbxfuncname}" = "x" ; then		# only checking headers -> no library
+	    SPEEX_PREPROCESS_LIB=""
+	 fi
+         PBX_SPEEX_PREPROCESS=1
+         # XXX don't know how to evaluate the description (third argument) in AC_DEFINE_UNQUOTED
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_SPEEX_PREPROCESS 1
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_SPEEX_PREPROCESS_VERSION
+_ACEOF
+
+      fi
+   fi
+fi
+
+if test "${PBX_SPEEX_PREPROCESS}" = 1; then
+   PBX_SPEEX_PREPROCESS=1
+fi
+
 
 if test "x${PBX_SPEEXDSP}" != "x1" -a "${USE_SPEEXDSP}" != "no"; then
    pbxlibdir=""
@@ -42003,6 +42270,11 @@ _ACEOF
    fi
 fi
 
+if test "${PBX_SPEEXDSP}" = 1; then
+   PBX_SPEEX_PREPROCESS=1
+fi
+
+
 
 
 if test "x${PBX_SQLITE}" != "x1" -a "${USE_SQLITE}" != "no"; then
@@ -50727,6 +50999,7 @@ OPENH323_INCDIR!$OPENH323_INCDIR$ac_delim
 OPENH323_LIBDIR!$OPENH323_LIBDIR$ac_delim
 OPENH323_SUFFIX!$OPENH323_SUFFIX$ac_delim
 OPENH323_BUILD!$OPENH323_BUILD$ac_delim
+PBX_SPEEX_PREPROCESS!$PBX_SPEEX_PREPROCESS$ac_delim
 CONFIG_GMIME!$CONFIG_GMIME$ac_delim
 PBX_ZAPTEL_VLDTMF!$PBX_ZAPTEL_VLDTMF$ac_delim
 PBX_ZAPTEL_ECHOCANPARAMS!$PBX_ZAPTEL_ECHOCANPARAMS$ac_delim
@@ -50743,7 +51016,7 @@ CURL_CONFIG!$CURL_CONFIG$ac_delim
 LTLIBOBJS!$LTLIBOBJS$ac_delim
 _ACEOF
 
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 67; then
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 68; then
     break
   elif $ac_last_try; then
     { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
diff --git a/configure.ac b/configure.ac
index 6dbd99b473efecd4c78cfd7ceccc4fc5a9283d8f..9f5428aa43f3c716bf916fb1f2bc99cbebf7997e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1314,7 +1314,18 @@ AST_EXT_LIB_CHECK([RADIUS], [radiusclient-ng], [rc_read_config], [radiusclient-n
 
 AST_EXT_LIB_CHECK([SPEEX], [speex], [speex_encode], [speex/speex.h], [-lm])
 
+# See if the main speex library contains the preprocess functions
+AST_EXT_LIB_CHECK([SPEEX_PREPROCESS], [speex_preprocess_ctl], [speex/speex.h], [-lm])
+if test "${PBX_SPEEX_PREPROCESS}" = 1; then
+   PBX_SPEEX_PREPROCESS=1
+fi
+
 AST_EXT_LIB_CHECK([SPEEXDSP], [speexdsp], [speex_preprocess_ctl], [speex/speex.h], [-lm])
+if test "${PBX_SPEEXDSP}" = 1; then
+   PBX_SPEEX_PREPROCESS=1
+fi
+
+AC_SUBST(PBX_SPEEX_PREPROCESS)
 
 AST_EXT_LIB_CHECK([SQLITE], [sqlite], [sqlite_exec], [sqlite.h])
 
diff --git a/funcs/func_speex.c b/funcs/func_speex.c
index 81cba38f5512384c4b82cc2f8fa61cbefe0c374e..afceb9870e5e40da0109cbc0d2199c319fd6e1a3 100644
--- a/funcs/func_speex.c
+++ b/funcs/func_speex.c
@@ -31,6 +31,8 @@
 
 /*** MODULEINFO
 	<depend>speex</depend>
+	<depend>speex_preprocess</depend>
+	<use>speexdsp</use>
  ***/
 
 #include "asterisk.h"
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index d4806a5e27249bbeb5b934b8381f9741f172ced2..4b4d37bf8075eb3fef97e072392d83a415aeb962 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -724,6 +724,12 @@
 /* Define to indicate the ${SPEEXDSP_DESCRIP} library version */
 #undef HAVE_SPEEXDSP_VERSION
 
+/* Define this to indicate the ${SPEEX_PREPROCESS_DESCRIP} library */
+#undef HAVE_SPEEX_PREPROCESS
+
+/* Define to indicate the ${SPEEX_PREPROCESS_DESCRIP} library version */
+#undef HAVE_SPEEX_PREPROCESS_VERSION
+
 /* Define to indicate the ${SPEEX_DESCRIP} library version */
 #undef HAVE_SPEEX_VERSION