Commit ca8a4cd2 authored by Pavel KORSHUNOV's avatar Pavel KORSHUNOV

Made API backward compatible

parent 386d8494
Pipeline #3906 failed with stage
in 23 minutes and 40 seconds
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
PyDoc_STRVAR(s_ceps_str, BOB_EXT_MODULE_PREFIX ".Ceps"); PyDoc_STRVAR(s_ceps_str, BOB_EXT_MODULE_PREFIX ".Ceps");
PyDoc_STRVAR(s_ceps_doc, PyDoc_STRVAR(s_ceps_doc,
"Ceps(sampling_frequency, [win_length_ms=20., [win_shift_ms=10., [normalize_mean=True, [n_filters=24, [n_ceps=19, [f_min=0., [f_max=4000., [delta_win=2, [pre_emphasis_coeff=0.95, [mel_scale=True, [dct_norm=True, [ssfc_features=False, [scfc_features=False, [scmc_features=False, [rect_filter=False, [inverse_filter=False, [normalize_spectrum=False]]]]]]]]]]]]]]]]]) -> new Ceps\n\ "Ceps(sampling_frequency, [win_length_ms=20., [win_shift_ms=10., [n_filters=24, [n_ceps=19, [f_min=0., [f_max=4000., [delta_win=2, [pre_emphasis_coeff=0.95, [mel_scale=True, [dct_norm=True, [normalize_mean=True, [rect_filter=False, [inverse_filter=False, [normalize_spectrum=False, [ssfc_features=False, [scfc_features=False, [scmc_features=False]]]]]]]]]]]]]]]]]) -> new Ceps\n\
Ceps(other) -> new Ceps\n\ Ceps(other) -> new Ceps\n\
\n\ \n\
Objects of this class, after configuration, can extract the\n\ Objects of this class, after configuration, can extract the\n\
...@@ -31,11 +31,6 @@ win_length_ms\n\ ...@@ -31,11 +31,6 @@ win_length_ms\n\
win_shift_ms\n\ win_shift_ms\n\
[float] the window shift in miliseconds\n\ [float] the window shift in miliseconds\n\
\n\ \n\
normalize_mean\n\
[bool] Tells whether frame should be normalized \n\
by subtracting mean (True) or dividing by max_range (False)\n\
``True`` is the default value.\n\
\n\
n_filters\n\ n_filters\n\
[int] the number of filter bands\n\ [int] the number of filter bands\n\
\n\ \n\
...@@ -63,20 +58,10 @@ mel_scale\n\ ...@@ -63,20 +58,10 @@ mel_scale\n\
dct_norm\n\ dct_norm\n\
[bool] A factor by which the cepstral coefficients are\n\ [bool] A factor by which the cepstral coefficients are\n\
multiplied\n\ multiplied\n\
ssfc_features\n\ normalize_mean\n\
[bool] Set to true if you want to compute\n\ [bool] Tells whether frame should be normalized \n\
Subband Spectral Flux Coefficients (SSFC), which measures\n\ by subtracting mean (True) or dividing by max_range (False)\n\
the frame-by-frame change in the power spectrum\n\ ``True`` is the default value.\n\
\n\
scfc_features\n\
[bool] Set to true if you want to compute\n\
Spectral Centroid Frequency Coefficients (SCFC), which\n\
capture detailed information about subbands similar to formant frequencies\n\
\n\
scmc_features\n\
[bool] Set to true if you want to compute\n\
Spectral Centroid Magnitude Coefficients (SCMC), which\n\
capture detailed information about subbands similar to SCFC features\n\
\n\ \n\
rect_filter\n\ rect_filter\n\
[bool] tells whether to apply the filter in the\n\ [bool] tells whether to apply the filter in the\n\
...@@ -92,6 +77,21 @@ normalize_spectrum\n\ ...@@ -92,6 +77,21 @@ normalize_spectrum\n\
[bool] Tells whether to normalize the power spectrum of the signal.\n\ [bool] Tells whether to normalize the power spectrum of the signal.\n\
The default value is ``False``.\n\ The default value is ``False``.\n\
\n\ \n\
ssfc_features\n\
[bool] Set to true if you want to compute\n\
Subband Spectral Flux Coefficients (SSFC), which measures\n\
the frame-by-frame change in the power spectrum\n\
\n\
scfc_features\n\
[bool] Set to true if you want to compute\n\
Spectral Centroid Frequency Coefficients (SCFC), which\n\
capture detailed information about subbands similar to formant frequencies\n\
\n\
scmc_features\n\
[bool] Set to true if you want to compute\n\
Spectral Centroid Magnitude Coefficients (SCMC), which\n\
capture detailed information about subbands similar to SCFC features\n\
\n\
other\n\ other\n\
[Ceps] an object of which is or inherits from ``Ceps``\n\ [Ceps] an object of which is or inherits from ``Ceps``\n\
that will be deep-copied into a new instance.\n\ that will be deep-copied into a new instance.\n\
...@@ -158,7 +158,6 @@ static int PyBobApCeps_InitParameters ...@@ -158,7 +158,6 @@ static int PyBobApCeps_InitParameters
"sampling_frequency", "sampling_frequency",
"win_length_ms", "win_length_ms",
"win_shift_ms", "win_shift_ms",
"normalize_mean",
"n_filters", "n_filters",
"n_ceps", "n_ceps",
"f_min", "f_min",
...@@ -166,10 +165,11 @@ static int PyBobApCeps_InitParameters ...@@ -166,10 +165,11 @@ static int PyBobApCeps_InitParameters
"delta_win", "delta_win",
"pre_emphasis_coeff", "pre_emphasis_coeff",
"mel_scale", "mel_scale",
"dct_norm",
"normalize_mean",
"rect_filter", "rect_filter",
"inverse_filter", "inverse_filter",
"normalize_spectrum", "normalize_spectrum",
"dct_norm",
"ssfc_features", "ssfc_features",
"scfc_features", "scfc_features",
"scmc_features", "scmc_features",
...@@ -179,7 +179,6 @@ static int PyBobApCeps_InitParameters ...@@ -179,7 +179,6 @@ static int PyBobApCeps_InitParameters
double sampling_frequency = 0.; double sampling_frequency = 0.;
double win_length_ms = 20.; double win_length_ms = 20.;
double win_shift_ms = 10.; double win_shift_ms = 10.;
PyObject* normalize_mean = Py_True;
Py_ssize_t n_filters = 24; Py_ssize_t n_filters = 24;
Py_ssize_t n_ceps = 19; Py_ssize_t n_ceps = 19;
double f_min = 0.; double f_min = 0.;
...@@ -187,35 +186,38 @@ static int PyBobApCeps_InitParameters ...@@ -187,35 +186,38 @@ static int PyBobApCeps_InitParameters
Py_ssize_t delta_win = 2; Py_ssize_t delta_win = 2;
double pre_emphasis_coeff = 0.95; double pre_emphasis_coeff = 0.95;
PyObject* mel_scale = Py_True; PyObject* mel_scale = Py_True;
PyObject* dct_norm = Py_False;
PyObject* normalize_mean = Py_True;
PyObject* rect_filter = Py_False; PyObject* rect_filter = Py_False;
PyObject* inverse_filter = Py_False; PyObject* inverse_filter = Py_False;
PyObject* normalize_spectrum = Py_False; PyObject* normalize_spectrum = Py_False;
PyObject* dct_norm = Py_False;
PyObject* ssfc_features = Py_False; PyObject* ssfc_features = Py_False;
PyObject* scfc_features = Py_False; PyObject* scfc_features = Py_False;
PyObject* scmc_features = Py_False; PyObject* scmc_features = Py_False;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "d|ddOnnddndOOOOOOOO", kwlist, if (!PyArg_ParseTupleAndKeywords(args, kwds, "d|ddnnddndOOOOOOOOO", kwlist,
&sampling_frequency, &win_length_ms, &win_shift_ms, &normalize_mean, &n_filters, &sampling_frequency, &win_length_ms, &win_shift_ms, &n_filters,
&n_ceps, &f_min, &f_max, &delta_win, &pre_emphasis_coeff, &n_ceps, &f_min, &f_max, &delta_win, &pre_emphasis_coeff,
&mel_scale, &rect_filter, &inverse_filter, &normalize_spectrum, &dct_norm, &mel_scale, &dct_norm, &normalize_mean, &rect_filter,
&inverse_filter, &normalize_spectrum,
&ssfc_features, &scfc_features, &scmc_features)) &ssfc_features, &scfc_features, &scmc_features))
return -1; return -1;
bool normalize_mean_ = PyObject_IsTrue(normalize_mean);
bool mel_scale_ = PyObject_IsTrue(mel_scale); bool mel_scale_ = PyObject_IsTrue(mel_scale);
bool dct_norm_ = PyObject_IsTrue(dct_norm);
bool normalize_mean_ = PyObject_IsTrue(normalize_mean);
bool rect_filter_ = PyObject_IsTrue(rect_filter); bool rect_filter_ = PyObject_IsTrue(rect_filter);
bool inverse_filter_ = PyObject_IsTrue(inverse_filter); bool inverse_filter_ = PyObject_IsTrue(inverse_filter);
bool normalize_spectrum_ = PyObject_IsTrue(normalize_spectrum); bool normalize_spectrum_ = PyObject_IsTrue(normalize_spectrum);
bool dct_norm_ = PyObject_IsTrue(dct_norm);
bool ssfc_features_ = PyObject_IsTrue(ssfc_features); bool ssfc_features_ = PyObject_IsTrue(ssfc_features);
bool scfc_features_ = PyObject_IsTrue(scfc_features); bool scfc_features_ = PyObject_IsTrue(scfc_features);
bool scmc_features_ = PyObject_IsTrue(scmc_features); bool scmc_features_ = PyObject_IsTrue(scmc_features);
try { try {
self->cxx = new bob::ap::Ceps(sampling_frequency, self->cxx = new bob::ap::Ceps(sampling_frequency,
win_length_ms, win_shift_ms, normalize_mean_, n_filters, n_ceps, f_min, f_max, win_length_ms, win_shift_ms, n_filters, n_ceps, f_min, f_max,
delta_win, pre_emphasis_coeff, mel_scale_, rect_filter_, inverse_filter_, normalize_spectrum_, delta_win, pre_emphasis_coeff, mel_scale_, dct_norm_, normalize_mean_,
dct_norm_, ssfc_features_, scfc_features_, scmc_features_); rect_filter_, inverse_filter_, normalize_spectrum_,
ssfc_features_, scfc_features_, scmc_features_);
if (!self->cxx) { if (!self->cxx) {
PyErr_Format(PyExc_MemoryError, "cannot create new object of type `%s' - no more memory", Py_TYPE(self)->tp_name); PyErr_Format(PyExc_MemoryError, "cannot create new object of type `%s' - no more memory", Py_TYPE(self)->tp_name);
return -1; return -1;
...@@ -286,7 +288,7 @@ static PyObject* PyBobApCeps_Repr(PyBobApCepsObject* self) { ...@@ -286,7 +288,7 @@ static PyObject* PyBobApCeps_Repr(PyBobApCepsObject* self) {
Py_ssize_t n_filters = self->cxx->getNFilters(); Py_ssize_t n_filters = self->cxx->getNFilters();
Py_ssize_t n_ceps = self->cxx->getNCeps(); Py_ssize_t n_ceps = self->cxx->getNCeps();
Py_ssize_t delta_win = self->cxx->getDeltaWin(); Py_ssize_t delta_win = self->cxx->getDeltaWin();
auto count = std::snprintf(buffer, MAXSIZE, "%s(sampling_frequency=%f, win_length_ms=%f, win_shift_ms=%f, normalize_mean=%s, n_filters=%" PY_FORMAT_SIZE_T "d, n_ceps=%" PY_FORMAT_SIZE_T "d, f_min=%f, f_max=%f, delta_win=%" PY_FORMAT_SIZE_T "d, pre_emphasis_coeff=%f, mel_scale=%s, rect_filter=%s, inverse_filter=%s, normalize_spectrum=%s, dct_norm=%s, ssfc_features=%s, scfc_features=%s, scmc_features=%s)", Py_TYPE(self)->tp_name, self->cxx->getSamplingFrequency(), self->cxx->getWinLengthMs(), self->cxx->getWinShiftMs(), self->cxx->getNormalizeMean()?"True":"False", n_filters, n_ceps, self->cxx->getFMin(), self->cxx->getFMax(), delta_win, self->cxx->getPreEmphasisCoeff(), self->cxx->getMelScale()?"True":"False", self->cxx->getRectangularFilter()?"True":"False", self->cxx->getInverseFilter()?"True":"False", self->cxx->getNormalizeSpectrum()?"True":"False", self->cxx->getDctNorm()?"True":"False", self->cxx->getSSFCFeatures()?"True":"False", self->cxx->getSCFCFeatures()?"True":"False", self->cxx->getSCMCFeatures()?"True":"False"); auto count = std::snprintf(buffer, MAXSIZE, "%s(sampling_frequency=%f, win_length_ms=%f, win_shift_ms=%f, n_filters=%" PY_FORMAT_SIZE_T "d, n_ceps=%" PY_FORMAT_SIZE_T "d, f_min=%f, f_max=%f, delta_win=%" PY_FORMAT_SIZE_T "d, pre_emphasis_coeff=%f, mel_scale=%s, dct_norm=%s, normalize_mean=%s, rect_filter=%s, inverse_filter=%s, normalize_spectrum=%s, ssfc_features=%s, scfc_features=%s, scmc_features=%s)", Py_TYPE(self)->tp_name, self->cxx->getSamplingFrequency(), self->cxx->getWinLengthMs(), self->cxx->getWinShiftMs(), n_filters, n_ceps, self->cxx->getFMin(), self->cxx->getFMax(), delta_win, self->cxx->getPreEmphasisCoeff(), self->cxx->getMelScale()?"True":"False", self->cxx->getDctNorm()?"True":"False", self->cxx->getNormalizeMean()?"True":"False", self->cxx->getRectangularFilter()?"True":"False", self->cxx->getInverseFilter()?"True":"False", self->cxx->getNormalizeSpectrum()?"True":"False", self->cxx->getSSFCFeatures()?"True":"False", self->cxx->getSCFCFeatures()?"True":"False", self->cxx->getSCMCFeatures()?"True":"False");
return return
# if PY_VERSION_HEX >= 0x03000000 # if PY_VERSION_HEX >= 0x03000000
PyUnicode_FromStringAndSize PyUnicode_FromStringAndSize
......
...@@ -15,14 +15,13 @@ ...@@ -15,14 +15,13 @@
bob::ap::Ceps::Ceps(const double sampling_frequency, bob::ap::Ceps::Ceps(const double sampling_frequency,
const double win_length_ms, const double win_shift_ms, const double win_length_ms, const double win_shift_ms,
const bool normalize_mean,
const size_t n_filters, const size_t n_ceps, const double f_min, const size_t n_filters, const size_t n_ceps, const double f_min,
const double f_max, const size_t delta_win, const double pre_emphasis_coeff, const double f_max, const size_t delta_win, const double pre_emphasis_coeff,
const bool mel_scale, const bool rect_filter, const bool inverse_filter, const bool normalize_spectrum, const bool mel_scale, const bool dct_norm, const bool normalize_mean,
const bool dct_norm, const bool ssfc_features, const bool rect_filter, const bool inverse_filter, const bool normalize_spectrum,
const bool scfc_features, const bool scmc_features): const bool ssfc_features, const bool scfc_features, const bool scmc_features):
bob::ap::Spectrogram(sampling_frequency, win_length_ms, win_shift_ms, normalize_mean, bob::ap::Spectrogram(sampling_frequency, win_length_ms, win_shift_ms, normalize_mean,
n_filters, f_min, f_max, pre_emphasis_coeff, mel_scale, rect_filter, inverse_filter, n_filters, f_min, f_max, pre_emphasis_coeff, mel_scale, normalize_mean, rect_filter, inverse_filter,
normalize_spectrum, ssfc_features, scfc_features, scmc_features), normalize_spectrum, ssfc_features, scfc_features, scmc_features),
m_n_ceps(n_ceps), m_delta_win(delta_win), m_dct_norm(dct_norm), m_n_ceps(n_ceps), m_delta_win(delta_win), m_dct_norm(dct_norm),
m_with_energy(false), m_with_delta(false), m_with_delta_delta(false) m_with_energy(false), m_with_delta(false), m_with_delta_delta(false)
......
...@@ -19,7 +19,8 @@ bob::ap::Energy::Energy(const double sampling_frequency, const double win_length ...@@ -19,7 +19,8 @@ bob::ap::Energy::Energy(const double sampling_frequency, const double win_length
} }
bob::ap::Energy::Energy(const bob::ap::Energy& other): bob::ap::Energy::Energy(const bob::ap::Energy& other):
bob::ap::FrameExtractor(other), m_energy_floor(1.) bob::ap::FrameExtractor(other),
m_energy_floor(other.m_energy_floor)
{ {
// Initializes logarithm of flooring values // Initializes logarithm of flooring values
m_log_energy_floor = log(m_energy_floor); m_log_energy_floor = log(m_energy_floor);
......
...@@ -61,7 +61,8 @@ bool bob::ap::FrameExtractor::operator==(const bob::ap::FrameExtractor& other) c ...@@ -61,7 +61,8 @@ bool bob::ap::FrameExtractor::operator==(const bob::ap::FrameExtractor& other) c
{ {
return (m_sampling_frequency == other.m_sampling_frequency && return (m_sampling_frequency == other.m_sampling_frequency &&
m_win_length_ms == other.m_win_length_ms && m_win_length_ms == other.m_win_length_ms &&
m_win_shift_ms == other.m_win_shift_ms); m_win_shift_ms == other.m_win_shift_ms &&
m_normalize_mean == other.m_normalize_mean);
} }
bool bob::ap::FrameExtractor::operator!=(const bob::ap::FrameExtractor& other) const bool bob::ap::FrameExtractor::operator!=(const bob::ap::FrameExtractor& other) const
......
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
bob::ap::Spectrogram::Spectrogram(const double sampling_frequency, bob::ap::Spectrogram::Spectrogram(const double sampling_frequency,
const double win_length_ms, const double win_shift_ms, const double win_length_ms, const double win_shift_ms,
const bool normalize_mean,
const size_t n_filters, const double f_min, const double f_max, const size_t n_filters, const double f_min, const double f_max,
const double pre_emphasis_coeff, const bool mel_scale, const double pre_emphasis_coeff, const bool mel_scale,
const bool rect_filter, const bool inverse_filter, const bool normalize_spectrum, const bool normalize_mean, const bool rect_filter,
const bool inverse_filter, const bool normalize_spectrum,
const bool ssfc_features, const bool scfc_features, const bool scmc_features): const bool ssfc_features, const bool scfc_features, const bool scmc_features):
bob::ap::Energy(sampling_frequency, win_length_ms, win_shift_ms), bob::ap::Energy(sampling_frequency, win_length_ms, win_shift_ms, normalize_mean),
m_n_filters(n_filters), m_f_min(f_min), m_f_max(f_max), m_n_filters(n_filters), m_f_min(f_min), m_f_max(f_max),
m_pre_emphasis_coeff(pre_emphasis_coeff), m_mel_scale(mel_scale), m_pre_emphasis_coeff(pre_emphasis_coeff), m_mel_scale(mel_scale),
m_rect_filter(rect_filter), m_inverse_filter(inverse_filter), m_rect_filter(rect_filter), m_inverse_filter(inverse_filter),
...@@ -51,7 +51,8 @@ bob::ap::Spectrogram::Spectrogram(const Spectrogram& other): ...@@ -51,7 +51,8 @@ bob::ap::Spectrogram::Spectrogram(const Spectrogram& other):
bob::ap::Energy(other), m_n_filters(other.m_n_filters), bob::ap::Energy(other), m_n_filters(other.m_n_filters),
m_f_min(other.m_f_min), m_f_max(other.m_f_max), m_f_min(other.m_f_min), m_f_max(other.m_f_max),
m_pre_emphasis_coeff(other.m_pre_emphasis_coeff), m_pre_emphasis_coeff(other.m_pre_emphasis_coeff),
m_mel_scale(other.m_mel_scale), m_rect_filter(other.m_rect_filter), m_mel_scale(other.m_mel_scale),
m_rect_filter(other.m_rect_filter),
m_inverse_filter(other.m_inverse_filter), m_inverse_filter(other.m_inverse_filter),
m_normalize_spectrum(other.m_normalize_spectrum), m_normalize_spectrum(other.m_normalize_spectrum),
m_ssfc_features(other.m_ssfc_features), m_ssfc_features(other.m_ssfc_features),
......
...@@ -47,9 +47,11 @@ class Ceps: public Spectrogram ...@@ -47,9 +47,11 @@ class Ceps: public Spectrogram
const size_t n_ceps=19, const double f_min=0., const size_t n_ceps=19, const double f_min=0.,
const double f_max=4000., const size_t delta_win=2, const double f_max=4000., const size_t delta_win=2,
const double pre_emphasis_coef=0.95, const bool mel_scale=true, const double pre_emphasis_coef=0.95, const bool mel_scale=true,
const bool dct_norm=false, const bool normalize_mean=true,
const bool rect_filter=false, const bool inverse_filter=false, const bool rect_filter=false, const bool inverse_filter=false,
const bool dct_norm=false, const bool ssfc_features=false, const bool normalize_spectrum=false,
const bool scfc_features=false, const bool scmc_features=false, bool normalize_spectrum=false); const bool ssfc_features=false, const bool scfc_features=false,
const bool scmc_features=false);
/** /**
* @brief Copy constructor. * @brief Copy constructor.
......
...@@ -41,10 +41,10 @@ class Spectrogram: public Energy ...@@ -41,10 +41,10 @@ class Spectrogram: public Energy
*/ */
Spectrogram(const double sampling_frequency, Spectrogram(const double sampling_frequency,
const double win_length_ms=20., const double win_shift_ms=10., const double win_length_ms=20., const double win_shift_ms=10.,
const bool normalize_mean=true,
const size_t n_filters=24, const double f_min=0., const size_t n_filters=24, const double f_min=0.,
const double f_max=8000., const double pre_emphasis_coeff=0.95, const double f_max=8000., const double pre_emphasis_coeff=0.95,
const bool mel_scale=true, const bool rect_filter=false, const bool inverse_filter=false, const bool mel_scale=true, const bool normalize_mean=true,
const bool rect_filter=false, const bool inverse_filter=false,
const bool normalize_spectrum=false, const bool ssfc_features=false, const bool normalize_spectrum=false, const bool ssfc_features=false,
const bool scfc_features=false, const bool scmc_features=false); const bool scfc_features=false, const bool scmc_features=false);
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
PyDoc_STRVAR(s_spectrogram_str, BOB_EXT_MODULE_PREFIX ".Spectrogram"); PyDoc_STRVAR(s_spectrogram_str, BOB_EXT_MODULE_PREFIX ".Spectrogram");
PyDoc_STRVAR(s_spectrogram_doc, PyDoc_STRVAR(s_spectrogram_doc,
"Spectrogram(sampling_frequency, [win_length_ms=20., [win_shift_ms=10., [normalize_mean=True, [n_filters=24, [f_min=0., [f_max=4000., [pre_emphasis_coeff=0.95, [mel_scale=True, [rect_filter=False, [inverse_filter=False, [normalize_spectrum=False, [ssfc_features=False, [scfc_features=False, [scmc_features=False]]]]]]]]]]]]]]) -> new Spectrogram\n\ "Spectrogram(sampling_frequency, [win_length_ms=20., [win_shift_ms=10., [n_filters=24, [f_min=0., [f_max=4000., [pre_emphasis_coeff=0.95, [mel_scale=True, [normalize_mean=True, [rect_filter=False, [inverse_filter=False, [normalize_spectrum=False, [ssfc_features=False, [scfc_features=False, [scmc_features=False]]]]]]]]]]]]]]) -> new Spectrogram\n\
Spectrogram(other) -> new Spectrogram\n\ Spectrogram(other) -> new Spectrogram\n\
\n\ \n\
Objects of this class, after configuration, can extract the\n\ Objects of this class, after configuration, can extract the\n\
...@@ -31,11 +31,6 @@ win_length_ms\n\ ...@@ -31,11 +31,6 @@ win_length_ms\n\
win_shift_ms\n\ win_shift_ms\n\
[float] the window shift in miliseconds\n\ [float] the window shift in miliseconds\n\
\n\ \n\
normalize_mean\n\
[bool] Tells whether frame should be normalized \n\
by subtracting mean (True) or dividing by max_range (False)\n\
``True`` is the default value.\n\
\n\
n_filters\n\ n_filters\n\
[int] the number of filter bands\n\ [int] the number of filter bands\n\
\n\ \n\
...@@ -53,6 +48,11 @@ mel_scale\n\ ...@@ -53,6 +48,11 @@ mel_scale\n\
on a linear (LFCC, set it to ``False``) or Mel (MFCC,\n\ on a linear (LFCC, set it to ``False``) or Mel (MFCC,\n\
set it to ``True`` - the default)\n\ set it to ``True`` - the default)\n\
\n\ \n\
normalize_mean\n\
[bool] Tells whether frame should be normalized \n\
by subtracting mean (True) or dividing by max_range (False)\n\
``True`` is the default value.\n\
\n\
rect_filter\n\ rect_filter\n\
[bool] tells whether to apply the filter in the\n\ [bool] tells whether to apply the filter in the\n\
inversed order, i.e., from high frequencies to low\n\ inversed order, i.e., from high frequencies to low\n\
...@@ -146,12 +146,12 @@ static int PyBobApSpectrogram_InitParameters ...@@ -146,12 +146,12 @@ static int PyBobApSpectrogram_InitParameters
"sampling_frequency", "sampling_frequency",
"win_length_ms", "win_length_ms",
"win_shift_ms", "win_shift_ms",
"normalize_mean",
"n_filters", "n_filters",
"f_min", "f_min",
"f_max", "f_max",
"pre_emphasis_coeff", "pre_emphasis_coeff",
"mel_scale", "mel_scale",
"normalize_mean",
"rect_filter", "rect_filter",
"inverse_filter", "inverse_filter",
"normalize_spectrum", "normalize_spectrum",
...@@ -164,27 +164,27 @@ static int PyBobApSpectrogram_InitParameters ...@@ -164,27 +164,27 @@ static int PyBobApSpectrogram_InitParameters
double sampling_frequency = 0.; double sampling_frequency = 0.;
double win_length_ms = 20.; double win_length_ms = 20.;
double win_shift_ms = 10.; double win_shift_ms = 10.;
PyObject* normalize_mean = Py_True;
Py_ssize_t n_filters = 24; Py_ssize_t n_filters = 24;
double f_min = 0.; double f_min = 0.;
double f_max = 8000.; double f_max = 8000.;
double pre_emphasis_coeff = 0.95; double pre_emphasis_coeff = 0.95;
PyObject* mel_scale = Py_True; PyObject* mel_scale = Py_True;
PyObject* normalize_mean = Py_True;
PyObject* rect_filter = Py_False; PyObject* rect_filter = Py_False;
PyObject* inverse_filter = Py_False; PyObject* inverse_filter = Py_False;
PyObject* normalize_spectrum = Py_False; PyObject* normalize_spectrum = Py_False;
PyObject* ssfc_features = Py_False; PyObject* ssfc_features = Py_False;
PyObject* scfc_features = Py_False; PyObject* scfc_features = Py_False;
PyObject* scmc_features = Py_False; PyObject* scmc_features = Py_False;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "d|ddOndddOOOOOOO", kwlist, if (!PyArg_ParseTupleAndKeywords(args, kwds, "d|ddndddOOOOOOOO", kwlist,
&sampling_frequency, &win_length_ms, &win_shift_ms, &normalize_mean, &sampling_frequency, &win_length_ms, &win_shift_ms,
&n_filters, &f_min, &f_max, &pre_emphasis_coeff, &mel_scale, &n_filters, &f_min, &f_max, &pre_emphasis_coeff, &mel_scale,
&rect_filter, &inverse_filter, &normalize_spectrum, &normalize_mean, &rect_filter, &inverse_filter, &normalize_spectrum,
&ssfc_features, &scfc_features, &scmc_features)) &ssfc_features, &scfc_features, &scmc_features))
return -1; return -1;
bool normalize_mean_ = PyObject_IsTrue(normalize_mean);
bool mel_scale_ = PyObject_IsTrue(mel_scale); bool mel_scale_ = PyObject_IsTrue(mel_scale);
bool normalize_mean_ = PyObject_IsTrue(normalize_mean);
bool rect_filter_ = PyObject_IsTrue(rect_filter); bool rect_filter_ = PyObject_IsTrue(rect_filter);
bool inverse_filter_ = PyObject_IsTrue(inverse_filter); bool inverse_filter_ = PyObject_IsTrue(inverse_filter);
bool normalize_spectrum_ = PyObject_IsTrue(normalize_spectrum); bool normalize_spectrum_ = PyObject_IsTrue(normalize_spectrum);
...@@ -194,8 +194,9 @@ static int PyBobApSpectrogram_InitParameters ...@@ -194,8 +194,9 @@ static int PyBobApSpectrogram_InitParameters
try { try {
self->cxx = new bob::ap::Spectrogram(sampling_frequency, self->cxx = new bob::ap::Spectrogram(sampling_frequency,
win_length_ms, win_shift_ms, normalize_mean_, n_filters, f_min, f_max, win_length_ms, win_shift_ms, n_filters, f_min, f_max,
pre_emphasis_coeff, mel_scale_, rect_filter_, inverse_filter_, normalize_spectrum_, pre_emphasis_coeff, mel_scale_, normalize_mean_, rect_filter_,
inverse_filter_, normalize_spectrum_,
ssfc_features_, scfc_features_, scmc_features_); ssfc_features_, scfc_features_, scmc_features_);
if (!self->cxx) { if (!self->cxx) {
PyErr_Format(PyExc_MemoryError, "cannot create new object of type `%s' - no more memory", Py_TYPE(self)->tp_name); PyErr_Format(PyExc_MemoryError, "cannot create new object of type `%s' - no more memory", Py_TYPE(self)->tp_name);
...@@ -264,7 +265,7 @@ static PyObject* PyBobApSpectrogram_Repr(PyBobApSpectrogramObject* self) { ...@@ -264,7 +265,7 @@ static PyObject* PyBobApSpectrogram_Repr(PyBobApSpectrogramObject* self) {
static const int MAXSIZE = 256; static const int MAXSIZE = 256;
char buffer[MAXSIZE]; char buffer[MAXSIZE];
Py_ssize_t n_filters = self->cxx->getNFilters(); Py_ssize_t n_filters = self->cxx->getNFilters();
auto count = std::snprintf(buffer, MAXSIZE, "%s(sampling_frequency=%f, win_length_ms=%f, win_shift_ms=%f, normalize_mean=%s, n_filters=%" PY_FORMAT_SIZE_T "d, f_min=%f, f_max=%f, pre_emphasis_coeff=%f, mel_scale=%s, rect_filter=%s, inverse_filter=%s, normalize_spectrum=%s, ssfc_features=%s, scfc_features=%s, scmc_features=%s)", Py_TYPE(self)->tp_name, self->cxx->getSamplingFrequency(), self->cxx->getWinLengthMs(), self->cxx->getWinShiftMs(), self->cxx->getNormalizeMean()?"True":"False", n_filters, self->cxx->getFMin(), self->cxx->getFMax(), self->cxx->getPreEmphasisCoeff(), self->cxx->getMelScale()?"True":"False", self->cxx->getRectangularFilter()?"True":"False", self->cxx->getInverseFilter()?"True":"False", self->cxx->getNormalizeSpectrum()?"True":"False", self->cxx->getSSFCFeatures()?"True":"False", self->cxx->getSCFCFeatures()?"True":"False", self->cxx->getSCMCFeatures()?"True":"False"); auto count = std::snprintf(buffer, MAXSIZE, "%s(sampling_frequency=%f, win_length_ms=%f, win_shift_ms=%f,n_filters=%" PY_FORMAT_SIZE_T "d, f_min=%f, f_max=%f, pre_emphasis_coeff=%f, mel_scale=%s, normalize_mean=%s, rect_filter=%s, inverse_filter=%s, normalize_spectrum=%s, ssfc_features=%s, scfc_features=%s, scmc_features=%s)", Py_TYPE(self)->tp_name, self->cxx->getSamplingFrequency(), self->cxx->getWinLengthMs(), self->cxx->getWinShiftMs(), n_filters, self->cxx->getFMin(), self->cxx->getFMax(), self->cxx->getPreEmphasisCoeff(), self->cxx->getMelScale()?"True":"False", self->cxx->getNormalizeMean()?"True":"False", self->cxx->getRectangularFilter()?"True":"False", self->cxx->getInverseFilter()?"True":"False", self->cxx->getNormalizeSpectrum()?"True":"False", self->cxx->getSSFCFeatures()?"True":"False", self->cxx->getSCFCFeatures()?"True":"False", self->cxx->getSCMCFeatures()?"True":"False");
return return
# if PY_VERSION_HEX >= 0x03000000 # if PY_VERSION_HEX >= 0x03000000
PyUnicode_FromStringAndSize PyUnicode_FromStringAndSize
......
...@@ -75,12 +75,12 @@ values are the default ones: ...@@ -75,12 +75,12 @@ values are the default ones:
>>> win_length_ms = 20 # The window length of the cepstral analysis in milliseconds >>> win_length_ms = 20 # The window length of the cepstral analysis in milliseconds
>>> win_shift_ms = 10 # The window shift of the cepstral analysis in milliseconds >>> win_shift_ms = 10 # The window shift of the cepstral analysis in milliseconds
>>> n_filters = 24 # The number of filter bands >>> n_filters = 20 # The number of filter bands
>>> n_ceps = 19 # The number of cepstral coefficients >>> n_ceps = 20 # The number of cepstral coefficients
>>> f_min = 0. # The minimal frequency of the filter bank >>> f_min = 0. # The minimal frequency of the filter bank
>>> f_max = 4000. # The maximal frequency of the filter bank >>> f_max = 4000. # The maximal frequency of the filter bank
>>> delta_win = 2 # The integer delta value used for computing the first and second order derivatives >>> delta_win = 2 # The integer delta value used for computing the first and second order derivatives
>>> pre_emphasis_coef = 0.97 # The coefficient used for the pre-emphasis >>> pre_emphasis_coef = 1.0 # The coefficient used for the pre-emphasis
>>> dct_norm = True # A factor by which the cepstral coefficients are multiplied >>> dct_norm = True # A factor by which the cepstral coefficients are multiplied
>>> mel_scale = True # Tell whether cepstral features are extracted on a linear (LFCC) or Mel (MFCC) scale >>> mel_scale = True # Tell whether cepstral features are extracted on a linear (LFCC) or Mel (MFCC) scale
......
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