summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2017-02-20 10:24:55 -0600
committerGerrit Code Review <gerrit2@gerrit.digium.api>2017-02-20 10:24:55 -0600
commitfe88f2e5ca1aadfd77fb1e11122755d37fdbb49d (patch)
tree3e6796fdc04dbe3dc3ec7d394779b622c1ab3f5c
parenta6225d100eecfef74172ef308b7eb066e19488e5 (diff)
parentb58de2fab71ad53b5a385476620dc7b45970cfb6 (diff)
Merge "Binaural synthesis (confbridge): Adds utils/conf_bridge_binaural_hrir_importer"
-rw-r--r--build_tools/menuselect-deps.in1
-rwxr-xr-xconfigure227
-rw-r--r--configure.ac4
-rw-r--r--include/asterisk/autoconfig.h.in9
-rw-r--r--makeopts.in3
-rw-r--r--utils/Makefile9
-rw-r--r--utils/conf_bridge_binaural_hrir_importer.c148
-rw-r--r--utils/utils.xml5
8 files changed, 324 insertions, 82 deletions
diff --git a/build_tools/menuselect-deps.in b/build_tools/menuselect-deps.in
index 9f1aa7082..ec70be0da 100644
--- a/build_tools/menuselect-deps.in
+++ b/build_tools/menuselect-deps.in
@@ -57,6 +57,7 @@ RESAMPLE=@PBX_RESAMPLE@
FFTW3=@PBX_FFTW3@
RADIUS=@PBX_RADIUS@
LAUNCHD=@PBX_LAUNCHD@
+SNDFILE=@PBX_SNDFILE@
SPANDSP=@PBX_SPANDSP@
SPEEX=@PBX_SPEEX@
SPEEXDSP=@PBX_SPEEXDSP@
diff --git a/configure b/configure
index 148d11101..42a21d7c5 100755
--- a/configure
+++ b/configure
@@ -835,6 +835,10 @@ PBX_SDL
SDL_DIR
SDL_INCLUDE
SDL_LIB
+PBX_SNDFILE
+SNDFILE_DIR
+SNDFILE_INCLUDE
+SNDFILE_LIB
PBX_RESAMPLE
RESAMPLE_DIR
RESAMPLE_INCLUDE
@@ -1262,7 +1266,6 @@ COMPRESS
FIND
PYTHON
FLEX
-CUT
CAT
CMP
BISON
@@ -1349,7 +1352,6 @@ infodir
docdir
oldincludedir
includedir
-runstatedir
localstatedir
sharedstatedir
sysconfdir
@@ -1436,6 +1438,7 @@ with_pwlib
with_radius
with_fftw3
with_resample
+with_sndfile
with_sdl
with_SDL_image
with_spandsp
@@ -1532,7 +1535,6 @@ datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
-runstatedir='${localstatedir}/run'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@@ -1785,15 +1787,6 @@ do
| -silent | --silent | --silen | --sile | --sil)
silent=yes ;;
- -runstatedir | --runstatedir | --runstatedi | --runstated \
- | --runstate | --runstat | --runsta | --runst | --runs \
- | --run | --ru | --r)
- ac_prev=runstatedir ;;
- -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
- | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
- | --run=* | --ru=* | --r=*)
- runstatedir=$ac_optarg ;;
-
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1931,7 +1924,7 @@ fi
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
- libdir localedir mandir runstatedir
+ libdir localedir mandir
do
eval ac_val=\$$ac_var
# Remove trailing slashes.
@@ -2084,7 +2077,6 @@ Fine tuning of the installation directories:
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
- --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
@@ -2198,6 +2190,7 @@ Optional Packages:
--with-radius=PATH use Radius Client files in PATH
--with-fftw3=PATH use LIBFFTW3 files in PATH
--with-resample=PATH use LIBRESAMPLE files in PATH
+ --with-sndfile=PATH use libsndfile files in PATH
--with-sdl=PATH use Sdl files in PATH
--with-SDL_image=PATH use Sdl Image files in PATH
--with-spandsp=PATH use SPANDSP files in PATH
@@ -6852,47 +6845,6 @@ $as_echo "no" >&6; }
fi
-# Extract the first word of "cut", so it can be a program name with args.
-set dummy cut; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_CUT+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- case $CUT in
- [\\/]* | ?:[\\/]*)
- ac_cv_path_CUT="$CUT" # Let the user override the test with a path.
- ;;
- *)
- as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
- IFS=$as_save_IFS
- test -z "$as_dir" && as_dir=.
- for ac_exec_ext in '' $ac_executable_extensions; do
- if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
- ac_cv_path_CUT="$as_dir/$ac_word$ac_exec_ext"
- $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
- break 2
- fi
-done
- done
-IFS=$as_save_IFS
-
- test -z "$ac_cv_path_CUT" && ac_cv_path_CUT=":"
- ;;
-esac
-fi
-CUT=$ac_cv_path_CUT
-if test -n "$CUT"; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CUT" >&5
-$as_echo "$CUT" >&6; }
-else
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
# Extract the first word of "flex", so it can be a program name with args.
set dummy flex; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
@@ -9342,7 +9294,7 @@ $as_echo "configuring" >&6; }
as_fn_error $? "nm is required to build bundled pjproject" "$LINENO" 5
fi
if test "${MD5}" = ":" ; then
- as_fn_error $? "md5dum is required to build bundled pjproject" "$LINENO" 5
+ as_fn_error $? "md5sum is required to build bundled pjproject" "$LINENO" 5
fi
if test "${CAT}" = ":" ; then
as_fn_error $? "cat is required to build bundled pjproject" "$LINENO" 5
@@ -12083,6 +12035,38 @@ fi
+ SNDFILE_DESCRIP="libsndfile"
+ SNDFILE_OPTION="sndfile"
+ PBX_SNDFILE=0
+
+# Check whether --with-sndfile was given.
+if test "${with_sndfile+set}" = set; then :
+ withval=$with_sndfile;
+ case ${withval} in
+ n|no)
+ USE_SNDFILE=no
+ # -1 is a magic value used by menuselect to know that the package
+ # was disabled, other than 'not found'
+ PBX_SNDFILE=-1
+ ;;
+ y|ye|yes)
+ ac_mandatory_list="${ac_mandatory_list} SNDFILE"
+ ;;
+ *)
+ SNDFILE_DIR="${withval}"
+ ac_mandatory_list="${ac_mandatory_list} SNDFILE"
+ ;;
+ esac
+
+fi
+
+
+
+
+
+
+
+
SDL_DESCRIP="Sdl"
SDL_OPTION="sdl"
PBX_SDL=0
@@ -14857,7 +14841,7 @@ else
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
-#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
@@ -14903,7 +14887,7 @@ else
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
-#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
@@ -14927,7 +14911,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
-#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
@@ -14972,7 +14956,7 @@ else
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
-#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
@@ -14996,7 +14980,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
-#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
@@ -17105,21 +17089,6 @@ fi
-# https support (in main/http.c) uses funopen on BSD systems,
-# fopencookie on linux
-for ac_func in funopen fopencookie
-do :
- as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
-ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
-if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
- cat >>confdefs.h <<_ACEOF
-#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-done
-
-
for ac_func in inet_aton
do :
ac_fn_c_check_func "$LINENO" "inet_aton" "ac_cv_func_inet_aton"
@@ -29536,6 +29505,112 @@ $as_echo "#define HAVE_FFTW 1" >>confdefs.h
fi
+if test "x${PBX_SNDFILE}" != "x1" -a "${USE_SNDFILE}" != "no"; then
+ pbxlibdir=""
+ # if --with-SNDFILE=DIR has been specified, use it.
+ if test "x${SNDFILE_DIR}" != "x"; then
+ if test -d ${SNDFILE_DIR}/lib; then
+ pbxlibdir="-L${SNDFILE_DIR}/lib"
+ else
+ pbxlibdir="-L${SNDFILE_DIR}"
+ fi
+ fi
+ pbxfuncname="sf_open"
+ if test "x${pbxfuncname}" = "x" ; then # empty lib, assume only headers
+ AST_SNDFILE_FOUND=yes
+ else
+ ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
+ CFLAGS="${CFLAGS} "
+ as_ac_Lib=`$as_echo "ac_cv_lib_sndfile_${pbxfuncname}" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${pbxfuncname} in -lsndfile" >&5
+$as_echo_n "checking for ${pbxfuncname} in -lsndfile... " >&6; }
+if eval \${$as_ac_Lib+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-lsndfile ${pbxlibdir} -lsndfile $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* 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
+if ac_fn_c_try_link "$LINENO"; then :
+ eval "$as_ac_Lib=yes"
+else
+ eval "$as_ac_Lib=no"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+eval ac_res=\$$as_ac_Lib
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
+ AST_SNDFILE_FOUND=yes
+else
+ AST_SNDFILE_FOUND=no
+fi
+
+ CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
+ fi
+
+ # now check for the header.
+ if test "${AST_SNDFILE_FOUND}" = "yes"; then
+ SNDFILE_LIB="${pbxlibdir} -lsndfile -lsndfile"
+ # if --with-SNDFILE=DIR has been specified, use it.
+ if test "x${SNDFILE_DIR}" != "x"; then
+ SNDFILE_INCLUDE="-I${SNDFILE_DIR}/include"
+ fi
+ SNDFILE_INCLUDE="${SNDFILE_INCLUDE} "
+ if test "xsndfile.h" = "x" ; then # no header, assume found
+ SNDFILE_HEADER_FOUND="1"
+ else # check for the header
+ ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
+ CPPFLAGS="${CPPFLAGS} ${SNDFILE_INCLUDE}"
+ ac_fn_c_check_header_mongrel "$LINENO" "sndfile.h" "ac_cv_header_sndfile_h" "$ac_includes_default"
+if test "x$ac_cv_header_sndfile_h" = xyes; then :
+ SNDFILE_HEADER_FOUND=1
+else
+ SNDFILE_HEADER_FOUND=0
+fi
+
+
+ CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
+ fi
+ if test "x${SNDFILE_HEADER_FOUND}" = "x0" ; then
+ SNDFILE_LIB=""
+ SNDFILE_INCLUDE=""
+ else
+ if test "x${pbxfuncname}" = "x" ; then # only checking headers -> no library
+ SNDFILE_LIB=""
+ fi
+ PBX_SNDFILE=1
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_SNDFILE 1
+_ACEOF
+
+ fi
+ fi
+fi
+
+
+
+
+
if test "x${PBX_SPANDSP}" != "x1" -a "${USE_SPANDSP}" != "no"; then
if test "xminimum version of SpanDSP" != "x"; then
diff --git a/configure.ac b/configure.ac
index 5a504986c..fff8ecf7e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -552,6 +552,7 @@ AST_EXT_LIB_SETUP([PWLIB], [PWlib], [pwlib])
AST_EXT_LIB_SETUP([RADIUS], [Radius Client], [radius])
AST_EXT_LIB_SETUP([FFTW3], [LIBFFTW3], [fftw3])
AST_EXT_LIB_SETUP([RESAMPLE], [LIBRESAMPLE], [resample])
+AST_EXT_LIB_SETUP([SNDFILE], [libsndfile], [sndfile])
AST_EXT_LIB_SETUP([SDL], [Sdl], [sdl])
AST_EXT_LIB_SETUP([SDL_IMAGE], [Sdl Image], [SDL_image])
AST_EXT_LIB_SETUP([SPANDSP], [SPANDSP], [spandsp])
@@ -2286,6 +2287,9 @@ AST_EXT_LIB_CHECK([FFTW3], [fftw3], [fftw_alloc_real], [fftw3.h], [-lfftw3])
if test "$PBX_FFTW3" = "1"; then
AC_DEFINE([HAVE_FFTW], 1, [Define 1 if your system has fftw.])
fi
+AST_EXT_LIB_CHECK([SNDFILE], [sndfile], [sf_open], [sndfile.h], [-lsndfile])
+
+
AST_C_COMPILE_CHECK([SPANDSP], [
#if SPANDSP_RELEASE_DATE < 20080516
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index 41ba61353..eecd957fa 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -254,9 +254,6 @@
/* Define to 1 if you have the `fmodl' function. */
#undef HAVE_FMODL
-/* Define to 1 if you have the `fopencookie' function. */
-#undef HAVE_FOPENCOOKIE
-
/* Define to 1 if you have the `fork' function. */
#undef HAVE_FORK
@@ -269,9 +266,6 @@
/* Define to 1 if you have the `ftruncate' function. */
#undef HAVE_FTRUNCATE
-/* Define to 1 if you have the `funopen' function. */
-#undef HAVE_FUNOPEN
-
/* Define to 1 if your GCC C compiler provides atomic operations. */
#undef HAVE_GCC_ATOMICS
@@ -832,6 +826,9 @@
/* Define to 1 if you have the `sinl' function. */
#undef HAVE_SINL
+/* Define to 1 if you have the libsndfile library. */
+#undef HAVE_SNDFILE
+
/* Define to 1 if you have the `socket' function. */
#undef HAVE_SOCKET
diff --git a/makeopts.in b/makeopts.in
index c67e2f2b6..6a1164c32 100644
--- a/makeopts.in
+++ b/makeopts.in
@@ -380,3 +380,6 @@ TINFO_DIR=@TINFO_DIR@
# if poll is not present, let the makefile know.
POLL_AVAILABLE=@HAS_POLL@
TIMERFD_INCLUDE=@TIMERFD_INCLUDE@
+
+SNDFILE_INCLUDE=@SNDFILE_INCLUDE@
+SNDFILE_LIB=@SNDFILE_LIB@
diff --git a/utils/Makefile b/utils/Makefile
index 97b0e2fe6..b6618e195 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -70,6 +70,10 @@ ifneq ($(filter pbx_ael,$(MENUSELECT_PBX)),)
UTILS:=$(filter-out conf2ael,$(UTILS))
endif
+ifeq ($(SNDFILE_LIB),)
+ UTILS:=$(filter-out conf_bridge_binaural_hrir_importer,$(UTILS))
+endif
+
all: $(UTILS)
install:
@@ -93,6 +97,7 @@ clean:
rm -f db1-ast/.*.d
@$(MAKE) -C db1-ast clean
+
md5.c: $(ASTTOPDIR)/main/md5.c
$(ECHO_PREFIX) echo " [CP] $(subst $(ASTTOPDIR)/,,$<) -> $@"
$(CMD_PREFIX) cp "$<" "$@"
@@ -188,6 +193,10 @@ smsq: LIBS+=$(POPT_LIB)
streamplayer: streamplayer.o
+conf_bridge_binaural_hrir_importer: LIBS+=$(SNDFILE_LIB)
+conf_bridge_binaural_hrir_importer: _ASTCFLAGS+=$(SNDFILE_INCLUDE)
+conf_bridge_binaural_hrir_importer: conf_bridge_binaural_hrir_importer.o
+
muted: muted.o
muted: LIBS+=$(AUDIO_LIBS)
muted: _ASTCFLAGS:=$(filter-out -Werror,$(_ASTCFLAGS))
diff --git a/utils/conf_bridge_binaural_hrir_importer.c b/utils/conf_bridge_binaural_hrir_importer.c
new file mode 100644
index 000000000..5690d86ea
--- /dev/null
+++ b/utils/conf_bridge_binaural_hrir_importer.c
@@ -0,0 +1,148 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2016, Digium, Inc.
+ *
+ * Frank Haase <fra.haase@gmail.com>
+ * Dennis Guse <dennis.guse@alumni.tu-berlin.de>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * Converts a Head Related Impulse Response (HRIR) database (a multi-channel wave) into a C header file.
+ * HRIR for the left ear and HRIR for right ear have to be interleaved.
+ * No further signal processing is applied (e.g., resampling).
+ *
+ * Info messages are printed to stderror and the generated header file to output.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sndfile.h>
+
+int main (int argc, char **argv)
+{
+ char *hrir_filename;
+ unsigned int binaural_index_start;
+ unsigned int binaural_index_end;
+
+ SNDFILE *hrir_file;
+ SF_INFO hrir_info;
+ float *hrir_data;
+
+ unsigned int impulse_response_index_start;
+ unsigned int impulse_response_index_end;
+
+ int j;
+ int ir_current;
+
+ if(argc != 4) {
+ puts("HRIR database to C header file converter.");
+ puts("Usage: conf_bridge_binaural_hrir_importer HRIR.wav INDEX_START INDEX_END > OUTPUT.h");
+ puts("Example: conf_bridge_binaural_hrir_importer hrirs.wav 0 180 > ../bridges/bridge_softmix/include/hrirs.h");
+
+ return -1;
+ }
+
+ /* Parse arguments */
+ hrir_filename = argv[1];
+ binaural_index_start = atoi(argv[2]);
+ binaural_index_end = atoi(argv[3]);
+
+ /* Read HRIR database */
+ hrir_file = sf_open(hrir_filename, SFM_READ, &hrir_info);
+ if(hrir_file == NULL) {
+ fprintf(stderr, "ERROR: Could not open HRIR database (%s).\n", hrir_filename);
+
+ return -1;
+ }
+ fprintf(stderr, "INFO: Opened HRIR database (%s) with: number channels: %d; samplerate: %d; samples per channel: %ld\n", hrir_filename, hrir_info.channels, hrir_info.samplerate, hrir_info.frames);
+
+ hrir_data = (float *)malloc(hrir_info.channels * hrir_info.frames * sizeof(float));
+ if(hrir_data == NULL) {
+ fprintf(stderr, "ERROR: Out of memory!");
+
+ return -1;
+ }
+
+ /* Channels are interleaved */
+ sf_read_float(hrir_file, hrir_data, hrir_info.channels * hrir_info.frames);
+ sf_close(hrir_file);
+
+ if(binaural_index_start >= binaural_index_end) {
+ fprintf(stderr, "ERROR: INDEX_START (%d) must be smaller than INDEX_END (%d).", binaural_index_start, binaural_index_end);
+ free(hrir_data);
+
+ return -1;
+ }
+
+ if (binaural_index_end * 2 >= hrir_info.channels) {
+ fprintf(stderr, "ERROR: END_INDEX (%d) is out of range for HRIR database (%s).\n", binaural_index_end, hrir_filename);
+ free(hrir_data);
+
+ return -1;
+ }
+
+ /* Convert indices */
+ impulse_response_index_start = 2 * binaural_index_start;
+ impulse_response_index_end = (binaural_index_end + 1) * 2;
+
+ /* Write header */
+ printf("//Used hrirs database: %s\n", hrir_filename);
+ printf("//Start index in database: %d\n", impulse_response_index_start);
+ printf("//End index in database: %d\n", impulse_response_index_end);
+
+ printf("#define HRIRS_IMPULSE_LEN %ld\n", hrir_info.frames);
+ printf("#define HRIRS_IMPULSE_SIZE %d\n", binaural_index_end - binaural_index_start + 1);
+ printf("#define HRIRS_SAMPLE_RATE %d\n", hrir_info.samplerate);
+
+ printf("float hrirs_left[HRIRS_IMPULSE_SIZE][HRIRS_IMPULSE_LEN] = {\n");
+ for (ir_current = impulse_response_index_start; ir_current < impulse_response_index_end; ir_current += 2) {
+ printf("{");
+
+ for (j = 0; j < hrir_info.frames - 1; j++) {
+ printf("%.16f,", hrir_data[ir_current * hrir_info.frames + j]);
+ }
+ /* Write last without trailing "," */
+ printf("%.16f", hrir_data[ir_current * hrir_info.frames + hrir_info.frames - 1]);
+
+ if (ir_current + 2 < impulse_response_index_end) {
+ printf("},\n");
+ } else {
+ printf("}};");
+ }
+ }
+
+ printf("\nfloat hrirs_right[HRIRS_IMPULSE_SIZE][HRIRS_IMPULSE_LEN] = {\n");
+ for (ir_current = impulse_response_index_start + 1; ir_current < impulse_response_index_end + 1; ir_current += 2) {
+ printf("{");
+
+ for (j = 0; j < hrir_info.frames - 1; j++) {
+ printf("%.16f,", hrir_data[ir_current * hrir_info.frames + j]);
+ }
+ /* Write last without trailing "," */
+ printf("%.16f", hrir_data[ir_current * hrir_info.frames + hrir_info.frames - 1]);
+
+ if (ir_current + 2 < impulse_response_index_end) {
+ printf("},\n");
+ } else {
+ printf("}};");
+ }
+ }
+
+ fprintf(stderr, "INFO: Successfully converted: imported %d impulse responses.\n", impulse_response_index_end - impulse_response_index_start);
+ free(hrir_data);
+
+ return 0;
+}
diff --git a/utils/utils.xml b/utils/utils.xml
index 909406e84..498929a27 100644
--- a/utils/utils.xml
+++ b/utils/utils.xml
@@ -20,6 +20,11 @@
<depend>newt</depend>
<support_level>extended</support_level>
</member>
+ <member name="conf_bridge_binaural_hrir_importer">
+ <defaultenabled>no</defaultenabled>
+ <depend>sndfile</depend>
+ <support_level>extended</support_level>
+ </member>
<member name="check_expr">
<defaultenabled>no</defaultenabled>
<support_level>extended</support_level>