Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vorbis support to 0.6 release. #752

Merged
merged 2 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/unittest/linux/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ printf "Installing PyTorch with %s\n" "${cudatoolkit}"
conda install -y -c pytorch-nightly pytorch "${cudatoolkit}"

printf "* Installing torchaudio\n"
python setup.py develop
BUILD_SOX=1 python setup.py develop
1 change: 1 addition & 0 deletions .circleci/unittest/linux/scripts/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ eval "$(./conda/bin/conda shell.bash hook)"
conda activate ./env

python -m torch.utils.collect_env
export PATH="${PWD}/third_party/build/bin/:${PATH}"
pytest --cov=torchaudio --junitxml=test-results/junit.xml -v --durations 20 test
2 changes: 1 addition & 1 deletion .circleci/unittest/linux/scripts/setup_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ printf "* Installing dependencies (except PyTorch)\n"
conda env update --file "${this_dir}/environment.yml" --prune

# 4. Build codecs
# build_tools/setup_helpers/build_third_party.sh
build_tools/setup_helpers/build_third_party.sh
14 changes: 14 additions & 0 deletions build_tools/setup_helpers/build_third_party.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ mkdir -p "${tmp_dir}" "${build_dir}"

. "${this_dir}/build_third_party_helper.sh"

if ! found_ogg "${build_dir}" ; then
get_ogg "${tmp_dir}"
if [ "${download_only}" = "false" ]; then
build_ogg "${tmp_dir}" "${build_dir}"
fi
fi

if ! found_vorbis "${build_dir}" ; then
get_vorbis "${tmp_dir}"
if [ "${download_only}" = "false" ]; then
build_vorbis "${tmp_dir}" "${build_dir}"
fi
fi

if ! found_lame "${build_dir}" ; then
get_lame "${tmp_dir}"
if [ "${download_only}" = "false" ]; then
Expand Down
94 changes: 91 additions & 3 deletions build_tools/setup_helpers/build_third_party_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ all_found() {
done
}

found_ogg() {
all_found "$1" 'include/ogg/ogg.h' 'lib/libogg.a'
}

found_vorbis() {
all_found "$1" \
'include/vorbis/vorbisenc.h' \
'include/vorbis/vorbisfile.h' \
'lib/libvorbis.a' \
'lib/libvorbisenc.a' \
'lib/libvorbisfile.a'
}

found_lame() {
all_found "$1" 'include/lame/lame.h' 'lib/libmp3lame.a'
Expand Down Expand Up @@ -57,6 +69,82 @@ found_sox() {
all_found "$1" 'include/sox.h' 'lib/libsox.a'
}

# libogg 1.3.4 has bug on mac OS.
# https://trac.macports.org/ticket/58924
OGG="libogg-1.3.3"
OGG_ARCHIVE="${OGG}.tar.gz"

get_ogg() {
work_dir="$1"
url="https://ftp.osuosl.org/pub/xiph/releases/ogg/${OGG_ARCHIVE}"
(
cd "${work_dir}"
if [ ! -d "${OGG}" ]; then
if [ ! -f "${OGG_ARCHIVE}" ]; then
printf "Fetching libogg from %s\n" "${url}"
curl $CURL_OPTS -O "${url}"
fi
fi
)
}

build_ogg() {
work_dir="$1"
install_dir="$2"
(
cd "${work_dir}"
if [ ! -d "${OGG}" ]; then
tar xfp "${OGG_ARCHIVE}"
fi
cd "${OGG}"
printf "Building libogg\n"
if [ ! -f Makefile ]; then
./configure ${CONFIG_OPTS} \
--disable-shared --enable-static --prefix="${install_dir}" CFLAGS=-fPIC CXXFLAGS=-fPIC \
--with-pic --disable-dependency-tracking
fi
make ${MAKE_OPTS} > make.log 2>&1
make install
)
}

VORBIS="libvorbis-1.3.6"
VORBIS_ARCHIVE="${VORBIS}.tar.gz"

get_vorbis() {
work_dir="$1"
url="https://ftp.osuosl.org/pub/xiph/releases/vorbis/${VORBIS_ARCHIVE}"
(
cd "${work_dir}"
if [ ! -d "${VORBIS}" ]; then
if [ ! -f "${VORBIS_ARCHIVE}" ]; then
printf "Fetching libvorbis from %s\n" "${url}"
curl $CURL_OPTS -O "${url}"
fi
fi
)
}

build_vorbis() {
work_dir="$1"
install_dir="$2"
(
cd "${work_dir}"
if [ ! -d "${VORBIS}" ]; then
tar xfp "${VORBIS_ARCHIVE}"
fi
cd "${VORBIS}"
printf "Building libvorbis\n"
if [ ! -f Makefile ]; then
./configure ${CONFIG_OPTS} \
--disable-shared --enable-static --prefix="${install_dir}" CFLAGS=-fPIC CXXFLAGS=-fPIC \
--with-pic --disable-dependency-tracking
fi
make ${MAKE_OPTS} > make.log 2>&1
make install
)
}

LAME="lame-3.99.5"
LAME_ARCHIVE="${LAME}.tar.gz"

Expand Down Expand Up @@ -126,7 +214,7 @@ build_flac() {
if [ ! -f Makefile ]; then
./configure ${CONFIG_OPTS} \
--disable-shared --enable-static --prefix="${install_dir}" CFLAGS=-fPIC CXXFLAGS=-fPIC \
--with-pic --disable-debug --disable-dependency-tracking
--with-pic --with-ogg="${install_dir}" --disable-debug --disable-dependency-tracking
fi
make ${MAKE_OPTS} > make.log 2>&1
make ${MAKE_OPTS} install
Expand Down Expand Up @@ -207,8 +295,8 @@ build_sox() {
# it statically if we do.
./configure ${CONFIG_OPTS} --disable-shared --enable-static --prefix="${install_dir}" \
LDFLAGS="-L${install_dir}/lib" CPPFLAGS="-I${install_dir}/include" \
--with-lame --with-flac --with-mad --without-alsa --without-coreaudio \
--without-png --without-oggvorbis --without-oss --without-sndfile \
--with-lame --with-flac --with-mad --with-oggvorbis --without-alsa --without-coreaudio \
--without-png --without-oss --without-sndfile \
CFLAGS=-fPIC CXXFLAGS=-fPIC --with-pic --disable-debug --disable-dependency-tracking
fi
make ${MAKE_OPTS} > make.log 2>&1
Expand Down
14 changes: 12 additions & 2 deletions build_tools/setup_helpers/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,18 @@ def _get_extra_objects():
# NOTE: The order of the library listed bellow matters.
#
# (the most important thing is that dependencies come after a library
# e.g., sox comes first)
libs = ['libsox.a', 'libmad.a', 'libFLAC.a', 'libmp3lame.a']
# e.g., sox comes first, flac/vorbis comes before ogg, and
# vorbisenc/vorbisfile comes before vorbis
libs = [
'libsox.a',
'libmad.a',
'libFLAC.a',
'libmp3lame.a',
'libvorbisenc.a',
'libvorbisfile.a',
'libvorbis.a',
'libogg.a',
]
for lib in libs:
objs.append(str(_TP_INSTALL_DIR / 'lib' / lib))
return objs
Expand Down