mirror of
https://github.com/google/liblc3.git
synced 2026-04-17 21:25:30 +00:00
attdet: Move to fixed point
This commit is contained in:
@@ -132,8 +132,8 @@ def check_unit(rng, dt, sr):
|
||||
|
||||
### Generate noise, and an attack at random point
|
||||
|
||||
x = (2 * rng.random(ns)) - 1
|
||||
x[(ns * rng.random()).astype(int)] *= 100
|
||||
x = ((2 * rng.random(ns)) - 1) * (2 ** 8 - 1)
|
||||
x[(ns * rng.random()).astype(int)] *= 2 ** 7
|
||||
|
||||
### Check Implementation
|
||||
|
||||
@@ -143,8 +143,8 @@ def check_unit(rng, dt, sr):
|
||||
f_att_c = lc3.attdet_run(dt, sr, 100, state_c, x_c)
|
||||
|
||||
ok = ok and f_att_c == f_att
|
||||
ok = ok and np.amax(np.abs(1 - state_c['en1']/attdet.en1)) < 1e-6
|
||||
ok = ok and np.amax(np.abs(1 - state_c['an1']/attdet.an1)) < 1e-6
|
||||
ok = ok and np.amax(np.abs(1 - state_c['en1']/attdet.en1)) < 2
|
||||
ok = ok and np.amax(np.abs(1 - state_c['an1']/attdet.an1)) < 2
|
||||
ok = ok and state_c['p_att'] == attdet.p_att
|
||||
|
||||
return ok
|
||||
|
||||
@@ -27,7 +27,7 @@ static PyObject *attdet_run_py(PyObject *m, PyObject *args)
|
||||
unsigned dt, sr, nbytes;
|
||||
PyObject *attdet_obj, *x_obj;
|
||||
struct lc3_attdet_analysis attdet = { 0 };
|
||||
float *x;
|
||||
int16_t *x;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "IIIOO",
|
||||
&dt, &sr, &nbytes, &attdet_obj, &x_obj))
|
||||
@@ -39,7 +39,7 @@ static PyObject *attdet_run_py(PyObject *m, PyObject *args)
|
||||
|
||||
int ns = LC3_NS(dt, sr);
|
||||
|
||||
CTYPES_CHECK("x", x_obj = to_1d_ptr(x_obj, NPY_FLOAT, ns+6, &x));
|
||||
CTYPES_CHECK("x", x_obj = to_1d_ptr(x_obj, NPY_INT16, ns+6, &x));
|
||||
|
||||
int att = lc3_attdet_run(dt, sr, nbytes, &attdet, x+6);
|
||||
|
||||
|
||||
@@ -201,10 +201,10 @@ static PyObject *to_attdet_analysis(
|
||||
CTYPES_CHECK("attdet", obj && PyDict_Check(obj));
|
||||
|
||||
CTYPES_CHECK("attdet.en1", to_scalar(
|
||||
PyDict_GetItemString(obj, "en1"), NPY_FLOAT, &attdet->en1));
|
||||
PyDict_GetItemString(obj, "en1"), NPY_INT32, &attdet->en1));
|
||||
|
||||
CTYPES_CHECK("attdet.an1", to_scalar(
|
||||
PyDict_GetItemString(obj, "an1"), NPY_FLOAT, &attdet->an1));
|
||||
PyDict_GetItemString(obj, "an1"), NPY_INT32, &attdet->an1));
|
||||
|
||||
CTYPES_CHECK("attdet.p_att", to_scalar(
|
||||
PyDict_GetItemString(obj, "p_att"), NPY_INT, &attdet->p_att));
|
||||
@@ -219,10 +219,10 @@ static PyObject *from_attdet_analysis(
|
||||
if (!obj) obj = PyDict_New();
|
||||
|
||||
PyDict_SetItemString(obj, "en1",
|
||||
new_scalar(NPY_FLOAT, &attdet->en1));
|
||||
new_scalar(NPY_INT32, &attdet->en1));
|
||||
|
||||
PyDict_SetItemString(obj, "an1",
|
||||
new_scalar(NPY_FLOAT, &attdet->an1));
|
||||
new_scalar(NPY_INT32, &attdet->an1));
|
||||
|
||||
PyDict_SetItemString(obj, "p_att",
|
||||
new_scalar(NPY_INT, &attdet->p_att));
|
||||
|
||||
Reference in New Issue
Block a user