fldsp.h 3.23 KB
Newer Older
thomas's avatar
thomas committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* 

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

Copyright (c) 2001,2002 Thomas Grill (xovo@gmx.net)
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

thomas's avatar
thomas committed
22
namespace flext {
thomas's avatar
thomas committed
23 24 25

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

thomas's avatar
thomas committed
26
/*! \brief Flext dsp enabled base object
thomas's avatar
thomas committed
27
*/
thomas's avatar
thomas committed
28 29
class CDsp: //flext_dsp:
public CBase //flext_base
thomas's avatar
thomas committed
30 31 32 33 34
{
	FLEXT_HEADER_S(flext_dsp,flext_base,Setup)
	
public:

thomas's avatar
thomas committed
35 36 37 38 39
/*!	\defgroup FLEXT_C_DSP Flext basic dsp functionality

	@{ 
*/

thomas's avatar
thomas committed
40 41 42
	//! returns current sample rate
	float Samplerate() const { return srate; }
	
thomas's avatar
thomas committed
43
	//! returns current block (aka vector) size
thomas's avatar
thomas committed
44 45
	int Blocksize() const { return blksz; }
	
thomas's avatar
thomas committed
46 47 48
	/*! \brief returns number of audio system input channels
		\bug Doesn't work in Max/MSP - is always 0
	*/
thomas's avatar
thomas committed
49
	int ChannelsIn() const { return chnsin; }
thomas's avatar
thomas committed
50 51 52 53

	/*! \brief returns number of audio system output channels
		\bug Doesn't work in Max/MSP - is always 0
	*/
thomas's avatar
thomas committed
54 55
	int ChannelsOut() const { return chnsout; }
	
thomas's avatar
thomas committed
56 57
//!	@} 

thomas's avatar
thomas committed
58 59 60

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

thomas's avatar
thomas committed
61 62 63 64
/*!	\defgroup FLEXT_C_VIRTUAL_DSP Flext virtual dsp functions

	@{ 
*/
thomas's avatar
thomas committed
65
	/*! \brief Called on every dsp init.
thomas's avatar
thomas committed
66 67 68 69 70
		\note Don't expect any valid data in the signal vectors!

		\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
71 72 73
	*/
	virtual void m_dsp(int n,t_sample *const *insigs,t_sample *const *outsigs);

thomas's avatar
thomas committed
74 75 76 77 78
	/*! \brief Called with every signal vector - here you do the dsp calculation

		\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
79 80 81 82
	*/
	virtual void m_signal(int n,t_sample *const *insigs,t_sample *const *outsigs) = 0;

#ifndef MAXMSP
thomas's avatar
thomas committed
83 84 85
	/*! \brief called with "enable" message: pauses/resumes dsp
		\note PD only - implicitely defined in MaxMSP
	*/
thomas's avatar
thomas committed
86 87 88
	virtual void m_enable(bool on);
#endif

thomas's avatar
thomas committed
89 90 91 92 93 94 95 96
//!	@} 


/*!	\defgroup FLEXT_C_INOUT_DSP Flext dsp in-/outlet functions
	\note These must be called in the class' constructor

	@{ 
*/
thomas's avatar
thomas committed
97 98
// --- inlet/outlet stuff -----------------------------------------	

thomas's avatar
thomas committed
99 100 101
	/*! \brief Add signal inlet(s)
		\param m Number of inlets to add
	*/
thomas's avatar
thomas committed
102 103
	void AddInSignal(int m = 1) { AddInlet(xlet::tp_sig,m); }

thomas's avatar
thomas committed
104 105 106
	/*! \brief Add signal outlet(s)
		\param m Number of inlets to add
	*/
thomas's avatar
thomas committed
107 108
	void AddOutSignal(int m = 1) { AddOutlet(xlet::tp_sig,m); }

thomas's avatar
thomas committed
109 110
//!	@} 

thomas's avatar
thomas committed
111 112 113

protected:
	
thomas's avatar
thomas committed
114 115 116 117 118 119
//	flext_dsp();
//	~flext_dsp();

	CDsp();
	virtual ~CDsp();

thomas's avatar
thomas committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
private:

	// not static, could be different in different patchers..
	float srate; 
	int blksz;
	int chnsin,chnsout;

	// setup function
	static void Setup(t_class *c);

	// callback functions

	static void cb_dsp(t_class *c,t_signal **s);
#ifndef MAXMSP
	static void cb_enable(t_class *c,t_flint on);
	bool dspon;
#endif

	// dsp stuff

	static t_int *dspmeth(t_int *w); 
	t_sample **invecs,**outvecs;
};

thomas's avatar
thomas committed
144 145
} // namespace flext

thomas's avatar
thomas committed
146
#endif