Skip to content

Commit ee98d07

Browse files
authored
Add vorbis support to 0.6 release. (#752)
* Add vorbis to binary build (#750) * Fix lint error
1 parent 47a0c8e commit ee98d07

File tree

8 files changed

+127
-15
lines changed

8 files changed

+127
-15
lines changed

.circleci/unittest/linux/scripts/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ printf "Installing PyTorch with %s\n" "${cudatoolkit}"
2020
conda install -y -c pytorch-nightly pytorch "${cudatoolkit}"
2121

2222
printf "* Installing torchaudio\n"
23-
python setup.py develop
23+
BUILD_SOX=1 python setup.py develop

.circleci/unittest/linux/scripts/run_test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ eval "$(./conda/bin/conda shell.bash hook)"
66
conda activate ./env
77

88
python -m torch.utils.collect_env
9+
export PATH="${PWD}/third_party/build/bin/:${PATH}"
910
pytest --cov=torchaudio --junitxml=test-results/junit.xml -v --durations 20 test

.circleci/unittest/linux/scripts/setup_env.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ printf "* Installing dependencies (except PyTorch)\n"
3434
conda env update --file "${this_dir}/environment.yml" --prune
3535

3636
# 4. Build codecs
37-
# build_tools/setup_helpers/build_third_party.sh
37+
build_tools/setup_helpers/build_third_party.sh

build_tools/setup_helpers/build_third_party.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ mkdir -p "${tmp_dir}" "${build_dir}"
2121

2222
. "${this_dir}/build_third_party_helper.sh"
2323

24+
if ! found_ogg "${build_dir}" ; then
25+
get_ogg "${tmp_dir}"
26+
if [ "${download_only}" = "false" ]; then
27+
build_ogg "${tmp_dir}" "${build_dir}"
28+
fi
29+
fi
30+
31+
if ! found_vorbis "${build_dir}" ; then
32+
get_vorbis "${tmp_dir}"
33+
if [ "${download_only}" = "false" ]; then
34+
build_vorbis "${tmp_dir}" "${build_dir}"
35+
fi
36+
fi
37+
2438
if ! found_lame "${build_dir}" ; then
2539
get_lame "${tmp_dir}"
2640
if [ "${download_only}" = "false" ]; then

build_tools/setup_helpers/build_third_party_helper.sh

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ all_found() {
2424
done
2525
}
2626

27+
found_ogg() {
28+
all_found "$1" 'include/ogg/ogg.h' 'lib/libogg.a'
29+
}
30+
31+
found_vorbis() {
32+
all_found "$1" \
33+
'include/vorbis/vorbisenc.h' \
34+
'include/vorbis/vorbisfile.h' \
35+
'lib/libvorbis.a' \
36+
'lib/libvorbisenc.a' \
37+
'lib/libvorbisfile.a'
38+
}
2739

2840
found_lame() {
2941
all_found "$1" 'include/lame/lame.h' 'lib/libmp3lame.a'
@@ -57,6 +69,82 @@ found_sox() {
5769
all_found "$1" 'include/sox.h' 'lib/libsox.a'
5870
}
5971

72+
# libogg 1.3.4 has bug on mac OS.
73+
# https://trac.macports.org/ticket/58924
74+
OGG="libogg-1.3.3"
75+
OGG_ARCHIVE="${OGG}.tar.gz"
76+
77+
get_ogg() {
78+
work_dir="$1"
79+
url="https://ftp.osuosl.org/pub/xiph/releases/ogg/${OGG_ARCHIVE}"
80+
(
81+
cd "${work_dir}"
82+
if [ ! -d "${OGG}" ]; then
83+
if [ ! -f "${OGG_ARCHIVE}" ]; then
84+
printf "Fetching libogg from %s\n" "${url}"
85+
curl $CURL_OPTS -O "${url}"
86+
fi
87+
fi
88+
)
89+
}
90+
91+
build_ogg() {
92+
work_dir="$1"
93+
install_dir="$2"
94+
(
95+
cd "${work_dir}"
96+
if [ ! -d "${OGG}" ]; then
97+
tar xfp "${OGG_ARCHIVE}"
98+
fi
99+
cd "${OGG}"
100+
printf "Building libogg\n"
101+
if [ ! -f Makefile ]; then
102+
./configure ${CONFIG_OPTS} \
103+
--disable-shared --enable-static --prefix="${install_dir}" CFLAGS=-fPIC CXXFLAGS=-fPIC \
104+
--with-pic --disable-dependency-tracking
105+
fi
106+
make ${MAKE_OPTS} > make.log 2>&1
107+
make install
108+
)
109+
}
110+
111+
VORBIS="libvorbis-1.3.6"
112+
VORBIS_ARCHIVE="${VORBIS}.tar.gz"
113+
114+
get_vorbis() {
115+
work_dir="$1"
116+
url="https://ftp.osuosl.org/pub/xiph/releases/vorbis/${VORBIS_ARCHIVE}"
117+
(
118+
cd "${work_dir}"
119+
if [ ! -d "${VORBIS}" ]; then
120+
if [ ! -f "${VORBIS_ARCHIVE}" ]; then
121+
printf "Fetching libvorbis from %s\n" "${url}"
122+
curl $CURL_OPTS -O "${url}"
123+
fi
124+
fi
125+
)
126+
}
127+
128+
build_vorbis() {
129+
work_dir="$1"
130+
install_dir="$2"
131+
(
132+
cd "${work_dir}"
133+
if [ ! -d "${VORBIS}" ]; then
134+
tar xfp "${VORBIS_ARCHIVE}"
135+
fi
136+
cd "${VORBIS}"
137+
printf "Building libvorbis\n"
138+
if [ ! -f Makefile ]; then
139+
./configure ${CONFIG_OPTS} \
140+
--disable-shared --enable-static --prefix="${install_dir}" CFLAGS=-fPIC CXXFLAGS=-fPIC \
141+
--with-pic --disable-dependency-tracking
142+
fi
143+
make ${MAKE_OPTS} > make.log 2>&1
144+
make install
145+
)
146+
}
147+
60148
LAME="lame-3.99.5"
61149
LAME_ARCHIVE="${LAME}.tar.gz"
62150

@@ -126,7 +214,7 @@ build_flac() {
126214
if [ ! -f Makefile ]; then
127215
./configure ${CONFIG_OPTS} \
128216
--disable-shared --enable-static --prefix="${install_dir}" CFLAGS=-fPIC CXXFLAGS=-fPIC \
129-
--with-pic --disable-debug --disable-dependency-tracking
217+
--with-pic --with-ogg="${install_dir}" --disable-debug --disable-dependency-tracking
130218
fi
131219
make ${MAKE_OPTS} > make.log 2>&1
132220
make ${MAKE_OPTS} install
@@ -207,8 +295,8 @@ build_sox() {
207295
# it statically if we do.
208296
./configure ${CONFIG_OPTS} --disable-shared --enable-static --prefix="${install_dir}" \
209297
LDFLAGS="-L${install_dir}/lib" CPPFLAGS="-I${install_dir}/include" \
210-
--with-lame --with-flac --with-mad --without-alsa --without-coreaudio \
211-
--without-png --without-oggvorbis --without-oss --without-sndfile \
298+
--with-lame --with-flac --with-mad --with-oggvorbis --without-alsa --without-coreaudio \
299+
--without-png --without-oss --without-sndfile \
212300
CFLAGS=-fPIC CXXFLAGS=-fPIC --with-pic --disable-debug --disable-dependency-tracking
213301
fi
214302
make ${MAKE_OPTS} > make.log 2>&1

build_tools/setup_helpers/extension.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,18 @@ def _get_extra_objects():
7676
# NOTE: The order of the library listed bellow matters.
7777
#
7878
# (the most important thing is that dependencies come after a library
79-
# e.g., sox comes first)
80-
libs = ['libsox.a', 'libmad.a', 'libFLAC.a', 'libmp3lame.a']
79+
# e.g., sox comes first, flac/vorbis comes before ogg, and
80+
# vorbisenc/vorbisfile comes before vorbis
81+
libs = [
82+
'libsox.a',
83+
'libmad.a',
84+
'libFLAC.a',
85+
'libmp3lame.a',
86+
'libvorbisenc.a',
87+
'libvorbisfile.a',
88+
'libvorbis.a',
89+
'libogg.a',
90+
]
8191
for lib in libs:
8292
objs.append(str(_TP_INSTALL_DIR / 'lib' / lib))
8393
return objs

torchaudio/csrc/sox.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ std::tuple<sox_signalinfo_t, sox_encodinginfo_t> get_info(
8383
}
8484

8585
std::vector<std::string> get_effect_names() {
86-
sox_effect_fn_t const * fns = sox_get_effect_fns();
86+
sox_effect_fn_t const* fns = sox_get_effect_fns();
8787
std::vector<std::string> sv;
88-
for(int i = 0; fns[i]; ++i) {
89-
const sox_effect_handler_t *eh = fns[i] ();
90-
if(eh && eh->name)
88+
for (int i = 0; fns[i]; ++i) {
89+
const sox_effect_handler_t* eh = fns[i]();
90+
if (eh && eh->name)
9191
sv.push_back(eh->name);
9292
}
9393
return sv;
@@ -502,7 +502,5 @@ PYBIND11_MODULE(_torchaudio, m) {
502502
&torch::audio::initialize_sox,
503503
"initialize sox for effects");
504504
m.def(
505-
"shutdown_sox",
506-
&torch::audio::shutdown_sox,
507-
"shutdown sox for effects");
505+
"shutdown_sox", &torch::audio::shutdown_sox, "shutdown sox for effects");
508506
}

torchaudio/csrc/sox.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ std::tuple<sox_signalinfo_t, sox_encodinginfo_t> get_info(
4848
// get names of all sox effects
4949
std::vector<std::string> get_effect_names();
5050

51-
// Initialize and Shutdown SoX effects chain. These functions should only be run once.
51+
// Initialize and Shutdown SoX effects chain. These functions should only be
52+
// run once.
5253
int initialize_sox();
5354
int shutdown_sox();
5455

0 commit comments

Comments
 (0)