fldsp.h 4.3 KB
Newer Older
thomas's avatar
thomas committed
1 2 3 4
/* 

flext - C++ layer for Max/MSP and pd (pure data) externals

thomas's avatar
thomas committed
5
Copyright (c) 2001-2005 Thomas Grill (gr@grrrr.org)
thomas's avatar
thomas committed
6 7 8 9 10 11 12 13 14 15 16 17 18
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.  

*/

/*! \file fldsp.h
    \brief Declares the flext dsp class
    
*/

#ifndef __FLDSP_H
#define __FLDSP_H

thomas's avatar
thomas committed
19
// include the header file declaring the base classes
thomas's avatar
thomas committed
20
#include "flext.h"
thomas's avatar
thomas committed
21 22 23 24


// === flext_dsp ==================================================

25 26 27 28
class FLEXT_SHARE FLEXT_CLASSDEF(flext_dsp);
typedef class FLEXT_SHARE FLEXT_CLASSDEF(flext_dsp) flext_dsp;


thomas's avatar
thomas committed
29
/*! \brief Flext dsp enabled base object
thomas's avatar
thomas committed
30
*/
31
class FLEXT_SHARE FLEXT_CLASSDEF(flext_dsp):
thomas's avatar
thomas committed
32
	public flext_base
thomas's avatar
thomas committed
33
{
34
	FLEXT_HEADER_S(FLEXT_CLASSDEF(flext_dsp),flext_base,Setup)
thomas's avatar
thomas committed
35 36 37
	
public:

thomas's avatar
thomas committed
38 39 40 41 42 43
/*!	\defgroup FLEXT_DSP Flext dsp class

	@{ 
*/

/*!	\defgroup FLEXT_C_DSP Basic dsp functionality
thomas's avatar
thomas committed
44 45 46 47

	@{ 
*/

thomas's avatar
thomas committed
48 49 50
	//! returns current sample rate
	float Samplerate() const { return srate; }
	
thomas's avatar
thomas committed
51
	//! returns current block (aka vector) size
thomas's avatar
thomas committed
52
	int Blocksize() const { return blksz; }
thomas's avatar
thomas committed
53
    
54
	//! returns array of input vectors (CntInSig() vectors)
55
    t_sample *const *InSig() const { return vecs; }
56

57
	//! returns input vector
thomas's avatar
thomas committed
58
    t_sample *InSig(int i) const { return InSig()[i]; }
59

60
	//! returns array of output vectors (CntOutSig() vectors)
thomas's avatar
thomas committed
61 62 63 64 65 66 67
    // \todo cache that returned pointer
    t_sample *const *OutSig() const 
    { 
        int i = CntInSig(); 
        // we have at least one actual dsp in vector
        return vecs+(i?i:1); 
    }
68

69
	//! returns output vector
thomas's avatar
thomas committed
70
    t_sample *OutSig(int i) const { return OutSig()[i]; }
71

thomas's avatar
thomas committed
72 73
	//! typedef describing a signal vector
	typedef t_sample *t_signalvec;
thomas's avatar
thomas committed
74

thomas's avatar
thomas committed
75
//!	@} 
thomas's avatar
thomas committed
76 77 78

// --- inheritable virtual methods --------------------------------

thomas's avatar
thomas committed
79
/*!	\defgroup FLEXT_C_DSP_VIRTUAL Flext virtual dsp functions
thomas's avatar
thomas committed
80 81 82

	@{ 
*/
thomas's avatar
thomas committed
83
	/*! \brief Called on every dsp init.
thomas's avatar
thomas committed
84
		\note Don't expect any valid data in the signal vectors!
85 86 87 88 89 90 91 92 93 94 95
        flext_dsp::CbDsp should not be called by the derived class

        \return true (default)... use DSP, false, don't use DSP
    */
	virtual bool CbDsp();

	/*! \brief Called with every signal vector - here you do the dsp calculation
        flext_dsp::CbSignal fills all output vectors with silence
    */
	virtual void CbSignal();

thomas's avatar
thomas committed
96

97 98
    /*! \brief Deprecated method for CbSignal
        \deprecated
thomas's avatar
thomas committed
99 100 101
		\param n: frames (aka samples) in one signal vector
		\param insigs: array of input vectors  (get number with function CntInSig())
		\param outsigs: array of output vectors  (get number with function CntOutSig())
thomas's avatar
thomas committed
102
	*/
thomas's avatar
thomas committed
103
	virtual void m_dsp(int n,t_signalvec const *insigs,t_signalvec const *outsigs);
thomas's avatar
thomas committed
104

105 106
    /*! \brief Deprecated method for CbSignal
        \deprecated
thomas's avatar
thomas committed
107 108 109
		\param n: frames (aka samples) in one signal vector
		\param insigs: array of input vectors  (get number with function CntInSig())
		\param outsigs: array of output vectors  (get number with function CntOutSig())
thomas's avatar
thomas committed
110
	*/
thomas's avatar
thomas committed
111
	virtual void m_signal(int n,t_sample *const *insigs,t_sample *const *outsigs);
thomas's avatar
thomas committed
112

thomas's avatar
thomas committed
113 114 115
//!	@} 


thomas's avatar
thomas committed
116
/*!	\defgroup FLEXT_C_DSP_INOUT Flext dsp in-/outlet functions
thomas's avatar
thomas committed
117 118 119 120
	\note These must be called in the class' constructor

	@{ 
*/
thomas's avatar
thomas committed
121 122
// --- inlet/outlet stuff -----------------------------------------	

thomas's avatar
thomas committed
123 124 125
	/*! \brief Add signal inlet(s)
		\param m Number of inlets to add
	*/
thomas's avatar
thomas committed
126
	void AddInSignal(int m = 1) { AddInlet(xlet_sig,m); }
thomas's avatar
thomas committed
127

thomas's avatar
thomas committed
128 129 130
	/*! \brief Add signal inlet (with description)
		\param desc Description of inlet
	*/
thomas's avatar
thomas committed
131
	void AddInSignal(const char *desc) { AddInlet(xlet_sig,1,desc); }
thomas's avatar
thomas committed
132

thomas's avatar
thomas committed
133 134 135
	/*! \brief Add signal outlet(s)
		\param m Number of inlets to add
	*/
thomas's avatar
thomas committed
136
	void AddOutSignal(int m = 1) { AddOutlet(xlet_sig,m); }
thomas's avatar
thomas committed
137

thomas's avatar
thomas committed
138 139 140
	/*! \brief Add signal outlet (with description)
		\param desc Description of outlet
	*/
thomas's avatar
thomas committed
141
	void AddOutSignal(const char *desc) { AddOutlet(xlet_sig,1,desc); }
thomas's avatar
thomas committed
142

thomas's avatar
thomas committed
143 144
//!	@} 

thomas's avatar
thomas committed
145
//!	@} 
thomas's avatar
thomas committed
146 147 148

protected:
	
149
	FLEXT_CLASSDEF(flext_dsp)();
150 151 152 153 154 155

#if FLEXT_SYS == FLEXT_SYS_MAX
    virtual bool Init();
#endif

    virtual void Exit();
thomas's avatar
thomas committed
156

thomas's avatar
thomas committed
157 158 159 160 161
private:

	// not static, could be different in different patchers..
	float srate; 
	int blksz;
162
	t_signalvec *vecs;
thomas's avatar
thomas committed
163 164

	// setup function
thomas's avatar
thomas committed
165
	static void Setup(t_classid c);
thomas's avatar
thomas committed
166 167

	// callback functions
168
#if FLEXT_SYS == FLEXT_SYS_MAX
thomas's avatar
thomas committed
169
	static void cb_dsp(t_class *c,t_signal **s,short *count);
thomas's avatar
thomas committed
170
#else
thomas's avatar
thomas committed
171
	static void cb_dsp(t_class *c,t_signal **s);
thomas's avatar
thomas committed
172
	static void cb_enable(t_class *c,t_float on);
thomas's avatar
thomas committed
173 174 175 176 177 178 179 180
	bool dspon;
#endif

	// dsp stuff
	static t_int *dspmeth(t_int *w); 
};

#endif