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 <bwdet.c>
234930cef6SMatthias Ringwald #include "ctypes.h"
244930cef6SMatthias Ringwald
bwdet_run_py(PyObject * m,PyObject * args)254930cef6SMatthias Ringwald static PyObject *bwdet_run_py(PyObject *m, PyObject *args)
264930cef6SMatthias Ringwald {
274930cef6SMatthias Ringwald unsigned dt, sr;
284930cef6SMatthias Ringwald PyObject *e_obj;
294930cef6SMatthias Ringwald float *e;
304930cef6SMatthias Ringwald
314930cef6SMatthias Ringwald if (!PyArg_ParseTuple(args, "IIO", &dt, &sr, &e_obj))
324930cef6SMatthias Ringwald return NULL;
334930cef6SMatthias Ringwald
34*6897da5cSDirk Helbig CTYPES_CHECK("dt", dt < LC3_NUM_DT);
35*6897da5cSDirk Helbig CTYPES_CHECK("sr", sr < LC3_NUM_SRATE);
36*6897da5cSDirk Helbig CTYPES_CHECK("e", to_1d_ptr(e_obj, NPY_FLOAT, LC3_MAX_BANDS, &e));
374930cef6SMatthias Ringwald
384930cef6SMatthias Ringwald int bw = lc3_bwdet_run(dt, sr, e);
394930cef6SMatthias Ringwald
404930cef6SMatthias Ringwald return Py_BuildValue("i", bw);
414930cef6SMatthias Ringwald }
424930cef6SMatthias Ringwald
434930cef6SMatthias Ringwald static PyMethodDef methods[] = {
444930cef6SMatthias Ringwald { "bwdet_run", bwdet_run_py, METH_VARARGS },
454930cef6SMatthias Ringwald { NULL },
464930cef6SMatthias Ringwald };
474930cef6SMatthias Ringwald
lc3_bwdet_py_init(PyObject * m)484930cef6SMatthias Ringwald PyMODINIT_FUNC lc3_bwdet_py_init(PyObject *m)
494930cef6SMatthias Ringwald {
504930cef6SMatthias Ringwald import_array();
514930cef6SMatthias Ringwald
524930cef6SMatthias Ringwald PyModule_AddFunctions(m, methods);
534930cef6SMatthias Ringwald
544930cef6SMatthias Ringwald return m;
554930cef6SMatthias Ringwald }
56