Skip to content

Commit

Permalink
Rename CySoxr to CSoxr as it doesn't use Cython anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
dofuuz committed Jun 1, 2024
1 parent 7e33993 commit 36b07de
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
'myst_parser',
]

autodoc_mock_imports = ['soxr.cysoxr', 'soxr.version', 'numpy']
autodoc_mock_imports = ['soxr.soxr_ext', 'soxr.version', 'numpy']
myst_enable_extensions = ['linkify']

# Add any paths that contain templates here, relative to this directory.
Expand Down
14 changes: 7 additions & 7 deletions src/soxr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def __init__(self,

q = _quality_to_enum(quality)

self._cysoxr = soxr_ext.CySoxr(in_rate, out_rate, num_channels, stype, q)
self._process = getattr(self._cysoxr, f'process_{self._type}')
self._csoxr = soxr_ext.CSoxr(in_rate, out_rate, num_channels, stype, q)
self._process = getattr(self._csoxr, f'process_{self._type}')

def resample_chunk(self, x: np.ndarray, last=False) -> np.ndarray:
""" Resample chunk with streaming resampler
Expand Down Expand Up @@ -143,7 +143,7 @@ def num_clips(self) -> int:
int
Count of clipped samples.
"""
return self._cysoxr.num_clips()
return self._csoxr.num_clips()

def delay(self) -> float:
""" Get current delay.
Expand All @@ -155,14 +155,14 @@ def delay(self) -> float:
float
Current delay in output samples.
"""
return self._cysoxr.delay()
return self._csoxr.delay()

def clear(self) -> None:
""" Reset resampler. Ready for fresh signal, same config.
This can be used to save initialization time.
"""
self._cysoxr.clear()
self._csoxr.clear()


def resample(x: ArrayLike, in_rate: float, out_rate: float, quality='HQ') -> np.ndarray:
Expand Down Expand Up @@ -195,7 +195,7 @@ def resample(x: ArrayLike, in_rate: float, out_rate: float, quality='HQ') -> np.
x = np.asarray(x, dtype=np.float32)

try:
divide_proc = getattr(soxr_ext, f'cysoxr_divide_proc_{x.dtype}')
divide_proc = getattr(soxr_ext, f'csoxr_divide_proc_{x.dtype}')
except AttributeError:
raise TypeError(_DTYPE_ERR_STR.format(x.dtype))

Expand Down Expand Up @@ -223,7 +223,7 @@ def _resample_oneshot(x: np.ndarray, in_rate: float, out_rate: float, quality='H
This function exists for test purpose.
"""
try:
oneshot = getattr(soxr_ext, f'cysoxr_oneshot_{x.dtype}')
oneshot = getattr(soxr_ext, f'csoxr_oneshot_{x.dtype}')
except AttributeError:
raise TypeError(_DTYPE_ERR_STR.format(x.dtype))

Expand Down
58 changes: 29 additions & 29 deletions src/soxr_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static soxr_datatype_t to_soxr_datatype(const type_info& ntype) {
}


class CySoxr {
class CSoxr {
soxr_t _soxr = nullptr;
const double _oi_rate;

Expand All @@ -54,7 +54,7 @@ class CySoxr {
const unsigned _channels;
bool _ended = false;

CySoxr(double in_rate, double out_rate, unsigned num_channels,
CSoxr(double in_rate, double out_rate, unsigned num_channels,
soxr_datatype_t ntype, unsigned long quality) :
_in_rate(in_rate),
_out_rate(out_rate),
Expand All @@ -74,7 +74,7 @@ class CySoxr {
}
}

~CySoxr() {
~CSoxr() {
soxr_delete(_soxr);
}

Expand Down Expand Up @@ -144,7 +144,7 @@ class CySoxr {


template <typename T>
auto cysoxr_divide_proc(
auto csoxr_divide_proc(
double in_rate, double out_rate,
ndarray<const T, nb::ndim<2>, nb::c_contig, nb::device::cpu> x,
unsigned long quality) {
Expand Down Expand Up @@ -208,7 +208,7 @@ auto cysoxr_divide_proc(


template <typename T>
auto cysoxr_oneshot(
auto csoxr_oneshot(
double in_rate, double out_rate,
ndarray<const T, nb::ndim<2>, nb::c_contig, nb::device::cpu> x,
unsigned long quality) {
Expand Down Expand Up @@ -247,31 +247,31 @@ auto cysoxr_oneshot(
NB_MODULE(soxr_ext, m) {
m.def("libsoxr_version", libsoxr_version);

nb::class_<CySoxr>(m, "CySoxr")
.def_ro("in_rate", &CySoxr::_in_rate)
.def_ro("out_rate", &CySoxr::_out_rate)
.def_ro("ntype", &CySoxr::_ntype)
.def_ro("channels", &CySoxr::_channels)
.def_ro("ended", &CySoxr::_ended)
nb::class_<CSoxr>(m, "CSoxr")
.def_ro("in_rate", &CSoxr::_in_rate)
.def_ro("out_rate", &CSoxr::_out_rate)
.def_ro("ntype", &CSoxr::_ntype)
.def_ro("channels", &CSoxr::_channels)
.def_ro("ended", &CSoxr::_ended)
.def(nb::init<double, double, unsigned, soxr_datatype_t, unsigned long>())
.def("process_float32", &CySoxr::process<float>)
.def("process_float64", &CySoxr::process<double>)
.def("process_int32", &CySoxr::process<int32_t>)
.def("process_int16", &CySoxr::process<int16_t>)
.def("num_clips", &CySoxr::num_clips)
.def("delay", &CySoxr::delay)
.def("engine", &CySoxr::engine)
.def("clear", &CySoxr::clear);

m.def("cysoxr_divide_proc_float32", cysoxr_divide_proc<float>);
m.def("cysoxr_divide_proc_float64", cysoxr_divide_proc<double>);
m.def("cysoxr_divide_proc_int32", cysoxr_divide_proc<int32_t>);
m.def("cysoxr_divide_proc_int16", cysoxr_divide_proc<int16_t>);

m.def("cysoxr_oneshot_float32", cysoxr_oneshot<float>);
m.def("cysoxr_oneshot_float64", cysoxr_oneshot<double>);
m.def("cysoxr_oneshot_int32", cysoxr_oneshot<int32_t>);
m.def("cysoxr_oneshot_int16", cysoxr_oneshot<int16_t>);
.def("process_float32", &CSoxr::process<float>)
.def("process_float64", &CSoxr::process<double>)
.def("process_int32", &CSoxr::process<int32_t>)
.def("process_int16", &CSoxr::process<int16_t>)
.def("num_clips", &CSoxr::num_clips)
.def("delay", &CSoxr::delay)
.def("engine", &CSoxr::engine)
.def("clear", &CSoxr::clear);

m.def("csoxr_divide_proc_float32", csoxr_divide_proc<float>);
m.def("csoxr_divide_proc_float64", csoxr_divide_proc<double>);
m.def("csoxr_divide_proc_int32", csoxr_divide_proc<int32_t>);
m.def("csoxr_divide_proc_int16", csoxr_divide_proc<int16_t>);

m.def("csoxr_oneshot_float32", csoxr_oneshot<float>);
m.def("csoxr_oneshot_float64", csoxr_oneshot<double>);
m.def("csoxr_oneshot_int32", csoxr_oneshot<int32_t>);
m.def("csoxr_oneshot_int16", csoxr_oneshot<int16_t>);

nb::enum_<soxr_datatype_t>(m, "soxr_datatype_t")
.value("SOXR_FLOAT32_I", SOXR_FLOAT32_I)
Expand Down

0 comments on commit 36b07de

Please sign in to comment.