23#include <numpy/ndarrayobject.h>
28#define CTYPES_CHECK(exc, t) \
30 if (!(t)) return (exc) ? PyErr_Format(PyExc_TypeError, exc) : NULL; \
38#define to_scalar(obj, t, ptr) \
39 __to_scalar(obj, t, (void *)(ptr))
41#define to_1d_ptr(obj, t, n, ptr) \
42 __to_1d_ptr(obj, t, n, (void **)(ptr))
44#define to_2d_ptr(obj, t, n1, n2, ptr) \
45 __to_2d_ptr(obj, t, n1, n2, (void **)(ptr))
47#define to_1d_copy(obj, t, ptr, n) \
48 __to_1d_copy(obj, t, ptr, n)
50#define to_2d_copy(obj, t, ptr, n1, n2) \
51 __to_2d_copy(obj, t, ptr, n1, n2)
58#define new_scalar(obj, ptr) \
59 __new_scalar(obj, ptr)
61#define new_1d_ptr(t, n, ptr) \
62 __new_1d_ptr(t, n, (void **)(ptr))
64#define new_2d_ptr(t, n1, n2, ptr) \
65 __new_2d_ptr(t, n1, n2, (void **)(ptr))
67#define new_1d_copy(t, n, src) \
68 __new_1d_copy(t, n, src)
70#define new_2d_copy(t, n1, n2, src) \
71 __new_2d_copy(t, n1, n2, src)
77static PyObject *__to_scalar(PyObject *
obj,
int t,
void *
ptr)
79 obj =
obj ? PyArray_FROMANY(
obj,
t, 0, 0, NPY_ARRAY_FORCECAST) :
obj;
90static PyObject *__to_1d_ptr(PyObject *
obj,
int t,
int n,
void **
ptr)
93 t, 1, 1, NPY_ARRAY_FORCECAST|NPY_ARRAY_CARRAY) :
obj;
94 if (!
obj || (
n && PyArray_SIZE((PyArrayObject *)
obj) !=
n))
97 *
ptr = PyArray_DATA((PyArrayObject *)
obj);
102static PyObject *__to_2d_ptr(PyObject *
obj,
int t,
int n1,
int n2,
void **
ptr)
105 t, 2, 2, NPY_ARRAY_FORCECAST|NPY_ARRAY_CARRAY) :
obj;
106 if (!
obj || (
n1 && PyArray_DIMS((PyArrayObject *)
obj)[0] !=
n1)
107 || (
n2 && PyArray_DIMS((PyArrayObject *)
obj)[1] !=
n2))
110 *
ptr = PyArray_DATA((PyArrayObject *)
obj);
115static PyObject *__to_1d_copy(PyObject *
obj,
int t,
void *
v,
int n)
126static PyObject *__to_2d_copy(PyObject *
obj,
int t,
void *
v,
int n1,
int n2)
139static PyObject *__new_scalar(
int t,
const void *
ptr)
141 PyObject *
obj = PyArray_SimpleNew(0,
NULL,
t);
150static PyObject *__new_1d_ptr(
int t,
int n,
void **
ptr)
152 PyObject *
obj = PyArray_SimpleNew(1, (
const npy_intp []){
n },
t);
154 *
ptr = PyArray_DATA((PyArrayObject *)
obj);
159static PyObject *__new_2d_ptr(
int t,
int n1,
int n2,
void **
ptr)
163 obj = PyArray_SimpleNew(2, ((
const npy_intp []){
n1,
n2 }),
t);
165 *
ptr = PyArray_DATA((PyArrayObject *)
obj);
170static PyObject *__new_1d_copy(
int t,
int n,
const void *
src)
182static PyObject *__new_2d_copy(
int t,
int n1,
int n2,
const void *
src)
198static PyObject *to_attdet_analysis(
204 PyDict_GetItemString(
obj,
"en1"), NPY_INT32, &
attdet->en1));
207 PyDict_GetItemString(
obj,
"an1"), NPY_INT32, &
attdet->an1));
210 PyDict_GetItemString(
obj,
"p_att"), NPY_INT, &
attdet->p_att));
216static PyObject *from_attdet_analysis(
219 if (!
obj)
obj = PyDict_New();
238static PyObject *to_ltpf_hp50_state(
244 PyDict_GetItemString(
obj,
"s1"), NPY_INT64, &
hp50->s1));
247 PyDict_GetItemString(
obj,
"s2"), NPY_INT64, &
hp50->s2));
253static PyObject *from_ltpf_hp50_state(
266static PyObject *to_ltpf_analysis(
269 PyObject *nc_obj, *x_12k8_obj, *x_6k4_obj;
276 PyDict_GetItemString(
obj,
"active"), NPY_BOOL, &
ltpf->active));
279 PyDict_GetItemString(
obj,
"pitch"), NPY_INT, &
ltpf->pitch));
282 PyDict_GetItemString(
obj,
"nc"), NPY_FLOAT,
ltpf->nc, 2));
286 PyDict_GetItemString(
obj,
"hp50"), &
ltpf->hp50));
289 PyDict_GetItemString(
obj,
"x_12k8"), NPY_INT16,
ltpf->x_12k8,
n_12k8));
293 PyDict_GetItemString(
obj,
"x_6k4"), NPY_INT16,
ltpf->x_6k4,
n_6k4));
297 PyDict_GetItemString(
obj,
"tc"), NPY_INT, &
ltpf->tc));
303static PyObject *from_ltpf_analysis(
307 const int n_6k4 =
sizeof(
ltpf->x_6k4) /
sizeof(*
ltpf->x_6k4);
309 if (!
obj)
obj = PyDict_New();
321 from_ltpf_hp50_state(PyDict_New(), &
ltpf->hp50));
336static PyObject *to_ltpf_synthesis(
339 PyObject *c_obj, *x_obj;
344 PyDict_GetItemString(
obj,
"active"), NPY_BOOL, &
ltpf->active));
347 PyDict_GetItemString(
obj,
"pitch"), NPY_INT, &
ltpf->pitch));
350 PyDict_GetItemString(
obj,
"c"), NPY_FLOAT,
ltpf->c, 2*12));
354 PyDict_GetItemString(
obj,
"x"), NPY_FLOAT,
ltpf->x, 12));
361static PyObject *from_ltpf_synthesis(
364 if (!
obj)
obj = PyDict_New();
384 PyObject *
obj = PyDict_New();
396static PyObject *to_ltpf_data(
403 if ((item = PyDict_GetItemString(
obj,
"active")))
407 if ((item = PyDict_GetItemString(
obj,
"pitch_index")))
421 PyObject *
obj = PyDict_New();
457 if ((item = PyDict_GetItemString(
obj,
"lfcb")))
460 if ((item = PyDict_GetItemString(
obj,
"hfcb")))
463 if ((item = PyDict_GetItemString(
obj,
"shape")))
466 if ((item = PyDict_GetItemString(
obj,
"gain")))
469 if ((item = PyDict_GetItemString(
obj,
"idx_a")))
472 if ((item = PyDict_GetItemString(
obj,
"ls_a")))
475 if ((item = PyDict_GetItemString(
obj,
"idx_b")))
478 if ((item = PyDict_GetItemString(
obj,
"ls_b")))
491 PyObject *
obj = PyDict_New();
515 if ((item = PyDict_GetItemString(
obj,
"nfilters")))
519 if ((item = PyDict_GetItemString(
obj,
"lpc_weighting"))) {
524 if ((item = PyDict_GetItemString(
obj,
"rc_order"))) {
530 if ((item = PyDict_GetItemString(
obj,
"rc"))) {
544static PyObject *from_spec_analysis(
547 if (!
obj)
obj = PyDict_New();
559static PyObject *to_spec_analysis(
566 NPY_FLOAT, &
spec->nbits_off));
570 NPY_INT, &
spec->nbits_spare));
578 PyObject *
obj = PyDict_New();
593static PyObject *to_spec_data(
600 if ((item = PyDict_GetItemString(
obj,
"g_idx")))
604 if ((item = PyDict_GetItemString(
obj,
"nq")))
608 if ((item = PyDict_GetItemString(
obj,
"lsb_mode")))
622 PyObject *
obj = PyDict_New();
628 new_ltpf_data(&
side->ltpf));
631 new_sns_data(&
side->sns));
634 new_tns_data(&
side->tns));
646 if ((item = PyDict_GetItemString(
obj,
"bw"))) {
652 if ((item = PyDict_GetItemString(
obj,
"ltpf")))
653 to_ltpf_data(item, &
side->ltpf);
655 if ((item = PyDict_GetItemString(
obj,
"sns")))
656 to_sns_data(item, &
side->sns);
658 if ((item = PyDict_GetItemString(
obj,
"tns")))
659 to_tns_data(item, &
side->tns);
665static PyObject *new_plc_state(
const struct lc3_plc_state *plc)
667 PyObject *
obj = PyDict_New();
682static PyObject *to_plc_state(
688 PyDict_GetItemString(
obj,
"seed"), NPY_UINT16, &plc->
seed));
691 PyDict_GetItemString(
obj,
"count"), NPY_INT, &plc->
count));
694 PyDict_GetItemString(
obj,
"alpha"), NPY_FLOAT, &plc->
alpha));
700static PyObject *from_encoder(PyObject *
obj,
const struct lc3_encoder *enc)
702 unsigned dt =
enc->dt, sr =
enc->sr;
703 unsigned sr_pcm =
enc->sr_pcm;
704 int ns = lc3_ns(dt, sr);
705 int nd = lc3_nd(dt, sr);
708 if (!
obj)
obj = PyDict_New();
720 from_attdet_analysis(
NULL, &
enc->attdet));
723 from_ltpf_analysis(
NULL, &
enc->ltpf));
726 from_spec_analysis(
NULL, &
enc->spec));
730 (int16_t *)
enc->x +
enc->xt_off - nt));
742static PyObject *to_encoder(PyObject *
obj,
struct lc3_encoder *enc)
744 unsigned dt, sr, sr_pcm;
745 PyObject *xt_obj, *xs_obj, *xd_obj;
750 PyDict_GetItemString(
obj,
"dt"), NPY_INT, &dt));
754 PyDict_GetItemString(
obj,
"sr"), NPY_INT, &sr));
758 PyDict_GetItemString(
obj,
"sr_pcm"), NPY_INT, &sr_pcm));
762 int ns = lc3_ns(dt, sr);
763 int nd = lc3_nd(dt, sr);
767 PyDict_GetItemString(
obj,
"attdet"), &
enc->attdet));
770 PyDict_GetItemString(
obj,
"ltpf"), &
enc->ltpf));
773 PyDict_GetItemString(
obj,
"quant"), &
enc->spec));
776 PyDict_GetItemString(
obj,
"xt"), NPY_INT16,
777 (int16_t *)
enc->x +
enc->xt_off - nt, ns+nt));
781 PyDict_GetItemString(
obj,
"xs"), NPY_FLOAT,
782 enc->x +
enc->xs_off, ns));
786 PyDict_GetItemString(
obj,
"xd"), NPY_FLOAT,
787 enc->x +
enc->xd_off, nd));
794static PyObject *from_decoder(PyObject *
obj,
const struct lc3_decoder *dec)
796 unsigned dt =
dec->dt, sr =
dec->sr;
797 unsigned sr_pcm =
dec->sr_pcm;
798 unsigned xs_pos =
dec->xs_off -
dec->xh_off;
799 int nh = lc3_nh(dt, sr);
800 int ns = lc3_ns(dt, sr);
801 int nd = lc3_nd(dt, sr);
803 if (!
obj)
obj = PyDict_New();
815 from_ltpf_synthesis(
NULL, &
dec->ltpf));
818 new_plc_state(&
dec->plc));
836static PyObject *to_decoder(PyObject *
obj,
struct lc3_decoder *dec)
838 unsigned dt, sr, sr_pcm, xs_pos;
839 PyObject *xh_obj, *xd_obj, *xg_obj;
844 PyDict_GetItemString(
obj,
"dt"), NPY_INT, &dt));
848 PyDict_GetItemString(
obj,
"sr"), NPY_INT, &sr));
852 PyDict_GetItemString(
obj,
"sr_pcm"), NPY_INT, &sr_pcm));
856 int nh = lc3_nh(dt, sr);
857 int ns = lc3_ns(dt, sr);
858 int nd = lc3_nd(dt, sr);
861 PyDict_GetItemString(
obj,
"ltpf"), &
dec->ltpf));
864 PyDict_GetItemString(
obj,
"plc"), &
dec->plc));
867 PyDict_GetItemString(
obj,
"xh"), NPY_FLOAT,
868 dec->x +
dec->xh_off, nh + ns));
872 PyDict_GetItemString(
obj,
"xs_pos"), NPY_INT, &xs_pos));
873 dec->xs_off =
dec->xh_off + xs_pos;
876 PyDict_GetItemString(
obj,
"xd"), NPY_FLOAT,
877 dec->x +
dec->xd_off, nd));
881 PyDict_GetItemString(
obj,
"xg"), NPY_FLOAT,
882 dec->x +
dec->xg_off, ns));
#define to_2d_copy(obj, t, ptr, n1, n2)
#define new_2d_ptr(t, n1, n2, ptr)
PyArray_NBYTES((PyArrayObject *) obj))
#define to_scalar(obj, t, ptr)
struct lc3_ltpf_hp50_state * hp50
PyDict_SetItemString(obj, "en1", new_scalar(NPY_INT32, &attdet->en1))
struct lc3_tns_data * side
#define to_1d_ptr(obj, t, n, ptr)
#define new_1d_ptr(t, n, ptr)
#define new_scalar(obj, ptr)
const struct lc3_ltpf_data * data
#define new_2d_copy(t, n1, n2, src)
#define to_2d_ptr(obj, t, n1, n2, ptr)
#define to_1d_copy(obj, t, ptr, n)
#define new_1d_copy(t, n, src)
#define CTYPES_CHECK(exc, t)
#define unused(v)
Marking v as a unused parameter or value.
void __attribute__((noreturn))(*rom_reset_usb_boot_fn)(uint32_t
Reboot the device into BOOTSEL mode.