many updates

- libpd gui on/off by setting path
- computeaudio (pd dsp 0/1) added
- streamstart delayed to prevent pops
This commit is contained in:
Dooho Yi 2023-10-13 14:48:36 +09:00
parent 38de570162
commit d282c21cfd
11 changed files with 37 additions and 68 deletions

View file

@ -1,8 +0,0 @@
[gd_resource type="NativeScript" load_steps=2 format=2]
[ext_resource path="res://addons/gdpd/bin/libgdpd.gdnlib" type="GDNativeLibrary" id=1]
[resource]
resource_name = "gdpd"
class_name = "Gdpd"
library = ExtResource( 1 )

View file

@ -1,18 +0,0 @@
[general]
singleton=false
load_once=false
symbol_prefix="godot_"
reloadable=true
[entry]
X11.64="res://addons/gdpd/bin/x11/libgdpd.so"
Windows.64="res://addons/gdpd/bin/win/libgdpd.dll"
OSX.64="res://addons/gdpd/bin/osx/libgdpd.dylib"
[dependencies]
X11.64=[ ]
Windows.64=[ ]
OSX.64=[ ]

View file

@ -1,8 +0,0 @@
[gd_resource type="NativeScript" load_steps=2 format=2]
[ext_resource path="res://addons/gdpd/bin/libgdpd.gdnlib" type="GDNativeLibrary" id=1]
[resource]
resource_name = "gdpd"
class_name = "Gdpd"
library = ExtResource( 1 )

View file

@ -1,18 +0,0 @@
[general]
singleton=false
load_once=false
symbol_prefix="godot_"
reloadable=true
[entry]
X11.64="res://addons/gdpd/bin/x11/libgdpd.so"
Windows.64="res://addons/gdpd/bin/win/libgdpd.dll"
OSX.64="res://addons/gdpd/bin/osx/libgdpd.dylib"
[dependencies]
X11.64=[ ]
Windows.64=[ ]
OSX.64=[ ]

Binary file not shown.

View file

@ -7,6 +7,7 @@ void Gdpd::_register_methods() {
register_method("get_available_output_devices", &Gdpd::get_available_output_devices);
register_method("init_devices", &Gdpd::init_devices);
register_method("init", &Gdpd::init);
register_method("streamstart", &Gdpd::streamstart);
register_method("stop", &Gdpd::stop);
register_method("openPatch", &Gdpd::openPatch);
register_method("closePatch", &Gdpd::closePatch);
@ -17,7 +18,9 @@ void Gdpd::_register_methods() {
register_method("add_symbol", &Gdpd::add_symbol);
register_method("add_float", &Gdpd::add_float);
register_method("finish_list", &Gdpd::finish_list);
register_method("computeAudio", &Gdpd::computeAudio);
register_method("set_volume", &Gdpd::set_volume);
register_method("set_gui_path", &Gdpd::set_gui_path);
}
int Gdpd::audioCallback(void *outputBuffer, void *inputBuffer,
@ -29,7 +32,7 @@ int Gdpd::audioCallback(void *outputBuffer, void *inputBuffer,
return 0;
}
Gdpd::Gdpd() : m_vol(1) {
Gdpd::Gdpd() : m_vol(0), m_gui_path("") {
//create message array
m_messages = new Array();
m_init=false;
@ -117,12 +120,12 @@ int Gdpd::start() {
//libpd_set_verbose(1);
#if defined(WITH_GUI)
libpd_start_gui((char*)"/Applications/Pd-0.53-1.app/Contents/Resources");
#endif
if (m_gui_path != "") {
libpd_start_gui((char*)m_gui_path.c_str());
}
//start dsp
m_pd.computeAudio(true);
// m_pd.computeAudio(true);
//intialize rtaudio
if(m_audio.getDeviceCount()==0){
@ -140,8 +143,8 @@ int Gdpd::start() {
m_audio.openStream(&outParams, NULL, RTAUDIO_FLOAT32,
m_sampleRate, &m_bufferFrames, &audioCallback,
this, &options);
m_audio.startStream();
print("Stream started");
// m_audio.startStream();
// print("Stream started");
}
catch(RtAudioError& e) {
Godot::print(e.getMessage().c_str());
@ -151,8 +154,8 @@ int Gdpd::start() {
m_audio.openStream(&outParams, &inpParams, RTAUDIO_FLOAT32,
m_sampleRate, &m_bufferFrames, &audioCallback,
this, &options);
m_audio.startStream();
print("Stream started");
// m_audio.startStream();
// print("Stream started");
}
catch(RtAudioError& e) {
Godot::print(e.getMessage().c_str());
@ -169,15 +172,20 @@ int Gdpd::start() {
return 0;
}
void Gdpd::streamstart() {
m_audio.startStream();
print("Stream started");
}
void Gdpd::stop() {
m_audio.stopStream();
m_audio.closeStream();
m_pd.computeAudio(false);
print("Stopped");
#if defined(WITH_GUI)
libpd_stop_gui();
#endif
if (m_gui_path != "") {
libpd_stop_gui();
}
}
void Gdpd::processAudio(void *outputBuffer, void *inputBuffer,
@ -291,3 +299,14 @@ void Gdpd::receiveList(const std::string& dest, const pd::List& list) {
void Gdpd::set_volume(float vol) {
m_vol=vol;
}
void Gdpd::set_gui_path(godot::String pathStr) {
std::wstring pathWs = pathStr.unicode_str();
std::string pathS(pathWs.begin(), pathWs.end());
m_gui_path = pathS;
}
void Gdpd::computeAudio(bool state) { //[; pd dsp 0/1 (
m_pd.computeAudio(state);
}

View file

@ -13,8 +13,6 @@
#include "PdReceiver.hpp"
#include "RtAudio.h"
// #define WITH_GUI
namespace godot {
class Gdpd : public godot::AudioStreamPlayer, public pd::PdReceiver {
@ -35,6 +33,7 @@ private:
int m_inputDevice;
int m_outputDevice;
std::map<int, pd::Patch> m_patchsMap;
std::string m_gui_path;
bool m_init;
@ -52,6 +51,7 @@ public:
int init_devices(String inputDevice, String outputDevice);
int init(int nbInputs, int nbOutputs, int sampleRate, int bufferSize);
int start();
void streamstart();
void stop();
int openPatch(String basename, String dirname);
void closePatch(int id);
@ -69,6 +69,8 @@ public:
void receiveList(const std::string& dest, const pd::List& list);
//godot functions
void computeAudio(bool state); //[; pd dsp 0/1 (
void set_gui_path(godot::String path);
void set_volume(float vol);
inline const float& get_volume(){
return m_vol;

Binary file not shown.

View file

@ -1,6 +1,6 @@
#!/bin/bash
git submodule update --init --recursive
cd src/godot-cpp
scons platform=$1 generate_bindings=yes
scons platform=$1 target=$2 generate_bindings=yes
cd ../..
scons platform=$1
scons platform=$1 target=$2