|
| 1 | +/************************** BEGIN audio.h ***************************** |
| 2 | + FAUST Architecture File |
| 3 | + Copyright (C) 2003-2022 GRAME, Centre National de Creation Musicale |
| 4 | + --------------------------------------------------------------------- |
| 5 | + This program is free software; you can redistribute it and/or modify |
| 6 | + it under the terms of the GNU Lesser General Public License as published by |
| 7 | + the Free Software Foundation; either version 2.1 of the License, or |
| 8 | + (at your option) any later version. |
| 9 | + |
| 10 | + This program is distributed in the hope that it will be useful, |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + GNU Lesser General Public License for more details. |
| 14 | + |
| 15 | + You should have received a copy of the GNU Lesser General Public License |
| 16 | + along with this program; if not, write to the Free Software |
| 17 | + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | + |
| 19 | + EXCEPTION : As a special exception, you may create a larger work |
| 20 | + that contains this FAUST architecture section and distribute |
| 21 | + that work under terms of your choice, so long as this FAUST |
| 22 | + architecture section is not modified. |
| 23 | + ***********************************************************************/ |
| 24 | + |
| 25 | +#ifndef __audio__ |
| 26 | +#define __audio__ |
| 27 | + |
| 28 | +#include <set> |
| 29 | +#include <utility> |
| 30 | + |
| 31 | +class dsp; |
| 32 | + |
| 33 | +typedef void (* shutdown_callback)(const char* message, void* arg); |
| 34 | + |
| 35 | +typedef void (* compute_callback)(void* arg); |
| 36 | + |
| 37 | +class audio { |
| 38 | + |
| 39 | + protected: |
| 40 | + |
| 41 | + shutdown_callback fShutdown; // Shutdown callback |
| 42 | + void* fShutdownArg; // Shutdown callback data |
| 43 | + |
| 44 | + std::set<std::pair<compute_callback, void*> > fComputeCallbackList; |
| 45 | + |
| 46 | + public: |
| 47 | + |
| 48 | + audio():fShutdown(nullptr), fShutdownArg(nullptr) {} |
| 49 | + virtual ~audio() {} |
| 50 | + |
| 51 | + /** |
| 52 | + * Init the DSP. |
| 53 | + * @param name - the DSP name to be given to the audio driven |
| 54 | + * (could appear as a JACK client for instance) |
| 55 | + * @param dsp - the dsp that will be initialized with the driver sample rate |
| 56 | + * |
| 57 | + * @return true is sucessful, false in case of driver failure. |
| 58 | + **/ |
| 59 | + virtual bool init(const char* name, ::dsp* dsp) = 0; |
| 60 | + |
| 61 | + /** |
| 62 | + * Start audio processing. |
| 63 | + * @return true is sucessful, false if case of driver failure. |
| 64 | + **/ |
| 65 | + virtual bool start() = 0; |
| 66 | + |
| 67 | + /** |
| 68 | + * Stop audio processing. |
| 69 | + **/ |
| 70 | + virtual void stop() = 0; |
| 71 | + |
| 72 | + void setShutdownCallback(shutdown_callback cb, void* arg) |
| 73 | + { |
| 74 | + fShutdown = cb; |
| 75 | + fShutdownArg = arg; |
| 76 | + } |
| 77 | + |
| 78 | + void addControlCallback(compute_callback cb, void* arg) |
| 79 | + { |
| 80 | + fComputeCallbackList.insert(std::make_pair(cb, arg)); |
| 81 | + } |
| 82 | + |
| 83 | + bool removeControlCallback(compute_callback cb, void* arg) |
| 84 | + { |
| 85 | + return (fComputeCallbackList.erase(std::make_pair(cb, arg)) == 1); |
| 86 | + } |
| 87 | + |
| 88 | + void runControlCallbacks() |
| 89 | + { |
| 90 | + for (const auto& it : fComputeCallbackList) { |
| 91 | + it.first(it.second); |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + // Return buffer size in frames. |
| 96 | + virtual int getBufferSize() = 0; |
| 97 | + |
| 98 | + // Return the driver sample rate in Hz. |
| 99 | + virtual int getSampleRate() = 0; |
| 100 | + |
| 101 | + // Return the driver hardware inputs number. |
| 102 | + virtual int getNumInputs() = 0; |
| 103 | + |
| 104 | + // Return the driver hardware outputs number. |
| 105 | + virtual int getNumOutputs() = 0; |
| 106 | + |
| 107 | + /** |
| 108 | + * @return Returns the average proportion of available CPU |
| 109 | + * being spent inside the audio callbacks (between 0.0 and 1.0). |
| 110 | + **/ |
| 111 | + virtual float getCPULoad() { return 0.f; } |
| 112 | +}; |
| 113 | + |
| 114 | +#endif |
| 115 | +/************************** END audio.h **************************/ |
0 commit comments