diff --git a/src/Reveal.cpp b/src/Reveal.cpp index 9e8e981fb7783c09404e0acaeaac295fa9ca7b08..6ce5dddb9a021af57180764d6e1a86291e4eb693 100644 --- a/src/Reveal.cpp +++ b/src/Reveal.cpp @@ -59,6 +59,7 @@ #include "gui/GuiListener.hpp" #include "osc/OscManager.hpp" #include "osc/OscListener.hpp" +#include "audio/AudioManager.hpp" using namespace std; @@ -85,6 +86,13 @@ Reveal::Reveal() : GroupModule() { Attribute::ACTION_ATTRIBUTE, quitCallback, this, Attribute::LOCAL, false)); + + addAttribute(new Attribute("audio_output", + Attribute::BOOL_ATTRIBUTE, + audioOutputCallback,this,1,Attribute::GLOBAL)); + m_audioOut=false; + + /* addAttribute(new Attribute("ressources_folder", Attribute::FOLDER_OPEN_ATTRIBUTE, ressourcesCallback, this, Attribute::LOCAL, @@ -92,6 +100,7 @@ Reveal::Reveal() : GroupModule() { addAttribute(new Attribute("ressource_upload", Attribute::ACTION_STRING_ATTRIBUTE, uploadCallback,this,2,Attribute::GLOBAL,false)); + */ addAttribute(new Attribute("debug_osc_input", Attribute::BOOL_ATTRIBUTE, debugOscCallback,this,1,Attribute::GLOBAL)); @@ -192,6 +201,12 @@ GLFWwindow* Reveal::getPreviewWindow() { return m_preview->getWindow(); } +void Reveal::setAudioOutput(const bool& aud) { + if(aud) { + AudioManager::getInstance()->init(); + } +} + void Reveal::planOpen(std::string opSt) { //FIXME find better strategy for delaying text m_openPlanned=10; diff --git a/src/Reveal.hpp b/src/Reveal.hpp index a4937e57328b9c9a71fdb2abbe34db649377cb0f..a9d3561893d88b5163ae56f5133c8aaa9cf939a2 100644 --- a/src/Reveal.hpp +++ b/src/Reveal.hpp @@ -128,14 +128,18 @@ class Reveal : public GroupModule { dynamic_cast<Reveal*>(mod)->uploadRessource(vf); } void uploadRessource(const std::vector<std::string>& vf); - static void debugOscCallback(Module* mod, - const std::vector<bool>& vf - ) { + static void debugOscCallback(Module* mod, const std::vector<bool>& vf) { dynamic_cast<Reveal*>(mod)->debugOSC(vf[0]); } void debugOSC(const bool& deb){m_debugOSC=deb;} const bool& getDebugOSC() {return m_debugOSC;} + static void audioOutputCallback(Module* mod, + const std::vector<bool>& vf) { + dynamic_cast<Reveal*>(mod)->setAudioOutput(vf[0]); + } + void setAudioOutput(const bool& aud); + virtual void load(xmlNodePtr); void addUpdateObserver(Module* upObs); @@ -218,6 +222,7 @@ class Reveal : public GroupModule { PreviewModule* m_preview; OutputManagerModule* m_output; bool m_debugOSC; + bool m_audioOut; int m_openPlanned; std::string m_openPlannedName; diff --git a/src/audio/AudioManager.cpp b/src/audio/AudioManager.cpp index 90aec71eca791dad87cb8c45a1177d3b45eea20e..a3a139d8a34b26e09fbc87f989bdd0b0a0bd4151 100644 --- a/src/audio/AudioManager.cpp +++ b/src/audio/AudioManager.cpp @@ -78,7 +78,7 @@ int AudioManager::rtaudio_callback(void *outbuf, void *inbuf, unsigned int nFram } else { memset(buf, 0, nFrames*data->nChannel*sizeof(float)); - cout<<"AudioManager : Could not read buffer"<<endl; +// cout<<"AudioManager : Could not read buffer"<<endl; } } else { @@ -96,6 +96,10 @@ int AudioManager::rtaudio_callback(void *outbuf, void *inbuf, unsigned int nFram } AudioManager::AudioManager() { + m_init=false; +} + +void AudioManager::init() { //audio = new RtAudio(RtAudio::LINUX_PULSE); m_rtAudio = new RtAudio(RtAudio::UNIX_JACK); param = new RtAudio::StreamParameters(); @@ -128,46 +132,49 @@ AudioManager::AudioManager() { memset(&data.mixBuffer[0], 0, data.mixSize*sizeof(float)); m_thread = new std::thread(audioThreadFunction, this); + m_init = true; } void AudioManager::changeBuf(float* outputBuf, float maxSinValue) { + if(m_init) { - //check if there is space to write the new values - size_t write_space = ringbuffer_write_space(data.ringBuffer); - if(write_space >= m_bufSize) { - - - //write all data to the ringbuffer - ringbuffer_write(data.ringBuffer, outputBuf, data.bufSize); - - /* - float phase = 0; - float pas = 1.0/float(data.mixSize); - - //fill the audioValue array with the audio value - for(int i=0; i < int(data.nFrames); i++) { - if(i < data.mixSize) { - audioValue[i] = outputBuf[i]*phase; - phase += pas; + //check if there is space to write the new values + size_t write_space = ringbuffer_write_space(data.ringBuffer); + if(write_space >= m_bufSize) { + + + //write all data to the ringbuffer + ringbuffer_write(data.ringBuffer, outputBuf, data.bufSize); + + /* + float phase = 0; + float pas = 1.0/float(data.mixSize); + + //fill the audioValue array with the audio value + for(int i=0; i < int(data.nFrames); i++) { + if(i < data.mixSize) { + audioValue[i] = outputBuf[i]*phase; + phase += pas; + } + else { + audioValue[i] = outputBuf[i]; + } } - else { - audioValue[i] = outputBuf[i]; + + //fill the audioValue array with the values for the next crossfading + for(int i=0; i<data.mixSize; i++) { + audioValue[data.nFrames+i] = outputBuf[data.nFrames+i]*phase; + phase-=pas; } + constAudioValue = const_cast<const float *>(audioValue); + + ringbuffer_write(data.audioBuf, constAudioValue, data.nFrames + data.mixSize); + */ } - - //fill the audioValue array with the values for the next crossfading - for(int i=0; i<data.mixSize; i++) { - audioValue[data.nFrames+i] = outputBuf[data.nFrames+i]*phase; - phase-=pas; + else { + //cout<<"AudioManager : Could not write buffer"<<endl; } - constAudioValue = const_cast<const float *>(audioValue); - - ringbuffer_write(data.audioBuf, constAudioValue, data.nFrames + data.mixSize); - */ - } - else { - //cout<<"AudioManager : Could not write buffer"<<endl; } } diff --git a/src/audio/AudioManager.hpp b/src/audio/AudioManager.hpp index b25e8e9f55d255498b831f647bcd00515eb8219e..600c86d27bb18201606c7c26da3608e7a735a9b4 100644 --- a/src/audio/AudioManager.hpp +++ b/src/audio/AudioManager.hpp @@ -66,6 +66,7 @@ class AudioManager { static AudioManager* getInstance(); ~AudioManager(); + void init(); void changeBuf(float* outputBuf, float maxSinValue); int getRate(); int getBufferSize(); @@ -87,6 +88,7 @@ class AudioManager { CallbackData data; std::mutex mtx_audio; + bool m_init; static int rtaudio_callback(void *outbuf, void *inbuf,