fldsp.h 4.31 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-2003 Thomas Grill (xovo@gmx.net)
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 ==================================================

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

thomas's avatar
thomas committed
34
35
36
37
38
39
/*!	\defgroup FLEXT_DSP Flext dsp class

	@{ 
*/

/*!	\defgroup FLEXT_C_DSP Basic dsp functionality
thomas's avatar
thomas committed
40
41
42
43

	@{ 
*/

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

	/*! \brief returns number of audio system output channels
		\bug Doesn't work in Max/MSP - is always 0
	*/
thomas's avatar
thomas committed
58
59
	int ChannelsOut() const { return chnsout; }
	
thomas's avatar
thomas committed
60
61
62
63
64
65
	//! typedef describing a signal vector
#if FLEXT_SYS == FLEXT_SYS_JMAX
	typedef fts_symbol_t t_signalvec;
#else
	typedef t_sample *t_signalvec;
#endif
thomas's avatar
thomas committed
66

thomas's avatar
thomas committed
67
//!	@} 
thomas's avatar
thomas committed
68
69
70

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

thomas's avatar
thomas committed
71
/*!	\defgroup FLEXT_C_DSP_VIRTUAL Flext virtual dsp functions
thomas's avatar
thomas committed
72
73
74

	@{ 
*/
thomas's avatar
thomas committed
75
	/*! \brief Called on every dsp init.
thomas's avatar
thomas committed
76
77
78
79
80
		\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
81
	*/
thomas's avatar
thomas committed
82
	virtual void m_dsp(int n,t_signalvec const *insigs,t_signalvec const *outsigs);
thomas's avatar
thomas committed
83

thomas's avatar
thomas committed
84
85
86
87
88
	/*! \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
89
	*/
thomas's avatar
thomas committed
90
	virtual void m_signal(int n,t_sample *const *insigs,t_sample *const *outsigs);
thomas's avatar
thomas committed
91

thomas's avatar
thomas committed
92
#if FLEXT_SYS != FLEXT_SYS_MAX
thomas's avatar
thomas committed
93
	/*! \brief called with "enable" message: pauses/resumes dsp
thomas's avatar
thomas committed
94
		\note PD only - implicitely defined in Max/MSP
thomas's avatar
thomas committed
95
	*/
thomas's avatar
thomas committed
96
97
98
	virtual void m_enable(bool on);
#endif

thomas's avatar
thomas committed
99
100
101
//!	@} 


thomas's avatar
thomas committed
102
/*!	\defgroup FLEXT_C_DSP_INOUT Flext dsp in-/outlet functions
thomas's avatar
thomas committed
103
104
105
106
	\note These must be called in the class' constructor

	@{ 
*/
thomas's avatar
thomas committed
107
108
// --- inlet/outlet stuff -----------------------------------------	

thomas's avatar
thomas committed
109
110
111
	/*! \brief Add signal inlet(s)
		\param m Number of inlets to add
	*/
thomas's avatar
thomas committed
112
113
	void AddInSignal(int m = 1) { AddInlet(xlet::tp_sig,m); }

thomas's avatar
thomas committed
114
115
116
117
118
	/*! \brief Add signal inlet (with description)
		\param desc Description of inlet
	*/
	void AddInSignal(const char *desc) { AddInlet(xlet::tp_sig,1,desc); }

thomas's avatar
thomas committed
119
120
121
	/*! \brief Add signal outlet(s)
		\param m Number of inlets to add
	*/
thomas's avatar
thomas committed
122
123
	void AddOutSignal(int m = 1) { AddOutlet(xlet::tp_sig,m); }

thomas's avatar
thomas committed
124
125
126
127
128
	/*! \brief Add signal outlet (with description)
		\param desc Description of outlet
	*/
	void AddOutSignal(const char *desc) { AddOutlet(xlet::tp_sig,1,desc); }

thomas's avatar
thomas committed
129
130
//!	@} 

thomas's avatar
thomas committed
131
//!	@} 
thomas's avatar
thomas committed
132
133
134

protected:
	
thomas's avatar
thomas committed
135
136
	flext_dsp();
	virtual ~flext_dsp();
thomas's avatar
thomas committed
137

thomas's avatar
thomas committed
138
139
140
141
142
143
144
145
private:

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

	// setup function
thomas's avatar
thomas committed
146
	static void Setup(t_classid c);
thomas's avatar
thomas committed
147
148
149

	// callback functions

thomas's avatar
thomas committed
150
151
152
153
154
#if FLEXT_SYS == FLEXT_SYS_JMAX
	static void	cb_dsp(fts_object_t *o, int winlet, fts_symbol_t s, int ac, const fts_atom_t *at);
//	static void	cb_dsp_init(fts_object_t *o, int winlet, fts_symbol_t *s, int ac, const fts_atom_t *at);
//	static void	cb_dsp_delete(fts_object_t *o, int winlet, fts_symbol_t *s, int ac, const fts_atom_t *at);
#else
thomas's avatar
thomas committed
155
	static void cb_dsp(t_class *c,t_signal **s);
thomas's avatar
thomas committed
156
157
#endif

thomas's avatar
thomas committed
158
#if FLEXT_SYS != FLEXT_SYS_MAX
thomas's avatar
thomas committed
159
160
161
#if FLEXT_SYS == FLEXT_SYS_JMAX
	static void cb_enable(fts_object_t *o, int winlet, fts_symbol_t s, int ac, const fts_atom_t *at);
#else
thomas's avatar
thomas committed
162
	static void cb_enable(t_class *c,t_float on);
thomas's avatar
thomas committed
163
#endif
thomas's avatar
thomas committed
164
165
166
167
168
	bool dspon;
#endif

	// dsp stuff

thomas's avatar
thomas committed
169
170
171
172
#if FLEXT_SYS == FLEXT_SYS_JMAX
	static void dspmeth(fts_word_t *);
	static const t_symbol *dspsym;
#else
thomas's avatar
thomas committed
173
	static t_int *dspmeth(t_int *w); 
thomas's avatar
thomas committed
174
175
#endif
	t_signalvec *invecs,*outvecs;
thomas's avatar
thomas committed
176
177
178
};

#endif