From a67dd3d66041266f8e6d0da18b8cc6e2c996d93d Mon Sep 17 00:00:00 2001 From: lyk Date: Sun, 3 Nov 2024 22:21:50 +0800 Subject: [PATCH] support mono audio --- py_src/core.cpp | 30 ++++++++++++++++++++++++++++-- py_src/py_utils.h | 4 ---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/py_src/core.cpp b/py_src/core.cpp index 5e397a0..74c80fc 100644 --- a/py_src/core.cpp +++ b/py_src/core.cpp @@ -10,6 +10,7 @@ #include #include #include +#include "prestosynth/wav.h" #include "symusic.h" #include "py_utils.h" #include "MetaMacro.h" @@ -58,9 +59,34 @@ nb::module_& bind_synthesizer(nb::module_& m) { ); + // m.def( + // "dump_wav", + // &psynth::write_audio, + // nb::arg("path"), + // nb::arg("data"), + // nb::arg("sample_rate"), + // nb::arg("use_int16") = true + // ); + + m.def( - "dump_wav", - &psynth::write_audio, + "dump_wav",[]( + const std::string& path, + const nb::ndarray, nb::device::cpu>& data, + const i32 sample_rate, + const bool use_int16 + ){ + // show the shape of the data + std::cout << "data shape: " << data.shape(0) << " " << data.shape(1) << std::endl; + psynth::WAVE_write( + path, + data.shape(0), + data.shape(1), + sample_rate, + data.data(), + use_int16 + ); + }, nb::arg("path"), nb::arg("data"), nb::arg("sample_rate"), diff --git a/py_src/py_utils.h b/py_src/py_utils.h index 5208171..5b95c8e 100644 --- a/py_src/py_utils.h +++ b/py_src/py_utils.h @@ -11,10 +11,6 @@ #include "nanobind/operators.h" #include - - - - namespace pyutils { using namespace symusic;