diff --git a/src/audio/abstract.cpp b/src/audio/abstract.cpp index fe5093024..8026adf8c 100644 --- a/src/audio/abstract.cpp +++ b/src/audio/abstract.cpp @@ -28,4 +28,7 @@ bool TAAudio::setRun(bool run) { bool TAAudio::init(TAAudioDesc& request, TAAudioDesc& response) { return false; +} + +TAAudio::~TAAudio() { } \ No newline at end of file diff --git a/src/audio/taAudio.h b/src/audio/taAudio.h index 8e8084383..86479a0b4 100644 --- a/src/audio/taAudio.h +++ b/src/audio/taAudio.h @@ -76,5 +76,7 @@ class TAAudio { audioProcCallback(NULL), sampleRateChanged(NULL), bufferSizeChanged(NULL) {} + + virtual ~TAAudio(); }; #endif diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 57458d081..75aa24241 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -3225,6 +3225,52 @@ void DivEngine::quitDispatch() { } \ } +bool DivEngine::initAudioBackend() { + switch (audioEngine) { + case DIV_AUDIO_JACK: +#ifndef HAVE_JACK + logE("Furnace was not compiled with JACK support!\n"); + setConf("audioEngine","SDL"); + saveConf(); + output=new TAAudioSDL; +#else + output=new TAAudioJACK; +#endif + break; + case DIV_AUDIO_SDL: + output=new TAAudioSDL; + break; + default: + logE("invalid audio engine!\n"); + return false; + } + want.bufsize=getConfInt("audioBufSize",1024); + want.rate=getConfInt("audioRate",44100); + want.fragments=2; + want.inChans=0; + want.outChans=2; + want.outFormat=TA_AUDIO_FORMAT_F32; + want.name="Furnace"; + + output->setCallback(process,this); + + logI("initializing audio.\n"); + if (!output->init(want,got)) { + logE("error while initializing audio!\n"); + return false; + } + return true; +} + +bool DivEngine::deinitAudioBackend() { + if (output!=NULL) { + output->quit(); + delete output; + output=NULL; + } + return true; +} + #ifdef _WIN32 #include "winStuff.h" #endif @@ -3263,39 +3309,7 @@ bool DivEngine::init() { } // init the rest of engine - switch (audioEngine) { - case DIV_AUDIO_JACK: -#ifndef HAVE_JACK - logE("Furnace was not compiled with JACK support!\n"); - setConf("audioEngine","SDL"); - saveConf(); - return false; -#else - output=new TAAudioJACK; -#endif - break; - case DIV_AUDIO_SDL: - output=new TAAudioSDL; - break; - default: - logE("invalid audio engine!\n"); - return false; - } - want.bufsize=getConfInt("audioBufSize",1024); - want.rate=getConfInt("audioRate",44100); - want.fragments=2; - want.inChans=0; - want.outChans=2; - want.outFormat=TA_AUDIO_FORMAT_F32; - want.name="Furnace"; - - output->setCallback(process,this); - - logI("initializing audio.\n"); - if (!output->init(want,got)) { - logE("error while initializing audio!\n"); - return false; - } + if (!initAudioBackend()) return false; samp_bb=blip_new(32768); if (samp_bb==NULL) { @@ -3330,7 +3344,7 @@ bool DivEngine::init() { } bool DivEngine::quit() { - output->quit(); + deinitAudioBackend(); quitDispatch(); logI("saving config.\n"); saveConf(); diff --git a/src/engine/engine.h b/src/engine/engine.h index f817c3d3d..43209fd50 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -176,6 +176,9 @@ class DivEngine { bool loadDMF(unsigned char* file, size_t len); bool loadFur(unsigned char* file, size_t len); + bool initAudioBackend(); + bool deinitAudioBackend(); + public: DivSong song; void nextBuf(float** in, float** out, int inChans, int outChans, unsigned int size); @@ -196,6 +199,8 @@ class DivEngine { SafeWriter* saveVGM(); // export to an audio file bool saveAudio(const char* path); + // wait for audio export to finish + void waitAudioFile(); // stop audio file export bool haltAudioFile(); @@ -435,6 +440,7 @@ class DivEngine { unsigned char* adpcmMem; DivEngine(): + output(NULL), chans(0), active(false), playing(false),