Fixed printing messages from pd
This commit is contained in:
parent
50c1578f4d
commit
79dfff51fb
3 changed files with 28 additions and 18 deletions
33
src/gdpd.cpp
33
src/gdpd.cpp
|
|
@ -12,17 +12,21 @@ void Gdpd::_register_methods() {
|
||||||
register_method("add_symbol", &Gdpd::add_symbol);
|
register_method("add_symbol", &Gdpd::add_symbol);
|
||||||
register_method("add_float", &Gdpd::add_float);
|
register_method("add_float", &Gdpd::add_float);
|
||||||
register_method("finish_list", &Gdpd::finish_list);
|
register_method("finish_list", &Gdpd::finish_list);
|
||||||
|
register_method("set_volume", &Gdpd::set_volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Gdpd::audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData){
|
int Gdpd::audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData){
|
||||||
// pass audio samples to/from libpd
|
Gdpd* gdpd = static_cast<Gdpd*>(userData);
|
||||||
int ticks = nBufferFrames / 64;
|
int ticks = nBufferFrames / 64;
|
||||||
libpd_process_float(ticks, (float*)inputBuffer, (float*)outputBuffer);
|
gdpd->m_pd.processFloat(ticks, (float*)inputBuffer, (float*)outputBuffer);
|
||||||
|
gdpd->m_pd.receiveMessages();
|
||||||
|
for(int b=0; b<nBufferFrames; ++b) {
|
||||||
|
((float*)outputBuffer)[b]*=gdpd->get_volume();
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Gdpd::Gdpd(): m_vol(1) {
|
||||||
Gdpd::Gdpd() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gdpd::_init() {
|
void Gdpd::_init() {
|
||||||
|
|
@ -30,22 +34,16 @@ void Gdpd::_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Gdpd::~Gdpd() {
|
Gdpd::~Gdpd() {
|
||||||
// add your cleanup here
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Gdpd::init(int nbInputs, int nbOutputs, int sampleRate) {
|
int Gdpd::init(int nbInputs, int nbOutputs, int sampleRate) {
|
||||||
|
|
||||||
|
|
||||||
if(!m_pd.init(nbInputs, nbOutputs, sampleRate, true)) {
|
if(!m_pd.init(nbInputs, nbOutputs, sampleRate, true)) {
|
||||||
Godot::print("GDPD : Error starting libpd");
|
Godot::print("GDPD : Error starting libpd");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
libpd_set_verbose(1);
|
||||||
int bufsize = 128;
|
|
||||||
m_inBuf = new float[bufsize * nbInputs];
|
|
||||||
m_outBuf = new float[bufsize * nbOutputs];
|
|
||||||
*/
|
|
||||||
|
|
||||||
//create message array
|
//create message array
|
||||||
m_messages = new Array();
|
m_messages = new Array();
|
||||||
|
|
@ -79,7 +77,7 @@ int Gdpd::init(int nbInputs, int nbOutputs, int sampleRate) {
|
||||||
try {
|
try {
|
||||||
m_audio.openStream(&outParams, &inParams, RTAUDIO_FLOAT32,
|
m_audio.openStream(&outParams, &inParams, RTAUDIO_FLOAT32,
|
||||||
sr, &m_bufferFrames, &audioCallback,
|
sr, &m_bufferFrames, &audioCallback,
|
||||||
&m_pd, &options);
|
this, &options);
|
||||||
m_audio.startStream();
|
m_audio.startStream();
|
||||||
}
|
}
|
||||||
catch(RtAudioError& e) {
|
catch(RtAudioError& e) {
|
||||||
|
|
@ -87,7 +85,7 @@ int Gdpd::init(int nbInputs, int nbOutputs, int sampleRate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Godot::print("GDPD : Initialized");
|
print("Initialized");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -100,7 +98,7 @@ void Gdpd::openfile(godot::String baseStr, godot::String dirStr) {
|
||||||
|
|
||||||
libpd_openfile(baseS.c_str(), dirS.c_str());
|
libpd_openfile(baseS.c_str(), dirS.c_str());
|
||||||
|
|
||||||
Godot::print("GDPD : Opened patch");
|
print("Opened patch");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gdpd::closefile() {
|
void Gdpd::closefile() {
|
||||||
|
|
@ -150,7 +148,7 @@ int Gdpd::finish_list(String destStr) {
|
||||||
|
|
||||||
|
|
||||||
void Gdpd::print(const std::string& message) {
|
void Gdpd::print(const std::string& message) {
|
||||||
Godot::print(message.c_str());
|
Godot::print((std::string("GDPD : ")+message).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gdpd::receiveList(const std::string& dest, const pd::List& list) {
|
void Gdpd::receiveList(const std::string& dest, const pd::List& list) {
|
||||||
|
|
@ -168,3 +166,8 @@ void Gdpd::receiveList(const std::string& dest, const pd::List& list) {
|
||||||
|
|
||||||
m_messages->push_back(gdlist);
|
m_messages->push_back(gdlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Gdpd::set_volume(float vol) {
|
||||||
|
m_vol=vol;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ private:
|
||||||
pd::Patch m_patch;
|
pd::Patch m_patch;
|
||||||
RtAudio m_audio;
|
RtAudio m_audio;
|
||||||
unsigned int m_bufferFrames;
|
unsigned int m_bufferFrames;
|
||||||
|
float m_vol;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void _register_methods();
|
static void _register_methods();
|
||||||
|
|
@ -47,9 +48,15 @@ public:
|
||||||
int finish_list(String destStr);
|
int finish_list(String destStr);
|
||||||
|
|
||||||
//libpd hooks
|
//libpd hooks
|
||||||
void print(const std::string& message);
|
virtual void print(const std::string& message);
|
||||||
void receiveList(const std::string& dest, const pd::List& list);
|
void receiveList(const std::string& dest, const pd::List& list);
|
||||||
|
|
||||||
|
//godot functions
|
||||||
|
void set_volume(float vol);
|
||||||
|
inline const float& get_volume(){return m_vol;}
|
||||||
|
|
||||||
|
|
||||||
|
//rtaudio
|
||||||
static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData);
|
static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in a new issue