1 /************************************************************************ 2 IMPORTANT NOTE : this file contains two clearly delimited sections : 3 the ARCHITECTURE section (in two parts) and the USER section. Each section 4 is governed by its own copyright and license. Please check individually 5 each section for license and copyright information. 6 *************************************************************************/ 7 8 /*******************BEGIN ARCHITECTURE SECTION (part 1/2)****************/ 9 10 /************************************************************************ 11 FAUST Architecture File 12 Copyright (C) 2003-2011 GRAME, Centre National de Creation Musicale 13 --------------------------------------------------------------------- 14 This Architecture section is free software; you can redistribute it 15 and/or modify it under the terms of the GNU General Public License 16 as published by the Free Software Foundation; either version 3 of 17 the License, or (at your option) any later version. 18 19 This program is distributed in the hope that it will be useful, 20 but WITHOUT ANY WARRANTY; without even the implied warranty of 21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 GNU General Public License for more details. 23 24 You should have received a copy of the GNU General Public License 25 along with this program; If not, see <http://www.gnu.org/licenses/>. 26 27 EXCEPTION : As a special exception, you may create a larger work 28 that contains this FAUST architecture section and distribute 29 that work under terms of your choice, so long as this FAUST 30 architecture section is not modified. 31 32 33 ************************************************************************ 34 ************************************************************************/ 35 36 /****************************************************************************** 37 ******************************************************************************* 38 39 A dummy audio driver 40 41 ******************************************************************************* 42 *******************************************************************************/ 43 44 #ifndef __dummy_audio__ 45 #define __dummy_audio__ 46 47 #include <stdlib.h> 48 #include <string.h> 49 #include <stdio.h> 50 #include <iostream> 51 #include <iomanip> 52 53 #include "faust/dsp/dsp.h" 54 #include "faust/audio/audio.h" 55 56 #define BUFFER_TO_RENDER 10 57 58 class dummyaudio : public audio { 59 60 private: 61 62 dsp* fDSP; 63 64 long fSampleRate; 65 long fBufferSize; 66 67 FAUSTFLOAT** fInChannel; 68 FAUSTFLOAT** fOutChannel; 69 70 int fCount; 71 bool fIsSample; 72 73 public: 74 75 dummyaudio(int sr, int bs, int count = 10, bool sample = false) fSampleRate(sr)76 :fSampleRate(sr), fBufferSize(bs), fCount(count), fIsSample(sample) {} 77 dummyaudio(int count = 10) 78 :fSampleRate(48000), fBufferSize(512), fCount(count) {} 79 ~dummyaudio()80 virtual ~dummyaudio() 81 { 82 for (int i = 0; i < fDSP->getNumInputs(); i++) { 83 delete[] fInChannel[i]; 84 } 85 for (int i = 0; i < fDSP->getNumOutputs(); i++) { 86 delete[] fOutChannel[i]; 87 } 88 89 delete [] fInChannel; 90 delete [] fOutChannel; 91 } 92 init(const char * name,dsp * dsp)93 virtual bool init(const char* name, dsp* dsp) 94 { 95 fDSP = dsp; 96 fDSP->init(fSampleRate); 97 98 fInChannel = new FAUSTFLOAT*[fDSP->getNumInputs()]; 99 fOutChannel = new FAUSTFLOAT*[fDSP->getNumOutputs()]; 100 101 for (int i = 0; i < fDSP->getNumInputs(); i++) { 102 fInChannel[i] = new FAUSTFLOAT[fBufferSize]; 103 memset(fInChannel[i], 0, sizeof(FAUSTFLOAT) * fBufferSize); 104 } 105 for (int i = 0; i < fDSP->getNumOutputs(); i++) { 106 fOutChannel[i] = new FAUSTFLOAT[fBufferSize]; 107 memset(fOutChannel[i], 0, sizeof(FAUSTFLOAT) * fBufferSize); 108 } 109 return true; 110 } start()111 virtual bool start() 112 { 113 while (--fCount > 0) { 114 printf("Render one buffer\n"); 115 render(); 116 } 117 return true; 118 } stop()119 virtual void stop() 120 {} 121 render()122 void render() 123 { 124 fDSP->compute(fBufferSize, fInChannel, fOutChannel); 125 if (fDSP->getNumInputs() > 0) { 126 if (fIsSample) { 127 for (int frame = 0; frame < fBufferSize; frame++) { 128 std::cout << std::setprecision(6) << "sample in " << fInChannel[0][frame] << std::endl; 129 } 130 } else { 131 std::cout << std::setprecision(6) << "sample in " << fInChannel[0][0] << std::endl; 132 } 133 } 134 if (fDSP->getNumOutputs() > 0) { 135 if (fIsSample) { 136 for (int frame = 0; frame < fBufferSize; frame++) { 137 std::cout << std::fixed << std::setprecision(6) << "sample out " << fOutChannel[0][frame] << std::endl; 138 } 139 } else { 140 std::cout << std::fixed << std::setprecision(6) << "sample out " << fOutChannel[0][0] << std::endl; 141 } 142 } 143 } 144 get_buffer_size()145 virtual int get_buffer_size() { return fBufferSize; } get_sample_rate()146 virtual int get_sample_rate() { return fSampleRate; } 147 148 }; 149 150 #endif 151