Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.ap
Commits
d35eccd1
Commit
d35eccd1
authored
Feb 17, 2014
by
André Anjos
💬
Browse files
Finish first implemenation of xbob.ap
parent
7053b7c8
Changes
6
Hide whitespace changes
Inline
Side-by-side
setup.py
View file @
d35eccd1
...
...
@@ -41,6 +41,7 @@ setup(
"xbob/ap/energy.cpp"
,
"xbob/ap/frame_extractor.cpp"
,
"xbob/ap/spectrogram.cpp"
,
"xbob/ap/ceps.cpp"
,
"xbob/ap/main.cpp"
,
],
packages
=
packages
,
...
...
xbob/ap/ceps.cpp
View file @
d35eccd1
...
...
@@ -71,9 +71,9 @@ int PyBobApCeps_Check(PyObject* o) {
static
void
PyBobApCeps_Delete
(
PyBobApCepsObject
*
o
)
{
o
->
parent
.
parent
.
parent
.
cxx
=
0
;
o
->
parent
.
parent
.
cxx
=
0
;
o
->
parent
.
cxx
=
0
;
o
->
parent
.
parent
.
parent
.
cxx
=
0
;
// FrameExtractor
o
->
parent
.
parent
.
cxx
=
0
;
// Energy
o
->
parent
.
cxx
=
0
;
// Spectrogram
delete
o
->
cxx
;
Py_TYPE
(
o
)
->
tp_free
((
PyObject
*
)
o
);
...
...
@@ -125,10 +125,13 @@ static int PyBobApCeps_InitParameters
"win_length_ms"
,
"win_shift_ms"
,
"n_filters"
,
"n_ceps"
,
"f_min"
,
"f_max"
,
"delta_win"
,
"pre_emphasis_coeff"
,
"mel_scale"
,
"dct_norm"
,
0
};
static
char
**
kwlist
=
const_cast
<
char
**>
(
const_kwlist
);
...
...
@@ -136,25 +139,31 @@ static int PyBobApCeps_InitParameters
double
win_length_ms
=
20.
;
double
win_shift_ms
=
10.
;
Py_ssize_t
n_filters
=
24
;
Py_ssize_t
n_ceps
=
19
;
double
f_min
=
0.
;
double
f_max
=
0.
;
double
pre_emphasis_coeff
=
0.
;
double
f_max
=
4000.
;
Py_ssize_t
delta_win
=
2
;
double
pre_emphasis_coeff
=
0.95
;
PyObject
*
mel_scale
=
Py_True
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"d|ddndddO"
,
kwlist
,
&
sampling_frequency
,
&
win_length_ms
,
&
win_shift_ms
,
&
n_filters
,
&
f_min
,
&
f_max
,
&
pre_emphasis_coeff
,
&
mel_scale
))
PyObject
*
dct_norm
=
Py_True
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"d|ddnnddndOO"
,
kwlist
,
&
sampling_frequency
,
&
win_length_ms
,
&
win_shift_ms
,
&
n_filters
,
&
n_ceps
,
&
f_min
,
&
f_max
,
&
delta_win
,
&
pre_emphasis_coeff
,
&
mel_scale
,
&
dct_norm
))
return
-
1
;
bool
mel_scale_
=
PyObject_IsTrue
(
mel_scale
);
bool
dct_norm_
=
PyObject_IsTrue
(
dct_norm
);
try
{
self
->
cxx
=
new
bob
::
ap
::
Ceps
(
sampling_frequency
,
win_length_ms
,
win_shift_ms
,
n_filters
,
f_min
,
f_max
,
pre_emphasis_coeff
,
mel_scale_
);
win_length_ms
,
win_shift_ms
,
n_filters
,
n_ceps
,
f_min
,
f_max
,
delta_win
,
pre_emphasis_coeff
,
mel_scale_
,
dct_norm_
);
if
(
!
self
->
cxx
)
{
PyErr_Format
(
PyExc_MemoryError
,
"cannot create new object of type `%s' - no more memory"
,
Py_TYPE
(
self
)
->
tp_name
);
return
-
1
;
}
self
->
parent
.
parent
.
parent
.
cxx
=
self
->
cxx
;
self
->
parent
.
parent
.
cxx
=
self
->
cxx
;
self
->
parent
.
cxx
=
self
->
cxx
;
}
...
...
@@ -215,14 +224,19 @@ static int PyBobApCeps_Init(PyBobApCepsObject* self,
}
static
PyObject
*
PyBobApCeps_Repr
(
PyBobApCepsObject
*
self
)
{
static
const
int
MAXSIZE
=
256
;
char
buffer
[
MAXSIZE
];
Py_ssize_t
n_filters
=
self
->
cxx
->
getNFilters
();
Py_ssize_t
n_ceps
=
self
->
cxx
->
getNCeps
();
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, 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)"
,
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"
);
return
# if PY_VERSION_HEX >= 0x03000000
PyUnicode_From
Format
PyUnicode_From
StringAndSize
# else
PyString_From
Format
PyString_From
StringAndSize
# endif
(
"%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)"
,
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"
);
(
buffer
,
(
count
<=
MAXSIZE
)
?
count
:
MAXSIZE
);
}
static
PyObject
*
PyBobApCeps_RichCompare
(
PyBobApCepsObject
*
self
,
...
...
@@ -252,21 +266,21 @@ static PyObject* PyBobApCeps_RichCompare (PyBobApCepsObject* self,
}
PyDoc_STRVAR
(
s_n_
filter
s_str
,
"n_
filter
s"
);
PyDoc_STRVAR
(
s_n_
filter
s_doc
,
"The number of
filter band
s"
PyDoc_STRVAR
(
s_n_
cep
s_str
,
"n_
cep
s"
);
PyDoc_STRVAR
(
s_n_
cep
s_doc
,
"The number of
cepstral coefficient
s"
);
static
PyObject
*
PyBobApCeps_GetN
Filter
s
static
PyObject
*
PyBobApCeps_GetN
Cep
s
(
PyBobApCepsObject
*
self
,
void
*
/*closure*/
)
{
return
Py_BuildValue
(
"n"
,
self
->
cxx
->
getN
Filter
s
());
return
Py_BuildValue
(
"n"
,
self
->
cxx
->
getN
Cep
s
());
}
static
int
PyBobApCeps_SetN
Filter
s
static
int
PyBobApCeps_SetN
Cep
s
(
PyBobApCepsObject
*
self
,
PyObject
*
o
,
void
*
/*closure*/
)
{
if
(
!
PyNumber_Check
(
o
))
{
PyErr_Format
(
PyExc_TypeError
,
"`%s' n_
filter
s can only be set using a number, not `%s'"
,
Py_TYPE
(
self
)
->
tp_name
,
Py_TYPE
(
o
)
->
tp_name
);
PyErr_Format
(
PyExc_TypeError
,
"`%s' n_
cep
s can only be set using a number, not `%s'"
,
Py_TYPE
(
self
)
->
tp_name
,
Py_TYPE
(
o
)
->
tp_name
);
return
-
1
;
}
...
...
@@ -274,14 +288,14 @@ static int PyBobApCeps_SetNFilters
if
(
PyErr_Occurred
())
return
-
1
;
try
{
self
->
cxx
->
setN
Filter
s
(
n
);
self
->
cxx
->
setN
Cep
s
(
n
);
}
catch
(
std
::
exception
&
ex
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
ex
.
what
());
return
-
1
;
}
catch
(...)
{
PyErr_Format
(
PyExc_RuntimeError
,
"cannot reset `n_
filter
s' of %s: unknown exception caught"
,
Py_TYPE
(
self
)
->
tp_name
);
PyErr_Format
(
PyExc_RuntimeError
,
"cannot reset `n_
cep
s' of %s: unknown exception caught"
,
Py_TYPE
(
self
)
->
tp_name
);
return
-
1
;
}
...
...
@@ -289,73 +303,37 @@ static int PyBobApCeps_SetNFilters
}
PyDoc_STRVAR
(
s_f_min_str
,
"f_min"
);
PyDoc_STRVAR
(
s_f_min_doc
,
"The minimum frequency of the filter bank"
PyDoc_STRVAR
(
s_delta_win_str
,
"delta_win"
);
PyDoc_STRVAR
(
s_delta_win_doc
,
"The integer delta value used for computing the first and
\n
\
second order derivatives"
);
static
PyObject
*
PyBobApCeps_Get
FM
in
static
PyObject
*
PyBobApCeps_Get
DeltaW
in
(
PyBobApCepsObject
*
self
,
void
*
/*closure*/
)
{
return
Py_BuildValue
(
"
d
"
,
self
->
cxx
->
get
FM
in
());
return
Py_BuildValue
(
"
n
"
,
self
->
cxx
->
get
DeltaW
in
());
}
static
int
PyBobApCeps_Set
FM
in
static
int
PyBobApCeps_Set
DeltaW
in
(
PyBobApCepsObject
*
self
,
PyObject
*
o
,
void
*
/*closure*/
)
{
if
(
!
PyNumber_Check
(
o
))
{
PyErr_Format
(
PyExc_TypeError
,
"`%s' f_min can only be set using a number, not `%s'"
,
Py_TYPE
(
self
)
->
tp_name
,
Py_TYPE
(
o
)
->
tp_name
);
return
-
1
;
}
double
d
=
PyFloat_AsDouble
(
o
);
if
(
PyErr_Occurred
())
return
-
1
;
try
{
self
->
cxx
->
setFMin
(
d
);
}
catch
(
std
::
exception
&
ex
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
ex
.
what
());
return
-
1
;
}
catch
(...)
{
PyErr_Format
(
PyExc_RuntimeError
,
"cannot reset `f_min' of %s: unknown exception caught"
,
Py_TYPE
(
self
)
->
tp_name
);
PyErr_Format
(
PyExc_TypeError
,
"`%s' delta_win can only be set using a number, not `%s'"
,
Py_TYPE
(
self
)
->
tp_name
,
Py_TYPE
(
o
)
->
tp_name
);
return
-
1
;
}
return
0
;
}
PyDoc_STRVAR
(
s_f_max_str
,
"f_max"
);
PyDoc_STRVAR
(
s_f_max_doc
,
"The maximum frequency of the filter bank"
);
static
PyObject
*
PyBobApCeps_GetFMax
(
PyBobApCepsObject
*
self
,
void
*
/*closure*/
)
{
return
Py_BuildValue
(
"d"
,
self
->
cxx
->
getFMax
());
}
static
int
PyBobApCeps_SetFMax
(
PyBobApCepsObject
*
self
,
PyObject
*
o
,
void
*
/*closure*/
)
{
if
(
!
PyNumber_Check
(
o
))
{
PyErr_Format
(
PyExc_TypeError
,
"`%s' f_max can only be set using a number, not `%s'"
,
Py_TYPE
(
self
)
->
tp_name
,
Py_TYPE
(
o
)
->
tp_name
);
return
-
1
;
}
double
d
=
PyFloat_AsDouble
(
o
);
Py_ssize_t
n
=
PyNumber_AsSsize_t
(
o
,
PyExc_OverflowError
);
if
(
PyErr_Occurred
())
return
-
1
;
try
{
self
->
cxx
->
set
FMax
(
d
);
self
->
cxx
->
set
DeltaWin
(
n
);
}
catch
(
std
::
exception
&
ex
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
ex
.
what
());
return
-
1
;
}
catch
(...)
{
PyErr_Format
(
PyExc_RuntimeError
,
"cannot reset `
f_max
' of %s: unknown exception caught"
,
Py_TYPE
(
self
)
->
tp_name
);
PyErr_Format
(
PyExc_RuntimeError
,
"cannot reset `
delta_win
' of %s: unknown exception caught"
,
Py_TYPE
(
self
)
->
tp_name
);
return
-
1
;
}
...
...
@@ -363,70 +341,32 @@ static int PyBobApCeps_SetFMax
}
PyDoc_STRVAR
(
s_
pre_emphasis_coeff_str
,
"pre_emphasis_coeff
"
);
PyDoc_STRVAR
(
s_
pre_emphasis_coeff
_doc
,
"
The coefficient used for the pre-emphasis
"
PyDoc_STRVAR
(
s_
dct_norm_str
,
"dct_norm
"
);
PyDoc_STRVAR
(
s_
dct_norm
_doc
,
"
A factor by which the cepstral coefficients are multiplied
"
);
static
PyObject
*
PyBobApCeps_Get
PreEmphasisCoeff
static
PyObject
*
PyBobApCeps_Get
DctNorm
(
PyBobApCepsObject
*
self
,
void
*
/*closure*/
)
{
return
Py_BuildValue
(
"d"
,
self
->
cxx
->
getPreEmphasisCoeff
());
}
static
int
PyBobApCeps_SetPreEmphasisCoeff
(
PyBobApCepsObject
*
self
,
PyObject
*
o
,
void
*
/*closure*/
)
{
if
(
!
PyNumber_Check
(
o
))
{
PyErr_Format
(
PyExc_TypeError
,
"`%s' pre_emphasis_coeff can only be set using a number, not `%s'"
,
Py_TYPE
(
self
)
->
tp_name
,
Py_TYPE
(
o
)
->
tp_name
);
return
-
1
;
}
double
d
=
PyFloat_AsDouble
(
o
);
if
(
PyErr_Occurred
())
return
-
1
;
try
{
self
->
cxx
->
setPreEmphasisCoeff
(
d
);
}
catch
(
std
::
exception
&
ex
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
ex
.
what
());
return
-
1
;
}
catch
(...)
{
PyErr_Format
(
PyExc_RuntimeError
,
"cannot reset `pre_emphasis_coeff' of %s: unknown exception caught"
,
Py_TYPE
(
self
)
->
tp_name
);
return
-
1
;
}
return
0
;
}
PyDoc_STRVAR
(
s_mel_scale_str
,
"mel_scale"
);
PyDoc_STRVAR
(
s_mel_scale_doc
,
"Tells whether cepstral features are extracted on a linear
\n
\
(LFCC) or Mel (MFCC) scale
\n
\
"
);
static
PyObject
*
PyBobApCeps_GetMelScale
(
PyBobApCepsObject
*
self
,
void
*
/*closure*/
)
{
if
(
self
->
cxx
->
getMelScale
())
Py_RETURN_TRUE
;
if
(
self
->
cxx
->
getDctNorm
())
Py_RETURN_TRUE
;
else
Py_RETURN_FALSE
;
}
static
int
PyBobApCeps_Set
MelScale
static
int
PyBobApCeps_Set
DctNorm
(
PyBobApCepsObject
*
self
,
PyObject
*
o
,
void
*
/*closure*/
)
{
bool
b
=
PyObject_IsTrue
(
o
);
if
(
PyErr_Occurred
())
return
-
1
;
try
{
self
->
cxx
->
set
MelScale
(
b
);
self
->
cxx
->
set
DctNorm
(
b
);
}
catch
(
std
::
exception
&
ex
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
ex
.
what
());
return
-
1
;
}
catch
(...)
{
PyErr_Format
(
PyExc_RuntimeError
,
"cannot reset `
mel_scale
' of %s: unknown exception caught"
,
Py_TYPE
(
self
)
->
tp_name
);
PyErr_Format
(
PyExc_RuntimeError
,
"cannot reset `
dct_norm
' of %s: unknown exception caught"
,
Py_TYPE
(
self
)
->
tp_name
);
return
-
1
;
}
...
...
@@ -434,32 +374,32 @@ static int PyBobApCeps_SetMelScale
}
PyDoc_STRVAR
(
s_energy_
filter_
str
,
"energy
_filter
"
);
PyDoc_STRVAR
(
s_energy_
filter_
doc
,
"Tells
whether
we
use
the energy o
r
the
square root of the energy
"
PyDoc_STRVAR
(
s_
with_
energy_str
,
"
with_
energy"
);
PyDoc_STRVAR
(
s_
with_
energy_doc
,
"Tells
if
we
add
the energy
t
o the
output feature
"
);
static
PyObject
*
PyBobApCeps_GetEnergy
Filter
static
PyObject
*
PyBobApCeps_Get
With
Energy
(
PyBobApCepsObject
*
self
,
void
*
/*closure*/
)
{
if
(
self
->
cxx
->
getEnergy
Filter
())
Py_RETURN_TRUE
;
if
(
self
->
cxx
->
get
With
Energy
())
Py_RETURN_TRUE
;
else
Py_RETURN_FALSE
;
}
static
int
PyBobApCeps_SetEnergy
Filter
static
int
PyBobApCeps_Set
With
Energy
(
PyBobApCepsObject
*
self
,
PyObject
*
o
,
void
*
/*closure*/
)
{
bool
b
=
PyObject_IsTrue
(
o
);
if
(
PyErr_Occurred
())
return
-
1
;
try
{
self
->
cxx
->
setEnergy
Filter
(
b
);
self
->
cxx
->
set
With
Energy
(
b
);
}
catch
(
std
::
exception
&
ex
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
ex
.
what
());
return
-
1
;
}
catch
(...)
{
PyErr_Format
(
PyExc_RuntimeError
,
"cannot reset `energy
_filter
' of %s: unknown exception caught"
,
Py_TYPE
(
self
)
->
tp_name
);
PyErr_Format
(
PyExc_RuntimeError
,
"cannot reset `
with_
energy' of %s: unknown exception caught"
,
Py_TYPE
(
self
)
->
tp_name
);
return
-
1
;
}
...
...
@@ -467,32 +407,32 @@ static int PyBobApCeps_SetEnergyFilter
}
PyDoc_STRVAR
(
s_
log_filter_str
,
"log_filter
"
);
PyDoc_STRVAR
(
s_
log_filter
_doc
,
"Tells
whether
we
use
the
log triangular filter or the triangular filter
"
PyDoc_STRVAR
(
s_
with_delta_str
,
"with_delta
"
);
PyDoc_STRVAR
(
s_
with_delta
_doc
,
"Tells
if
we
add
the
first derivatives to the output feature
"
);
static
PyObject
*
PyBobApCeps_Get
LogFilter
static
PyObject
*
PyBobApCeps_Get
WithDelta
(
PyBobApCepsObject
*
self
,
void
*
/*closure*/
)
{
if
(
self
->
cxx
->
get
LogFilter
())
Py_RETURN_TRUE
;
if
(
self
->
cxx
->
get
WithDelta
())
Py_RETURN_TRUE
;
else
Py_RETURN_FALSE
;
}
static
int
PyBobApCeps_Set
LogFilter
static
int
PyBobApCeps_Set
WithDelta
(
PyBobApCepsObject
*
self
,
PyObject
*
o
,
void
*
/*closure*/
)
{
bool
b
=
PyObject_IsTrue
(
o
);
if
(
PyErr_Occurred
())
return
-
1
;
try
{
self
->
cxx
->
set
LogFilter
(
b
);
self
->
cxx
->
set
WithDelta
(
b
);
}
catch
(
std
::
exception
&
ex
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
ex
.
what
());
return
-
1
;
}
catch
(...)
{
PyErr_Format
(
PyExc_RuntimeError
,
"cannot reset `
log_filter
' of %s: unknown exception caught"
,
Py_TYPE
(
self
)
->
tp_name
);
PyErr_Format
(
PyExc_RuntimeError
,
"cannot reset `
with_delta
' of %s: unknown exception caught"
,
Py_TYPE
(
self
)
->
tp_name
);
return
-
1
;
}
...
...
@@ -500,32 +440,32 @@ static int PyBobApCeps_SetLogFilter
}
PyDoc_STRVAR
(
s_
energy_bands_str
,
"energy_bands
"
);
PyDoc_STRVAR
(
s_
energy_bands
_doc
,
"Tells
whether we compute a ceps or energy bands
"
PyDoc_STRVAR
(
s_
with_delta_delta_str
,
"with_delta_delta
"
);
PyDoc_STRVAR
(
s_
with_delta_delta
_doc
,
"Tells
if we add the second derivatives to the output feature
"
);
static
PyObject
*
PyBobApCeps_Get
EnergyBands
static
PyObject
*
PyBobApCeps_Get
WithDeltaDelta
(
PyBobApCepsObject
*
self
,
void
*
/*closure*/
)
{
if
(
self
->
cxx
->
get
EnergyBands
())
Py_RETURN_TRUE
;
if
(
self
->
cxx
->
get
WithDeltaDelta
())
Py_RETURN_TRUE
;
else
Py_RETURN_FALSE
;
}
static
int
PyBobApCeps_Set
EnergyBands
static
int
PyBobApCeps_Set
WithDeltaDelta
(
PyBobApCepsObject
*
self
,
PyObject
*
o
,
void
*
/*closure*/
)
{
bool
b
=
PyObject_IsTrue
(
o
);
if
(
PyErr_Occurred
())
return
-
1
;
try
{
self
->
cxx
->
set
EnergyBands
(
b
);
self
->
cxx
->
set
WithDeltaDelta
(
b
);
}
catch
(
std
::
exception
&
ex
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
ex
.
what
());
return
-
1
;
}
catch
(...)
{
PyErr_Format
(
PyExc_RuntimeError
,
"cannot reset `
energy_bands
' of %s: unknown exception caught"
,
Py_TYPE
(
self
)
->
tp_name
);
PyErr_Format
(
PyExc_RuntimeError
,
"cannot reset `
with_delta_delta
' of %s: unknown exception caught"
,
Py_TYPE
(
self
)
->
tp_name
);
return
-
1
;
}
...
...
@@ -535,59 +475,45 @@ static int PyBobApCeps_SetEnergyBands
static
PyGetSetDef
PyBobApCeps_getseters
[]
=
{
{
s_n_filters_str
,
(
getter
)
PyBobApCeps_GetNFilters
,
(
setter
)
PyBobApCeps_SetNFilters
,
s_n_filters_doc
,
0
},
{
s_f_min_str
,
(
getter
)
PyBobApCeps_GetFMin
,
(
setter
)
PyBobApCeps_SetFMin
,
s_f_min_doc
,
0
},
{
s_f_max_str
,
(
getter
)
PyBobApCeps_GetFMax
,
(
setter
)
PyBobApCeps_SetFMax
,
s_f_max_doc
,
s_n_ceps_str
,
(
getter
)
PyBobApCeps_GetNCeps
,
(
setter
)
PyBobApCeps_SetNCeps
,
s_n_ceps_doc
,
0
},
{
s_
pre_emphasis_coeff
_str
,
(
getter
)
PyBobApCeps_Get
PreEmphasisCoeff
,
(
setter
)
PyBobApCeps_Set
PreEmphasisCoeff
,
s_
pre_emphasis_coeff
_doc
,
s_
delta_win
_str
,
(
getter
)
PyBobApCeps_Get
DeltaWin
,
(
setter
)
PyBobApCeps_Set
DeltaWin
,
s_
delta_win
_doc
,
0
},
{
s_
mel_scale
_str
,
(
getter
)
PyBobApCeps_Get
MelScale
,
(
setter
)
PyBobApCeps_Set
MelScale
,
s_
mel_scale
_doc
,
s_
dct_norm
_str
,
(
getter
)
PyBobApCeps_Get
DctNorm
,
(
setter
)
PyBobApCeps_Set
DctNorm
,
s_
dct_norm
_doc
,
0
},
{
s_energy_
filter_
str
,
(
getter
)
PyBobApCeps_GetEnergy
Filter
,
(
setter
)
PyBobApCeps_SetEnergy
Filter
,
s_energy_
filter_
doc
,
s_
with_
energy_str
,
(
getter
)
PyBobApCeps_Get
With
Energy
,
(
setter
)
PyBobApCeps_Set
With
Energy
,
s_
with_
energy_doc
,
0
},
{
s_
log_filter
_str
,
(
getter
)
PyBobApCeps_Get
LogFilter
,
(
setter
)
PyBobApCeps_Set
LogFilter
,
s_
log_filter
_doc
,
s_
with_delta
_str
,
(
getter
)
PyBobApCeps_Get
WithDelta
,
(
setter
)
PyBobApCeps_Set
WithDelta
,
s_
with_delta
_doc
,
0
},
{
s_
energy_bands
_str
,
(
getter
)
PyBobApCeps_Get
EnergyBands
,
(
setter
)
PyBobApCeps_Set
EnergyBands
,
s_
energy_bands
_doc
,
s_
with_delta_delta
_str
,
(
getter
)
PyBobApCeps_Get
WithDeltaDelta
,
(
setter
)
PyBobApCeps_Set
WithDeltaDelta
,
s_
with_delta_delta
_doc
,
0
},
{
0
}
/* Sentinel */
...
...
xbob/ap/energy.cpp
View file @
d35eccd1
...
...
@@ -165,13 +165,16 @@ static int PyBobApEnergy_Init(PyBobApEnergyObject* self,
}
static
PyObject
*
PyBobApEnergy_Repr
(
PyBobApEnergyObject
*
self
)
{
static
const
int
MAXSIZE
=
256
;
char
buffer
[
MAXSIZE
];
auto
count
=
std
::
snprintf
(
buffer
,
MAXSIZE
,
"%s(sampling_frequency=%f, win_length_ms=%f, win_shift_ms=%f)"
,
Py_TYPE
(
self
)
->
tp_name
,
self
->
cxx
->
getSamplingFrequency
(),
self
->
cxx
->
getWinLengthMs
(),
self
->
cxx
->
getWinShiftMs
());
return
# if PY_VERSION_HEX >= 0x03000000
PyUnicode_From
Format
PyUnicode_From
StringAndSize
# else
PyString_From
Format
PyString_From
StringAndSize
# endif
(
"%s(sampling_frequency=%f, win_length_ms=%f, win_shift_ms=%f)"
,
Py_TYPE
(
self
)
->
tp_name
,
self
->
cxx
->
getSamplingFrequency
(),
self
->
cxx
->
getWinLengthMs
(),
self
->
cxx
->
getWinShiftMs
()
);
(
buffer
,
(
count
<=
MAXSIZE
)
?
count
:
MAXSIZE
);
}
static
PyObject
*
PyBobApEnergy_RichCompare
(
PyBobApEnergyObject
*
self
,
...
...
xbob/ap/frame_extractor.cpp
View file @
d35eccd1
...
...
@@ -167,13 +167,16 @@ static int PyBobApFrameExtractor_Init(PyBobApFrameExtractorObject* self,
}
static
PyObject
*
PyBobApFrameExtractor_Repr
(
PyBobApFrameExtractorObject
*
self
)
{
static
const
int
MAXSIZE
=
256
;
char
buffer
[
MAXSIZE
];
auto
count
=
std
::
snprintf
(
buffer
,
MAXSIZE
,
"%s(sampling_frequency=%f, win_length_ms=%f, win_shift_ms=%f)"
,
Py_TYPE
(
self
)
->
tp_name
,
self
->
cxx
->
getSamplingFrequency
(),
self
->
cxx
->
getWinLengthMs
(),
self
->
cxx
->
getWinShiftMs
());
return
# if PY_VERSION_HEX >= 0x03000000
PyUnicode_From
Format
PyUnicode_From
StringAndSize
# else
PyString_From
Format
PyString_From
StringAndSize
# endif
(
"%s(sampling_frequency=%f, win_length_ms=%f, win_shift_ms=%f)"
,
Py_TYPE
(
self
)
->
tp_name
,
self
->
cxx
->
getSamplingFrequency
(),
self
->
cxx
->
getWinLengthMs
(),
self
->
cxx
->
getWinShiftMs
()
);
(
buffer
,
(
count
<=
MAXSIZE
)
?
count
:
MAXSIZE
);
}
static
PyObject
*
PyBobApFrameExtractor_RichCompare
(
PyBobApFrameExtractorObject
*
self
,
...
...
xbob/ap/spectrogram.cpp
View file @
d35eccd1
...
...
@@ -123,8 +123,8 @@ static int PyBobApSpectrogram_InitParameters
double
win_shift_ms
=
10.
;
Py_ssize_t
n_filters
=
24
;
double
f_min
=
0.
;
double
f_max
=
0.
;
double
pre_emphasis_coeff
=
0.
;
double
f_max
=
400
0.
;
double
pre_emphasis_coeff
=
0.
95
;
PyObject
*
mel_scale
=
Py_True
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"d|ddndddO"
,
kwlist
,
&
sampling_frequency
,
&
win_length_ms
,
&
win_shift_ms
,
...
...
@@ -201,14 +201,17 @@ static int PyBobApSpectrogram_Init(PyBobApSpectrogramObject* self,
}
static
PyObject
*
PyBobApSpectrogram_Repr
(
PyBobApSpectrogramObject
*
self
)
{
static
const
int
MAXSIZE
=
256
;
char
buffer
[
MAXSIZE
];
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, n_filters=%"
PY_FORMAT_SIZE_T
"d, f_min=%f, f_max=%f, pre_emphasis_coeff=%f, mel_scale=%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"
);
return
# if PY_VERSION_HEX >= 0x03000000
PyUnicode_From
Format
PyUnicode_From
StringAndSize
# else
PyString_From
Format
PyString_From
StringAndSize
# endif
(
"%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)"
,
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"
);
(
buffer
,
(
count
<=
MAXSIZE
)
?
count
:
MAXSIZE
);
}
static
PyObject
*
PyBobApSpectrogram_RichCompare
(
PyBobApSpectrogramObject
*
self
,
...
...
xbob/ap/test_ceps.py
View file @
d35eccd1
...
...
@@ -5,11 +5,11 @@
# Copyright (C) 2011-2013 Idiap Research Institute, Martigny, Switzerland
import
os
,
sys
import
unittest
import
numpy
import
array
import
math
import
time
import
nose.tools
from
.
import
Ceps
...
...
@@ -114,7 +114,7 @@ def dct_transform(filters, n_filters, dct_kernel, n_ceps, dct_norm):
return
ceps
def
cepstral_features_extraction
(
obj
,
rate_wavsample
,
win_length_ms
,
win_shift_ms
,
n_filters
,
n_ceps
,
dct_norm
,
f_min
,
f_max
,
delta_win
,
def
cepstral_features_extraction
(
rate_wavsample
,
win_length_ms
,
win_shift_ms
,
n_filters
,
n_ceps
,
dct_norm
,
f_min
,
f_max
,
delta_win
,
pre_emphasis_coef
,
mel_scale
,
with_energy
,
with_delta
,
with_delta_delta
):
#########################
## Initialisation part ##
...
...
@@ -341,7 +341,7 @@ def cepstral_features_extraction(obj, rate_wavsample, win_length_ms, win_shift_m
return
data
def
cepstral_comparison_run
(
obj
,
rate_wavsample
,
win_length_ms
,
win_shift_ms
,
n_filters
,
n_ceps
,
dct_norm
,
f_min
,
f_max
,
delta_win
,