1 /******************************************************************************
2 *
3 * Copyright 2022 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 #include <Python.h>
20 #include <numpy/ndarrayobject.h>
21
22 #include <bwdet.c>
23 #include "ctypes.h"
24
bwdet_run_py(PyObject * m,PyObject * args)25 static PyObject *bwdet_run_py(PyObject *m, PyObject *args)
26 {
27 unsigned dt, sr;
28 PyObject *e_obj;
29 float *e;
30
31 if (!PyArg_ParseTuple(args, "IIO", &dt, &sr, &e_obj))
32 return NULL;
33
34 CTYPES_CHECK("dt", (unsigned)dt < LC3_NUM_DT);
35 CTYPES_CHECK("sr", (unsigned)sr < LC3_NUM_SRATE);
36 CTYPES_CHECK("e", to_1d_ptr(e_obj, NPY_FLOAT, LC3_NUM_BANDS, &e));
37
38 int bw = lc3_bwdet_run(dt, sr, e);
39
40 return Py_BuildValue("i", bw);
41 }
42
43 static PyMethodDef methods[] = {
44 { "bwdet_run", bwdet_run_py, METH_VARARGS },
45 { NULL },
46 };
47
lc3_bwdet_py_init(PyObject * m)48 PyMODINIT_FUNC lc3_bwdet_py_init(PyObject *m)
49 {
50 import_array();
51
52 PyModule_AddFunctions(m, methods);
53
54 return m;
55 }
56