mirror of
https://github.com/google/liblc3.git
synced 2026-06-02 01:47:02 +00:00
mdct: work on 2 input buffers, and remove 1 encoding buffer
This commit is contained in:
+8
-8
@@ -729,10 +729,10 @@ static PyObject *from_encoder(PyObject *obj, const struct lc3_encoder *enc)
|
||||
new_1d_copy(NPY_INT16, nt+ns, enc->xt-nt));
|
||||
|
||||
PyDict_SetItemString(obj, "xs",
|
||||
new_1d_copy(NPY_FLOAT, ns+nd, enc->xs-nd));
|
||||
new_1d_copy(NPY_FLOAT, ns, enc->xs));
|
||||
|
||||
PyDict_SetItemString(obj, "xf",
|
||||
new_1d_copy(NPY_FLOAT, ns, enc->xf));
|
||||
PyDict_SetItemString(obj, "xd",
|
||||
new_1d_copy(NPY_FLOAT, nd, enc->xd));
|
||||
|
||||
return obj;
|
||||
}
|
||||
@@ -741,7 +741,7 @@ __attribute__((unused))
|
||||
static PyObject *to_encoder(PyObject *obj, struct lc3_encoder *enc)
|
||||
{
|
||||
unsigned dt, sr, sr_pcm;
|
||||
PyObject *xt_obj, *xs_obj, *xf_obj;
|
||||
PyObject *xt_obj, *xs_obj, *xd_obj;
|
||||
|
||||
CTYPES_CHECK("encoder", obj && PyDict_Check(obj));
|
||||
|
||||
@@ -776,12 +776,12 @@ static PyObject *to_encoder(PyObject *obj, struct lc3_encoder *enc)
|
||||
PyDict_SetItemString(obj, "xt", xt_obj);
|
||||
|
||||
CTYPES_CHECK("encoder.xs", xs_obj = to_1d_copy(
|
||||
PyDict_GetItemString(obj, "xs"), NPY_FLOAT, enc->xs-nd, ns+nd));
|
||||
PyDict_GetItemString(obj, "xs"), NPY_FLOAT, enc->xs, ns));
|
||||
PyDict_SetItemString(obj, "xs", xs_obj);
|
||||
|
||||
CTYPES_CHECK("encoder.xf", xf_obj = to_1d_copy(
|
||||
PyDict_GetItemString(obj, "xf"), NPY_FLOAT, enc->xf, ns));
|
||||
PyDict_SetItemString(obj, "xf", xf_obj);
|
||||
CTYPES_CHECK("encoder.xd", xd_obj = to_1d_copy(
|
||||
PyDict_GetItemString(obj, "xd"), NPY_FLOAT, enc->xd, nd));
|
||||
PyDict_SetItemString(obj, "xd", xd_obj);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
+10
-8
@@ -99,11 +99,15 @@ def check_forward_unit(rng, dt, sr):
|
||||
|
||||
x = (2 * rng.random(ns)) - 1
|
||||
|
||||
mdct = MdctForward(dt, sr)
|
||||
y = [ mdct.run(x), mdct.run(x) ]
|
||||
y = [ None ] * 2
|
||||
y_c = [ None ] * 2
|
||||
|
||||
y_c = [ lc3.mdct_forward(dt, sr, np.append(np.zeros(nd), x)),
|
||||
lc3.mdct_forward(dt, sr, np.append(x[-nd:], x)) ]
|
||||
mdct = MdctForward(dt, sr)
|
||||
y[0] = mdct.run(x)
|
||||
y[1] = mdct.run(x)
|
||||
|
||||
(y_c[0], d_c) = lc3.mdct_forward(dt, sr, x, np.zeros(nd))
|
||||
y_c[1] = lc3.mdct_forward(dt, sr, x, d_c)[0]
|
||||
|
||||
ok = ok and np.amax(np.abs(y[0] - y_c[0])) < 1e-5
|
||||
ok = ok and np.amax(np.abs(y[1] - y_c[1])) < 1e-5
|
||||
@@ -118,12 +122,10 @@ def check_forward_appendix_c(dt):
|
||||
nd = T.ND[dt][sr]
|
||||
ok = True
|
||||
|
||||
y = lc3.mdct_forward(dt, sr,
|
||||
np.append(np.zeros(nd), C.X_PCM[dt][0]))
|
||||
(y, d) = lc3.mdct_forward(dt, sr, C.X_PCM[dt][0], np.zeros(nd))
|
||||
ok = ok and np.amax(np.abs(y - C.X[dt][0])) < 1e-1
|
||||
|
||||
y = lc3.mdct_forward(dt, sr,
|
||||
np.append(C.X_PCM[dt][0][-nd:], C.X_PCM[dt][1]))
|
||||
(y, d) = lc3.mdct_forward(dt, sr, C.X_PCM[dt][1], d)
|
||||
ok = ok and np.amax(np.abs(y - C.X[dt][1])) < 1e-1
|
||||
|
||||
return ok
|
||||
|
||||
+10
-6
@@ -25,12 +25,12 @@
|
||||
|
||||
static PyObject *mdct_forward_py(PyObject *m, PyObject *args)
|
||||
{
|
||||
PyObject *x_obj, *y_obj;
|
||||
PyObject *x_obj, *xd_obj, *y_obj, *d_obj;
|
||||
enum lc3_dt dt;
|
||||
enum lc3_srate sr;
|
||||
float *x, *y;
|
||||
float *x, *xd, *y, *d;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "iiO", &dt, &sr, &x_obj))
|
||||
if (!PyArg_ParseTuple(args, "iiOO", &dt, &sr, &x_obj, &xd_obj))
|
||||
return NULL;
|
||||
|
||||
CTYPES_CHECK("dt", (unsigned)dt < LC3_NUM_DT);
|
||||
@@ -38,12 +38,16 @@ static PyObject *mdct_forward_py(PyObject *m, PyObject *args)
|
||||
|
||||
int ns = LC3_NS(dt, sr), nd = LC3_ND(dt, sr);
|
||||
|
||||
CTYPES_CHECK("x", to_1d_ptr(x_obj, NPY_FLOAT, nd+ns, &x));
|
||||
CTYPES_CHECK("x", to_1d_ptr(x_obj, NPY_FLOAT, ns, &x));
|
||||
CTYPES_CHECK("xd", to_1d_ptr(xd_obj, NPY_FLOAT, nd, &xd));
|
||||
d_obj = new_1d_ptr(NPY_FLOAT, nd, &d);
|
||||
y_obj = new_1d_ptr(NPY_FLOAT, ns, &y);
|
||||
|
||||
lc3_mdct_forward(dt, sr, sr, x+nd, y);
|
||||
memcpy(d, xd, nd * sizeof(float));
|
||||
|
||||
return Py_BuildValue("N", y_obj);
|
||||
lc3_mdct_forward(dt, sr, sr, x, d, y);
|
||||
|
||||
return Py_BuildValue("NN", y_obj, d_obj);
|
||||
}
|
||||
|
||||
static PyObject *mdct_inverse_py(PyObject *m, PyObject *args)
|
||||
|
||||
Reference in New Issue
Block a user