Bug fixed in the Makefile.
[Faustine.git] / interpretor / faust-0.9.47mr3 / architecture / audio / oscdsp.h
1
2 #ifndef __osc_dsp__
3 #define __osc_dsp__
4
5 #include <stdio.h>
6 #include "audio/audio.h"
7 #include "audio/dsp.h"
8 #include "OSCIO.h"
9
10 /******************************************************************************
11 *******************************************************************************
12
13 OSC AUDIO INTERFACE
14
15 *******************************************************************************
16 *******************************************************************************/
17
18 #define kMaxBuffer 4096
19
20 class oscdsp : public audio, public oscfaust::OSCIO {
21 dsp* fDsp;
22 float ** fInBuffers, **fOutBuffers;
23
24 public:
25 oscdsp(const char * dst, int argc, char *argv[]) : OSCIO(dst), fDsp(0), fInBuffers(0), fOutBuffers(0)
26 {
27 for (int i = 1; i < argc-1; i++)
28 if (!strcmp(argv[i], "-iodst")) setDest (argv[i+1]);
29 }
30 virtual ~oscdsp() { stop(); }
31
32 virtual bool init(const char*name, dsp* DSP) {
33 fDsp = DSP;
34 fDsp->init(44100);
35 fInBuffers = new float*[numInputs()];
36 fOutBuffers = new float*[numOutputs()];
37 for (int i= 0; i < numInputs(); i++)
38 fInBuffers[i] = new float[kMaxBuffer];
39 for (int i= 0; i < numOutputs(); i++)
40 fOutBuffers [i] = new float[kMaxBuffer];
41 return true;
42 }
43
44 virtual bool start() { return true; }
45 virtual void stop() {}
46
47 void compute( int nframes ) {
48 fDsp->compute(nframes, fInBuffers, fOutBuffers);
49 for (int i= 0; i < numOutputs(); i++)
50 send( nframes, fOutBuffers [i], i);
51 }
52
53 void receive( int nvalues, float * val ) {
54 int inChans = numInputs();
55 if (!inChans) {
56 compute(nvalues);
57 return;
58 }
59
60 for (int i=0; i < nvalues; i++) {
61 int c = i % inChans;
62 int frame = i / inChans;
63 fInBuffers[c][frame] = val[i];
64 }
65 compute (nvalues / inChans);
66 }
67 int numOutputs() const { return fDsp ? fDsp->getNumOutputs() : 0; }
68 int numInputs() const { return fDsp ? fDsp->getNumInputs() : 0; }
69 };
70
71 #endif