Unverified Commit 44af0dea authored by moto's avatar moto Committed by GitHub
Browse files

[BC Breaking] Reorganize C++ resources (#630)

This PR
 - Changes the location of C++ codes from
     - from `torchaudio/torch_sox.cpp` to `torchaudio/csrc/sox.cpp`
     - from `torchaudio/torch_sox.h` to `torchaudio/csrc/sox.h`
 - Changes the location where the resulting library is placed
     - from `_torch_sox.so` (outside of `torchaudio` module)
        to `torchaudio/_torchaudio.so`.
parent 2c28b743
#!/usr/bin/env python
import os
import platform
import sys
import subprocess
from setuptools import setup, find_packages
......@@ -85,8 +84,8 @@ if platform.system() == 'Windows':
else:
ext_modules = [
CppExtension(
'_torch_sox',
['torchaudio/torch_sox.cpp'],
'torchaudio._torchaudio',
['torchaudio/csrc/sox.cpp'],
libraries=libraries,
include_dirs=include_dirs + [cwd],
extra_compile_args=eca,
......@@ -94,6 +93,7 @@ else:
extra_link_args=ela),
]
setup(
name="torchaudio",
version=version,
......@@ -116,8 +116,7 @@ setup(
"Topic :: Multimedia :: Sound/Audio",
"Topic :: Scientific/Engineering :: Artificial Intelligence"
],
# Exclude the build files.
packages=find_packages(exclude=["build"]),
packages=find_packages(exclude=["build*", "test*", "torchaudio.csrc*"]),
ext_modules=ext_modules,
cmdclass={'build_ext': BuildExtension},
install_requires=[pytorch_package_dep]
......
......@@ -193,8 +193,8 @@ def save_encinfo(filepath: str,
# save data to file
src = src.contiguous()
import _torch_sox
_torch_sox.write_audio_file(filepath, src, signalinfo, encodinginfo, filetype)
from . import _torchaudio
_torchaudio.write_audio_file(filepath, src, signalinfo, encodinginfo, filetype)
def info(filepath: str) -> Tuple[SignalInfo, EncodingInfo]:
......@@ -236,8 +236,8 @@ def sox_signalinfo_t() -> SignalInfo:
>>> si.length = 0
"""
import _torch_sox
return _torch_sox.sox_signalinfo_t()
from . import _torchaudio
return _torchaudio.sox_signalinfo_t()
@_audio_backend_guard("sox")
......@@ -271,8 +271,8 @@ def sox_encodinginfo_t() -> EncodingInfo:
"""
import _torch_sox
ei = _torch_sox.sox_encodinginfo_t()
from . import _torchaudio
ei = _torchaudio.sox_encodinginfo_t()
sdo = get_sox_option_t(2) # sox_default_option
ei.reverse_bytes = sdo
ei.reverse_nibbles = sdo
......@@ -292,12 +292,12 @@ def get_sox_encoding_t(i: int = None) -> EncodingInfo:
sox_encoding_t: A sox_encoding_t type for output encoding
"""
import _torch_sox
from . import _torchaudio
if i is None:
# one can see all possible values using the .__members__ attribute
return _torch_sox.sox_encoding_t
return _torchaudio.sox_encoding_t
else:
return _torch_sox.sox_encoding_t(i)
return _torchaudio.sox_encoding_t(i)
@_audio_backend_guard("sox")
......@@ -312,11 +312,11 @@ def get_sox_option_t(i: int = 2) -> Any:
sox_option_t: A sox_option_t type
"""
import _torch_sox
from . import _torchaudio
if i is None:
return _torch_sox.sox_option_t
return _torchaudio.sox_option_t
else:
return _torch_sox.sox_option_t(i)
return _torchaudio.sox_option_t(i)
@_audio_backend_guard("sox")
......@@ -332,11 +332,11 @@ def get_sox_bool(i: int = 0) -> Any:
sox_bool: A sox_bool type
"""
import _torch_sox
from . import _torchaudio
if i is None:
return _torch_sox.sox_bool
return _torchaudio.sox_bool
else:
return _torch_sox.sox_bool(i)
return _torchaudio.sox_bool(i)
_SOX_INITIALIZED: Optional[bool] = False
......@@ -370,8 +370,8 @@ def initialize_sox() -> int:
if _SOX_INITIALIZED is None:
raise RuntimeError('SoX effects chain has been already shut down. Can not initialize again.')
if not _SOX_INITIALIZED:
import _torch_sox
code = _torch_sox.initialize_sox()
from . import _torchaudio
code = _torchaudio.initialize_sox()
if code == _SOX_SUCCESS_CODE:
_SOX_INITIALIZED = True
atexit.register(shutdown_sox)
......@@ -394,8 +394,8 @@ def shutdown_sox() -> int:
"""
global _SOX_INITIALIZED
if _SOX_INITIALIZED:
import _torch_sox
code = _torch_sox.shutdown_sox()
from . import _torchaudio
code = _torchaudio.shutdown_sox()
if code == _SOX_INITIALIZED:
_SOX_INITIALIZED = None
return code
......
......@@ -35,8 +35,8 @@ def load(filepath: str,
if offset < 0:
raise ValueError("Expected positive offset value")
import _torch_sox
sample_rate = _torch_sox.read_audio_file(
from . import _torchaudio
sample_rate = _torchaudio.read_audio_file(
filepath,
out,
channels_first,
......@@ -68,5 +68,5 @@ def save(filepath: str, src: Tensor, sample_rate: int, precision: int = 16, chan
def info(filepath: str) -> Tuple[SignalInfo, EncodingInfo]:
r"""See torchaudio.info"""
import _torch_sox
return _torch_sox.get_info(filepath)
from . import _torchaudio
return _torchaudio.get_info(filepath)
#include <torchaudio/torch_sox.h>
#include <torch/extension.h>
#include <sox.h>
#include <torchaudio/csrc/sox.h>
#include <algorithm>
#include <cstdint>
......@@ -385,7 +381,7 @@ int build_flow_effects(const std::string& file_name,
} // namespace audio
} // namespace torch
PYBIND11_MODULE(_torch_sox, m) {
PYBIND11_MODULE(_torchaudio, m) {
py::class_<torch::audio::SoxEffect>(m, "SoxEffect")
.def(py::init<>())
.def("__repr__", [](const torch::audio::SoxEffect &self) {
......
......@@ -16,8 +16,8 @@ def effect_names() -> List[str]:
>>> EFFECT_NAMES = torchaudio.sox_effects.effect_names()
"""
import _torch_sox
return _torch_sox.get_effect_names()
from . import _torchaudio
return _torchaudio.get_effect_names()
@_audio_backend_guard("sox")
......@@ -29,8 +29,8 @@ def SoxEffect():
name of effect, and eopts (List[str]) which is a list of effect options.
"""
import _torch_sox
return _torch_sox.SoxEffect()
from . import _torchaudio
return _torchaudio.SoxEffect()
class SoxEffectsChain(object):
......@@ -150,8 +150,8 @@ class SoxEffectsChain(object):
# print("effect options:", [x.eopts for x in self.chain])
torchaudio.initialize_sox()
import _torch_sox
sr = _torch_sox.build_flow_effects(self.input_file,
from . import _torchaudio
sr = _torchaudio.build_flow_effects(self.input_file,
out,
self.channels_first,
self.out_siginfo,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment