Skip to content

Commit

Permalink
Make the binaural compile more efficient(AOMediaCodec#110 was covered)
Browse files Browse the repository at this point in the history
  • Loading branch information
yilun-zhangs committed Jun 28, 2024
1 parent e0ae851 commit 98b3ec8
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 125 deletions.
12 changes: 12 additions & 0 deletions code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ link_directories (
${CODEC_LIB_DIR}
)

if(MULTICHANNEL_BINAURALIZER OR HOA_BINAURALIZER)
link_directories(
${EXTER_LIB_DIR}/binaural
)
endif()

if(BUILD_SHARED_LIBS)
add_library(${PROJECT_NAME} SHARED ${DIR_DEP_EXTERNAL_WAV} ${DIR_IAMF_COMMON}
${DIR_IAMF_DEC_OPUS} ${DIR_IAMF_DEC_AAC} ${DIR_IAMF_DEC_FLAC} ${DIR_IAMF_DEC_PCM} ${DIR_IAMF_DEC})
Expand All @@ -112,6 +118,12 @@ if(BUILD_SHARED_LIBS)
target_link_libraries (${PROJECT_NAME} FLAC)
endif()

if(MULTICHANNEL_BINAURALIZER)
target_link_libraries (${PROJECT_NAME} iamf2bear)
endif()
if(HOA_BINAURALIZER)
target_link_libraries (${PROJECT_NAME} iamf2resonance)
endif()
else()
add_library(${PROJECT_NAME} STATIC ${DIR_DEP_EXTERNAL_WAV} ${DIR_IAMF_COMMON}
${DIR_IAMF_DEC_OPUS} ${DIR_IAMF_DEC_AAC} ${DIR_IAMF_DEC_PCM}
Expand Down
231 changes: 207 additions & 24 deletions code/dep_codecs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,114 @@
# www.aomedia.org/license/patent.
#

OPUS_DIR="$( cd "$(dirname "$0")" ; pwd -P )/opus/opus-1.4"
AAC_DIR="$( cd "$(dirname "$0")" ; pwd -P )/aac/fdk-aac-free-2.0.0"
FLAC_DIR="$( cd "$(dirname "$0")" ; pwd -P )/flac/flac-1.4.2"
CODEC_LIB_DIR="$( cd "$(dirname "$0")" ; pwd -P )/lib"
set -e

run ()
{
if [ "$VERBOSE" = "yes" ] ; then
echo "##### NEW COMMAND"
echo "$@"
$@ 2>&1
else
if [ -n "$TMPLOG" ] ; then
echo "##### NEW COMMAND" >> $TMPLOG
echo "$@" >> $TMPLOG
$@ 2>&1 | tee -a $TMPLOG
else
$@ > /dev/null 2>&1
fi
fi
}

pattern_match ()
{
echo "$2" | grep -q -E -e "$1"
}

# Find if a given shell program is available.
#
# $1: variable name
# $2: program name
#
# Result: set $1 to the full path of the corresponding command
# or to the empty/undefined string if not available
#
find_program ()
{
eval $1=`command -v $2`
}

prepare_download ()
{
find_program CMD_WGET wget
find_program CMD_CURL curl
find_program CMD_SCRP scp
}

# Download a file with either 'curl', 'wget' or 'scp'
#
# $1: source URL (e.g. http://foo.com, ssh://blah, /some/path)
# $2: target file
download_file ()
{
# Is this HTTP, HTTPS or FTP ?
if pattern_match "^(http|https|ftp):.*" "$1"; then
if [ -n "$CMD_WGET" ] ; then
run $CMD_WGET -O $2 $1
elif [ -n "$CMD_CURL" ] ; then
run $CMD_CURL -L -o $2 $1
else
echo "Please install wget or curl on this machine"
exit 1
fi
return
fi

# Is this SSH ?
# Accept both ssh://<path> or <machine>:<path>
#
if pattern_match "^(ssh|[^:]+):.*" "$1"; then
if [ -n "$CMD_SCP" ] ; then
scp_src=`echo $1 | sed -e s%ssh://%%g`
run $CMD_SCP $scp_src $2
else
echo "Please install scp on this machine"
exit 1
fi
return
fi

# Is this a file copy ?
# Accept both file://<path> or /<path>
#
if pattern_match "^(file://|/).*" "$1"; then
cp_src=`echo $1 | sed -e s%^file://%%g`
run cp -f $cp_src $2
return
fi
}



OPUS_DIR="$( cd "$(dirname "$0")" ; pwd -P )/opus"
AAC_DIR="$( cd "$(dirname "$0")" ; pwd -P )/aac"
FLAC_DIR="$( cd "$(dirname "$0")" ; pwd -P )/flac"
CODECS_DIR="$( cd "$(dirname "$0")" ; pwd -P )"
OPUS_TAR="opus-1.4.tar.gz"
AAC_TAR="fdk-aac-free-2.0.0.tar.gz"
FLAC_TAR="flac-1.4.2.tar.xz"

declare -a CONFIG_FLAGS_OPUS
declare -a CONFIG_FLAGS_AAC
declare -a CONFIG_FLAGS_FLAC
CONFIG_FLAGS_AAC="--enable-static --disable-shared"
CONFIG_FLAGS_FLAC="-DWITH_OGG=OFF -DBUILD_CXXLIBS=OFF"
CONFIG_FLAGS_OPUS="-DCMAKE_C_FLAGS="-fPIC""
CONFIG_FLAGS_AAC="--enable-static --disable-shared --with-pic"
CONFIG_FLAGS_FLAC="-DWITH_OGG=OFF -DBUILD_CXXLIBS=OFF -DCMAKE_C_FLAGS="-fPIC""

OPUS_DOWNLOAD_LINK="https://downloads.xiph.org/releases/opus/opus-1.4.tar.gz"
AAC_DOWNLOAD_LINK="https://people.freedesktop.org/~wtay/fdk-aac-free-2.0.0.tar.gz"
FLAC_DOWNLOAD_LINK="https://downloads.xiph.org/releases/flac/flac-1.4.2.tar.xz"


function show_help()
{
Expand Down Expand Up @@ -47,30 +145,30 @@ do
want_help=yes ;;

--x86_64-mingw_toolchain)
CONFIG_FLAGS_OPUS="-DCMAKE_TOOLCHAIN_FILE=../../../build/cmake/toolchains/x86_64-mingw.cmake -DOPUS_STACK_PROTECTOR=OFF"
CONFIG_FLAGS_AAC="--host=x86_64-w64-mingw32 --enable-static --disable-shared"
CONFIG_FLAGS_FLAC="-DCMAKE_TOOLCHAIN_FILE=../../../build/cmake/toolchains/x86_64-mingw.cmake -DWITH_OGG=OFF -DBUILD_CXXLIBS=OFF -DWITH_STACK_PROTECTOR=OFF"
CONFIG_FLAGS_OPUS="-DCMAKE_TOOLCHAIN_FILE=../../../build/cmake/toolchains/x86_64-mingw.cmake -DOPUS_STACK_PROTECTOR=OFF -DCMAKE_C_FLAGS="-fPIC""
CONFIG_FLAGS_AAC="--host=x86_64-w64-mingw32 --enable-static --disable-shared --with-pic"
CONFIG_FLAGS_FLAC="-DCMAKE_TOOLCHAIN_FILE=../../../build/cmake/toolchains/x86_64-mingw.cmake -DWITH_OGG=OFF -DBUILD_CXXLIBS=OFF -DWITH_STACK_PROTECTOR=OFF -DCMAKE_C_FLAGS="-fPIC""
shift # past argument with no value
;;

--arm64-linux_toolchain)
CONFIG_FLAGS_OPUS="-DCMAKE_TOOLCHAIN_FILE=../../../build/cmake/toolchains/arm64-linux.cmake -DOPUS_STACK_PROTECTOR=OFF"
CONFIG_FLAGS_AAC="--host=aarch64-linux-gnu --enable-static --disable-shared"
CONFIG_FLAGS_FLAC="-DCMAKE_TOOLCHAIN_FILE=../../../build/cmake/toolchains/arm64-linux.cmake -DCMAKE_C_FLAGS="-fPIC" -DWITH_OGG=OFF -DBUILD_CXXLIBS=OFF -DWITH_STACK_PROTECTOR=OFF"
CONFIG_FLAGS_OPUS="-DCMAKE_TOOLCHAIN_FILE=../../../build/cmake/toolchains/arm64-linux.cmake -DOPUS_STACK_PROTECTOR=OFF -DCMAKE_C_FLAGS="-fPIC""
CONFIG_FLAGS_AAC="--host=aarch64-linux-gnu --enable-static --disable-shared --with-pic"
CONFIG_FLAGS_FLAC="-DCMAKE_TOOLCHAIN_FILE=../../../build/cmake/toolchains/arm64-linux.cmake -DWITH_OGG=OFF -DBUILD_CXXLIBS=OFF -DWITH_STACK_PROTECTOR=OFF -DCMAKE_C_FLAGS="-fPIC""
shift # past argument with no value
;;

--x86-macos_toolchain)
CONFIG_FLAGS_OPUS="-DCMAKE_TOOLCHAIN_FILE=../../../build/cmake/toolchains/x86-macos.cmake"
CONFIG_FLAGS_AAC="--host=x86_64-apple-darwin20.4 --enable-static --disable-shared"
CONFIG_FLAGS_FLAC="-DCMAKE_TOOLCHAIN_FILE=../../../build/cmake/toolchains/x86-macos.cmake -DWITH_OGG=OFF -DBUILD_CXXLIBS=OFF"
CONFIG_FLAGS_OPUS="-DCMAKE_TOOLCHAIN_FILE=../../../build/cmake/toolchains/x86-macos.cmake -DCMAKE_C_FLAGS="-fPIC""
CONFIG_FLAGS_AAC="--host=x86_64-apple-darwin20.4 --enable-static --disable-shared --with-pic"
CONFIG_FLAGS_FLAC="-DCMAKE_TOOLCHAIN_FILE=../../../build/cmake/toolchains/x86-macos.cmake -DWITH_OGG=OFF -DBUILD_CXXLIBS=OFF -DCMAKE_C_FLAGS="-fPIC""
shift # past argument with no value
;;

--arm64-ios_toolchain)
CONFIG_FLAGS_OPUS="-DCMAKE_TOOLCHAIN_FILE=../../../build/cmake/toolchains/arm64-ios.cmake"
CONFIG_FLAGS_AAC="--host=aarch64-apple-darwin20.4 --enable-static --disable-shared"
CONFIG_FLAGS_FLAC="-DCMAKE_TOOLCHAIN_FILE=../../../build/cmake/toolchains/arm64-ios.cmake -DWITH_OGG=OFF -DBUILD_CXXLIBS=OFF"
CONFIG_FLAGS_AAC="--host=aarch64-apple-darwin20.4 --enable-static --disable-shared --with-pic"
CONFIG_FLAGS_FLAC="-DCMAKE_TOOLCHAIN_FILE=../../../build/cmake/toolchains/arm64-ios.cmake -DWITH_OGG=OFF -DBUILD_CXXLIBS=OFF -DCMAKE_C_FLAGS="-fPIC""
shift # past argument with no value
;;

Expand All @@ -86,29 +184,114 @@ if test "x$want_help" = xyes; then
show_help
fi

#Delete old libraries
rm -rf $CODECS_DIR/lib

echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>Codec Download<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"

CLEAN=yes
DOWNLOAD=yes

if [ $CLEAN = yes ] ; then
echo "Cleaning: $OPUS_DIR"
rm -f -r $OPUS_DIR

echo "Cleaning: $AAC_DIR"
rm -f -r $AAC_DIR

echo "Cleaning: $FLAC_DIR"
rm -f -r $FLAC_DIR

mkdir $OPUS_DIR
mkdir $AAC_DIR
mkdir $FLAC_DIR
[ "$DOWNLOAD" = "yes" ] || exit 0
fi

#Download OPUS
if [ ! -f $OPUS_DIR/$OPUS_TAR ]
then
echo "Downloading opus please wait..."
prepare_download
download_file $OPUS_DOWNLOAD_LINK $OPUS_DIR/$OPUS_TAR
fi

if [ ! -f $OPUS_DIR/$OPUS_TAR ]
then
echo "Failed to download opus! Please download manually\nand save it in this directory as $OPUS_TAR"
exit 1
fi

if [ -f $OPUS_DIR/$OPUS_TAR ]
then
echo "Unpacking opus"
tar -zxf $OPUS_DIR/$OPUS_TAR -C $OPUS_DIR
fi

#Download AAC
if [ ! -f $AAC_DIR/$AAC_TAR ]
then
echo "Downloading aac please wait..."
prepare_download
download_file $AAC_DOWNLOAD_LINK $AAC_DIR/$AAC_TAR
fi

if [ ! -f $AAC_DIR/$AAC_TAR ]
then
echo "Failed to download aac! Please download manually\nand save it in this directory as $AAC_TAR"
exit 1
fi

if [ -f $AAC_DIR/$AAC_TAR ]
then
echo "Unpacking aac"
tar -zxf $AAC_DIR/$AAC_TAR -C $AAC_DIR
fi

#Download FLAC
if [ ! -f $FLAC_DIR/$FLAC_TAR ]
then
echo "Downloading flac please wait..."
prepare_download
download_file $FLAC_DOWNLOAD_LINK $FLAC_DIR/$FLAC_TAR
fi

if [ ! -f $FLAC_DIR/$FLAC_TAR ]
then
echo "Failed to download flac! Please download manually\nand save it in this directory as $FLAC_TAR"
exit 1
fi

if [ -f $FLAC_DIR/$FLAC_TAR ]
then
echo "Unpacking flac"
tar -xf $FLAC_DIR/$FLAC_TAR -C $FLAC_DIR
fi



echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>OPUS Compile<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
cd $OPUS_DIR
cd $OPUS_DIR/opus-1.4
rm -rf build
cmake -B build ./ $CONFIG_FLAGS_OPUS
cmake --build build --clean-first
cp -f build/libopus.a $CODEC_LIB_DIR
cmake --install build --prefix $CODECS_DIR

echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>AAC Compile<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
cd $AAC_DIR
cd $AAC_DIR/fdk-aac-free-2.0.0
rm -rf build
mkdir build
cd build
../configure $CONFIG_FLAGS_AAC
../configure $CONFIG_FLAGS_AAC --prefix=$CODECS_DIR
make
cp -f .libs/libfdk-aac.a $CODEC_LIB_DIR
make install

echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>FLAC Compile<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
cd $FLAC_DIR
cd $FLAC_DIR/flac-1.4.2
rm -rf build
cmake -B build ./ $CONFIG_FLAGS_FLAC
cmake --build build --clean-first
cp -f build/src/libFLAC/libFLAC.a $CODEC_LIB_DIR
cmake --install build --prefix $CODECS_DIR



21 changes: 10 additions & 11 deletions code/dep_external/src/binaural/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
README.md
=========
# Dependent Codec Libraries
# Dependent Externals Libraries

## Contents
1. [Downloading the opensource](#Downloading-the-opensource)
Expand All @@ -10,21 +10,20 @@ README.md


## Downloading the opensource
1. [visr](https://github.com/ebu/bear/releases/download/v0.0.1-pre/visr-0.13.0-pre-5e13f020.zip)
2. [boost](https://boostorg.jfrog.io/artifactory/main/release/1.82.0/source/boost_1_82_0.zip)

Please download the opensource and unzip to directory separately as following:
~~~
rd-audio-visr-public-master
boost_1_82_0
~~~
1. [bear](https://github.com/ebu/bear)
2. [resonance-audio](https://github.com/resonance-audio/resonance-audio)


## Building the libraries

### Prerequisites
1. [CMake](https://cmake.org) version 3.6 or higher.
2. Tool chains if need cross compiling.

2. [boost](https://boostorg.jfrog.io/artifactory/main/release/1.82.0/source/boost_1_82_0.zip), version 1.82
~~~
$ ./bootstrap.sh --with-toolset=gcc
$ ./b2 toolset=gcc
$ ./b2 install
~~~

### Basic build
"build.sh" is an example to build, you can run it directly at your side.
Loading

0 comments on commit 98b3ec8

Please sign in to comment.