OutMgr.h (3263B)
1 /* 2 ZynAddSubFX - a software synthesizer 3 4 OutMgr.h - Audio Engine Interfacer 5 Copyright (C) 2016 Mark McCurry 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License 9 as published by the Free Software Foundation; either version 2 10 of the License, or (at your option) any later version. 11 */ 12 #ifndef OUTMGR_H 13 #define OUTMGR_H 14 15 #include "../Misc/Stereo.h" 16 #include "../globals.h" 17 #include <list> 18 #if HAVE_BG_SYNTH_THREAD 19 #include <pthread.h> 20 #endif 21 #include <string> 22 #include <semaphore.h> 23 24 namespace zyn { 25 26 class AudioOut; 27 struct SYNTH_T; 28 class OutMgr 29 { 30 public: 31 enum { FRAME_SIZE_MAX = 1U << 14 }; 32 33 static OutMgr &getInstance(const SYNTH_T *synth=NULL); 34 ~OutMgr(); 35 36 /**Execute a tick*/ 37 Stereo<float *> tick(unsigned int frameSize) REALTIME; 38 39 /**Request a new set of samples 40 * @param n number of requested samples (defaults to 1) 41 * @return -1 for locking issues 0 for valid request*/ 42 void requestSamples(unsigned int n = 1); 43 44 /**Gets requested driver 45 * @param name case unsensitive name of driver 46 * @return pointer to Audio Out or NULL 47 */ 48 AudioOut *getOut(std::string name); 49 50 /**Gets the name of the first running driver 51 * Deprecated 52 * @return if no running output, "" is returned 53 */ 54 std::string getDriver() const; 55 56 bool setSink(std::string name); 57 58 std::string getSink() const; 59 60 void setAudioCompressor(bool isEnabled); 61 bool getAudioCompressor(void); 62 63 class WavEngine * wave; /**<The Wave Recorder*/ 64 friend class EngineMgr; 65 66 void setMaster(class Master *master_); 67 void applyOscEventRt(const char *msg); 68 #if HAVE_BG_SYNTH_THREAD 69 void setBackgroundSynth(bool); 70 static void *_refillThread(void *); 71 void *refillThread(); 72 #endif 73 private: 74 OutMgr(const SYNTH_T *synth); 75 void addSmps(float *l, float *r); 76 unsigned int curStoredSmps() const {return priBuffCurrent.l - priBuf.l; } 77 void removeStaleSmps(); 78 #if HAVE_BG_SYNTH_THREAD 79 void refillLock() { pthread_mutex_lock(&bgSynthMtx); } 80 void refillUnlock() { pthread_mutex_unlock(&bgSynthMtx); } 81 void refillWait() { pthread_cond_wait(&bgSynthCond, &bgSynthMtx); } 82 void refillWakeup() { pthread_cond_broadcast(&bgSynthCond); } 83 #else 84 void refillLock() { } 85 void refillUnlock() { } 86 #endif 87 void refillSmps(unsigned int); 88 89 AudioOut *currentOut; /**<The current output driver*/ 90 91 sem_t requested; 92 93 /**Buffer*/ 94 Stereo<float *> priBuf; //buffer for primary drivers 95 Stereo<float *> priBuffCurrent; //current array accessor 96 97 float *outl; 98 float *outr; 99 class Master *master; 100 101 /**Buffer state*/ 102 unsigned int stales; 103 unsigned int maxStoredSmps; 104 unsigned int midiFlushOffset; 105 const SYNTH_T &synth; 106 107 #if HAVE_BG_SYNTH_THREAD 108 /**Background synth*/ 109 pthread_mutex_t bgSynthMtx; 110 pthread_cond_t bgSynthCond; 111 pthread_t bgSynthThread; 112 bool bgSynthEnabled; 113 #endif 114 }; 115 116 } 117 118 #endif