debug
This commit is contained in:
parent
d1a3495378
commit
d556d8f294
|
@ -51,11 +51,32 @@ py::object create_numpy_array() {
|
||||||
|
|
||||||
return py::object(py::handle<>(py_array));
|
return py::object(py::handle<>(py_array));
|
||||||
}
|
}
|
||||||
|
py::object create_int16_array() {
|
||||||
|
// 1. 定义数组维度(1维,长度为 4)
|
||||||
|
npy_intp dims[1] = {4};
|
||||||
|
|
||||||
|
// 2. 创建原生 C 数组(int16_t 数据)
|
||||||
|
int16_t data[4] = {1, 2, -3, 4}; // 示例数据
|
||||||
|
|
||||||
|
// 3. 通过 NumPy C API 创建 PyObject*
|
||||||
|
PyObject* py_array = PyArray_SimpleNewFromData(
|
||||||
|
1, // 维度数
|
||||||
|
dims, // 各维度大小
|
||||||
|
NPY_INT16, // 数据类型(np.int16)
|
||||||
|
data // 数据指针
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!py_array) {
|
||||||
|
throw std::runtime_error("Failed to create NumPy array");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 转换为 py::object(自动管理引用计数)
|
||||||
|
return py::object(py::handle<>(py_array));
|
||||||
|
}
|
||||||
int sendCustomAudioData(const int16_t destChannelIndex, py::object pD, int32_t sampleRate, uint64_t channelNum,
|
int sendCustomAudioData(const int16_t destChannelIndex, py::object pD, int32_t sampleRate, uint64_t channelNum,
|
||||||
uint64_t dataLen) {
|
uint64_t dataLen) {
|
||||||
try {
|
try {
|
||||||
py::object pyData = create_numpy_array();
|
py::object pyData = create_int16_array();
|
||||||
std::cout << "step 1" << std::endl;
|
std::cout << "step 1" << std::endl;
|
||||||
// 1. 检查输入有效性
|
// 1. 检查输入有效性
|
||||||
if (pyData.ptr() == nullptr) {
|
if (pyData.ptr() == nullptr) {
|
||||||
|
|
Loading…
Reference in New Issue