mirror of
https://github.com/google/liblc3.git
synced 2026-04-19 22:24:50 +00:00
ltpf: Move analysis to fixed point
This commit is contained in:
@@ -241,10 +241,10 @@ static PyObject *to_ltpf_hp50_state(
|
||||
CTYPES_CHECK("hp50", obj && PyDict_Check(obj));
|
||||
|
||||
CTYPES_CHECK("hp50.s1", to_scalar(
|
||||
PyDict_GetItemString(obj, "s1"), NPY_FLOAT, &hp50->s1));
|
||||
PyDict_GetItemString(obj, "s1"), NPY_INT64, &hp50->s1));
|
||||
|
||||
CTYPES_CHECK("hp50.s2", to_scalar(
|
||||
PyDict_GetItemString(obj, "s2"), NPY_FLOAT, &hp50->s2));
|
||||
PyDict_GetItemString(obj, "s2"), NPY_INT64, &hp50->s2));
|
||||
|
||||
return obj;
|
||||
}
|
||||
@@ -254,10 +254,10 @@ static PyObject *from_ltpf_hp50_state(
|
||||
PyObject *obj, const struct lc3_ltpf_hp50_state *hp50)
|
||||
{
|
||||
PyDict_SetItemString(obj, "s1",
|
||||
new_scalar(NPY_FLOAT, &hp50->s1));
|
||||
new_scalar(NPY_INT64, &hp50->s1));
|
||||
|
||||
PyDict_SetItemString(obj, "s2",
|
||||
new_scalar(NPY_FLOAT, &hp50->s2));
|
||||
new_scalar(NPY_INT64, &hp50->s2));
|
||||
|
||||
return obj;
|
||||
}
|
||||
@@ -267,8 +267,8 @@ static PyObject *to_ltpf_analysis(
|
||||
PyObject *obj, struct lc3_ltpf_analysis *ltpf)
|
||||
{
|
||||
PyObject *nc_obj, *x_12k8_obj, *x_6k4_obj;
|
||||
const int n_12k8 = sizeof(ltpf->x_12k8) / sizeof(float);
|
||||
const int n_6k4 = sizeof(ltpf->x_6k4) / sizeof(float);
|
||||
const int n_12k8 = sizeof(ltpf->x_12k8) / sizeof(*ltpf->x_12k8);
|
||||
const int n_6k4 = sizeof(ltpf->x_6k4) / sizeof(*ltpf->x_6k4);
|
||||
|
||||
CTYPES_CHECK("ltpf", obj && PyDict_Check(obj));
|
||||
|
||||
@@ -286,11 +286,11 @@ static PyObject *to_ltpf_analysis(
|
||||
PyDict_GetItemString(obj, "hp50"), <pf->hp50));
|
||||
|
||||
CTYPES_CHECK("ltpf.x_12k8", x_12k8_obj = to_1d_copy(
|
||||
PyDict_GetItemString(obj, "x_12k8"), NPY_FLOAT, ltpf->x_12k8, n_12k8));
|
||||
PyDict_GetItemString(obj, "x_12k8"), NPY_INT16, ltpf->x_12k8, n_12k8));
|
||||
PyDict_SetItemString(obj, "x_12k8", x_12k8_obj);
|
||||
|
||||
CTYPES_CHECK("ltpf.x_6k4", x_6k4_obj = to_1d_copy(
|
||||
PyDict_GetItemString(obj, "x_6k4"), NPY_FLOAT, ltpf->x_6k4, n_6k4));
|
||||
PyDict_GetItemString(obj, "x_6k4"), NPY_INT16, ltpf->x_6k4, n_6k4));
|
||||
PyDict_SetItemString(obj, "x_6k4", x_6k4_obj);
|
||||
|
||||
CTYPES_CHECK("ltpf.tc", to_scalar(
|
||||
@@ -303,8 +303,8 @@ __attribute__((unused))
|
||||
static PyObject *from_ltpf_analysis(
|
||||
PyObject *obj, const struct lc3_ltpf_analysis *ltpf)
|
||||
{
|
||||
const int n_12k8 = sizeof(ltpf->x_12k8) / sizeof(float);
|
||||
const int n_6k4 = sizeof(ltpf->x_6k4) / sizeof(float);
|
||||
const int n_12k8 = sizeof(ltpf->x_12k8) / sizeof(*ltpf->x_12k8);
|
||||
const int n_6k4 = sizeof(ltpf->x_6k4) / sizeof(*ltpf->x_6k4);
|
||||
|
||||
if (!obj) obj = PyDict_New();
|
||||
|
||||
@@ -321,10 +321,10 @@ static PyObject *from_ltpf_analysis(
|
||||
from_ltpf_hp50_state(PyDict_New(), <pf->hp50));
|
||||
|
||||
PyDict_SetItemString(obj, "x_12k8",
|
||||
new_1d_copy(NPY_FLOAT, n_12k8, <pf->x_12k8));
|
||||
new_1d_copy(NPY_INT16, n_12k8, <pf->x_12k8));
|
||||
|
||||
PyDict_SetItemString(obj, "x_6k4",
|
||||
new_1d_copy(NPY_FLOAT, n_6k4, <pf->x_6k4));
|
||||
new_1d_copy(NPY_INT16, n_6k4, <pf->x_6k4));
|
||||
|
||||
PyDict_SetItemString(obj, "tc",
|
||||
new_scalar(NPY_INT, <pf->tc));
|
||||
@@ -703,6 +703,7 @@ static PyObject *from_encoder(PyObject *obj, const struct lc3_encoder *enc)
|
||||
unsigned sr_pcm = enc->sr_pcm;
|
||||
int ns = LC3_NS(dt, sr);
|
||||
int nd = LC3_ND(dt, sr);
|
||||
int nt = LC3_NT(sr);
|
||||
|
||||
if (!obj) obj = PyDict_New();
|
||||
|
||||
@@ -724,6 +725,9 @@ static PyObject *from_encoder(PyObject *obj, const struct lc3_encoder *enc)
|
||||
PyDict_SetItemString(obj, "quant",
|
||||
from_spec_analysis(NULL, &enc->spec));
|
||||
|
||||
PyDict_SetItemString(obj, "xt",
|
||||
new_1d_copy(NPY_INT16, nt+ns, enc->xt-nt));
|
||||
|
||||
PyDict_SetItemString(obj, "xs",
|
||||
new_1d_copy(NPY_FLOAT, ns+nd, enc->xs-nd));
|
||||
|
||||
@@ -737,7 +741,7 @@ __attribute__((unused))
|
||||
static PyObject *to_encoder(PyObject *obj, struct lc3_encoder *enc)
|
||||
{
|
||||
unsigned dt, sr, sr_pcm;
|
||||
PyObject *xs_obj, *xf_obj;
|
||||
PyObject *xt_obj, *xs_obj, *xf_obj;
|
||||
|
||||
CTYPES_CHECK("encoder", obj && PyDict_Check(obj));
|
||||
|
||||
@@ -756,6 +760,7 @@ static PyObject *to_encoder(PyObject *obj, struct lc3_encoder *enc)
|
||||
|
||||
int ns = LC3_NS(dt, sr);
|
||||
int nd = LC3_ND(dt, sr);
|
||||
int nt = LC3_NT(sr);
|
||||
|
||||
CTYPES_CHECK(NULL, to_attdet_analysis(
|
||||
PyDict_GetItemString(obj, "attdet"), &enc->attdet));
|
||||
@@ -766,6 +771,10 @@ static PyObject *to_encoder(PyObject *obj, struct lc3_encoder *enc)
|
||||
CTYPES_CHECK(NULL, to_spec_analysis(
|
||||
PyDict_GetItemString(obj, "quant"), &enc->spec));
|
||||
|
||||
CTYPES_CHECK("encoder.xt", xt_obj = to_1d_copy(
|
||||
PyDict_GetItemString(obj, "xt"), NPY_INT16, enc->xt-nt, ns+nt));
|
||||
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_SetItemString(obj, "xs", xs_obj);
|
||||
@@ -782,8 +791,8 @@ static PyObject *from_decoder(PyObject *obj, const struct lc3_decoder *dec)
|
||||
{
|
||||
unsigned dt = dec->dt, sr = dec->sr;
|
||||
unsigned sr_pcm = dec->sr_pcm;
|
||||
unsigned xs_pos = dec->xs - dec->xr;
|
||||
int nr = LC3_NR(dt, sr);
|
||||
unsigned xs_pos = dec->xs - dec->xh;
|
||||
int nh = LC3_NH(dt, sr);
|
||||
int ns = LC3_NS(dt, sr);
|
||||
int nd = LC3_ND(dt, sr);
|
||||
|
||||
@@ -804,8 +813,8 @@ static PyObject *from_decoder(PyObject *obj, const struct lc3_decoder *dec)
|
||||
PyDict_SetItemString(obj, "plc",
|
||||
new_plc_state(&dec->plc));
|
||||
|
||||
PyDict_SetItemString(obj, "xr",
|
||||
new_1d_copy(NPY_FLOAT, nr, dec->xr));
|
||||
PyDict_SetItemString(obj, "xh",
|
||||
new_1d_copy(NPY_FLOAT, nh, dec->xh));
|
||||
|
||||
PyDict_SetItemString(obj, "xs_pos",
|
||||
new_scalar(NPY_INT, &xs_pos));
|
||||
@@ -823,7 +832,7 @@ __attribute__((unused))
|
||||
static PyObject *to_decoder(PyObject *obj, struct lc3_decoder *dec)
|
||||
{
|
||||
unsigned dt, sr, sr_pcm, xs_pos;
|
||||
PyObject *xr_obj, *xd_obj, *xg_obj;
|
||||
PyObject *xh_obj, *xd_obj, *xg_obj;
|
||||
|
||||
CTYPES_CHECK("decoder", obj && PyDict_Check(obj));
|
||||
|
||||
@@ -840,7 +849,7 @@ static PyObject *to_decoder(PyObject *obj, struct lc3_decoder *dec)
|
||||
CTYPES_CHECK("decoder.sr_pcm",
|
||||
(unsigned)(dec->sr_pcm = sr_pcm) < LC3_NUM_SRATE);
|
||||
|
||||
int nr = LC3_NR(dt, sr);
|
||||
int nh = LC3_NH(dt, sr);
|
||||
int ns = LC3_NS(dt, sr);
|
||||
int nd = LC3_ND(dt, sr);
|
||||
|
||||
@@ -850,13 +859,13 @@ static PyObject *to_decoder(PyObject *obj, struct lc3_decoder *dec)
|
||||
CTYPES_CHECK(NULL, to_plc_state(
|
||||
PyDict_GetItemString(obj, "plc"), &dec->plc));
|
||||
|
||||
CTYPES_CHECK("decoder.xr", xr_obj = to_1d_copy(
|
||||
PyDict_GetItemString(obj, "xr"), NPY_FLOAT, dec->xr, nr));
|
||||
PyDict_SetItemString(obj, "xr", xr_obj);
|
||||
CTYPES_CHECK("decoder.xh", xh_obj = to_1d_copy(
|
||||
PyDict_GetItemString(obj, "xh"), NPY_FLOAT, dec->xh, nh));
|
||||
PyDict_SetItemString(obj, "xh", xh_obj);
|
||||
|
||||
CTYPES_CHECK("decoder.xs", to_scalar(
|
||||
PyDict_GetItemString(obj, "xs_pos"), NPY_INT, &xs_pos));
|
||||
dec->xs = dec->xr + xs_pos;
|
||||
dec->xs = dec->xh + xs_pos;
|
||||
|
||||
CTYPES_CHECK("decoder.xd", xd_obj = to_1d_copy(
|
||||
PyDict_GetItemString(obj, "xd"), NPY_FLOAT, dec->xd, nd));
|
||||
|
||||
Reference in New Issue
Block a user