xref: /btstack/3rd-party/lc3-google/test/attdet_py.c (revision 6897da5c53aac5b1f90f41b5b15d0bd43d61dfff)
14930cef6SMatthias Ringwald /******************************************************************************
24930cef6SMatthias Ringwald  *
34930cef6SMatthias Ringwald  *  Copyright 2022 Google LLC
44930cef6SMatthias Ringwald  *
54930cef6SMatthias Ringwald  *  Licensed under the Apache License, Version 2.0 (the "License");
64930cef6SMatthias Ringwald  *  you may not use this file except in compliance with the License.
74930cef6SMatthias Ringwald  *  You may obtain a copy of the License at:
84930cef6SMatthias Ringwald  *
94930cef6SMatthias Ringwald  *  http://www.apache.org/licenses/LICENSE-2.0
104930cef6SMatthias Ringwald  *
114930cef6SMatthias Ringwald  *  Unless required by applicable law or agreed to in writing, software
124930cef6SMatthias Ringwald  *  distributed under the License is distributed on an "AS IS" BASIS,
134930cef6SMatthias Ringwald  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
144930cef6SMatthias Ringwald  *  See the License for the specific language governing permissions and
154930cef6SMatthias Ringwald  *  limitations under the License.
164930cef6SMatthias Ringwald  *
174930cef6SMatthias Ringwald  ******************************************************************************/
184930cef6SMatthias Ringwald 
194930cef6SMatthias Ringwald #include <Python.h>
204930cef6SMatthias Ringwald #include <numpy/ndarrayobject.h>
214930cef6SMatthias Ringwald 
224930cef6SMatthias Ringwald #include <attdet.c>
234930cef6SMatthias Ringwald #include "ctypes.h"
244930cef6SMatthias Ringwald 
attdet_run_py(PyObject * m,PyObject * args)254930cef6SMatthias Ringwald static PyObject *attdet_run_py(PyObject *m, PyObject *args)
264930cef6SMatthias Ringwald {
274930cef6SMatthias Ringwald     unsigned dt, sr, nbytes;
284930cef6SMatthias Ringwald     PyObject *attdet_obj, *x_obj;
294930cef6SMatthias Ringwald     struct lc3_attdet_analysis attdet = { 0 };
304930cef6SMatthias Ringwald     int16_t *x;
314930cef6SMatthias Ringwald 
324930cef6SMatthias Ringwald     if (!PyArg_ParseTuple(args, "IIIOO",
334930cef6SMatthias Ringwald                 &dt, &sr, &nbytes, &attdet_obj, &x_obj))
344930cef6SMatthias Ringwald         return NULL;
354930cef6SMatthias Ringwald 
364930cef6SMatthias Ringwald     CTYPES_CHECK("dt", (unsigned)dt < LC3_NUM_DT);
374930cef6SMatthias Ringwald     CTYPES_CHECK("sr", (unsigned)sr < LC3_NUM_SRATE);
384930cef6SMatthias Ringwald     CTYPES_CHECK(NULL, attdet_obj = to_attdet_analysis(attdet_obj, &attdet));
394930cef6SMatthias Ringwald 
40*6897da5cSDirk Helbig     int ns = lc3_ns(dt, sr);
414930cef6SMatthias Ringwald 
424930cef6SMatthias Ringwald     CTYPES_CHECK("x", x_obj = to_1d_ptr(x_obj, NPY_INT16, ns+6, &x));
434930cef6SMatthias Ringwald 
444930cef6SMatthias Ringwald     int att = lc3_attdet_run(dt, sr, nbytes, &attdet, x+6);
454930cef6SMatthias Ringwald 
464930cef6SMatthias Ringwald     from_attdet_analysis(attdet_obj, &attdet);
474930cef6SMatthias Ringwald     return Py_BuildValue("i", att);
484930cef6SMatthias Ringwald }
494930cef6SMatthias Ringwald 
504930cef6SMatthias Ringwald static PyMethodDef methods[] = {
514930cef6SMatthias Ringwald     { "attdet_run", attdet_run_py, METH_VARARGS },
524930cef6SMatthias Ringwald     { NULL },
534930cef6SMatthias Ringwald };
544930cef6SMatthias Ringwald 
lc3_attdet_py_init(PyObject * m)554930cef6SMatthias Ringwald PyMODINIT_FUNC lc3_attdet_py_init(PyObject *m)
564930cef6SMatthias Ringwald {
574930cef6SMatthias Ringwald     import_array();
584930cef6SMatthias Ringwald 
594930cef6SMatthias Ringwald     PyModule_AddFunctions(m, methods);
604930cef6SMatthias Ringwald 
614930cef6SMatthias Ringwald     return m;
624930cef6SMatthias Ringwald }
63