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

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.  

*/

#include <flext.h>
#include <fldefs.h>


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

thomas's avatar
thomas committed
17
void flext_dsp::Setup(t_class *c)
thomas's avatar
thomas committed
18
19
20
21
22
23
24
25
{
#ifdef PD
	CLASS_MAINSIGNALIN(c,flext_hdr,defsig);
#elif defined(MAXMSP)
	dsp_initclass();
#endif
	
	add_dsp(c,cb_dsp);
thomas's avatar
thomas committed
26
27
28
#ifndef MAXMSP
	add_method1(c,cb_enable,"enable",A_FLINT);
#endif
thomas's avatar
thomas committed
29
30
31
}

flext_dsp::flext_dsp(): 
thomas's avatar
thomas committed
32
#ifndef MAXMSP
thomas's avatar
thomas committed
33
	dspon(true),
thomas's avatar
thomas committed
34
#endif
thomas's avatar
thomas committed
35
	srate(sys_getsr()),  // should we set it?
thomas's avatar
thomas committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
	invecs(NULL),outvecs(NULL)
{}


flext_dsp::~flext_dsp()
{
	if(invecs) delete[] invecs;
	if(outvecs) delete[] outvecs;
}


t_int *flext_dsp::dspmeth(t_int *w) 
{ 
	flext_dsp *obj = (flext_dsp *)w[1];
thomas's avatar
thomas committed
50
51
52
#ifdef MAXMSP
	if(!obj->thisHdr()->z_disabled) 
#else
thomas's avatar
thomas committed
53
	if(obj->dspon) 
thomas's avatar
thomas committed
54
#endif
thomas's avatar
thomas committed
55
		obj->m_signal((int)w[2],obj->invecs,obj->outvecs); 
thomas's avatar
thomas committed
56
57
58
	return w+3;
}

thomas's avatar
thomas committed
59
void flext_dsp::m_dsp(int /*n*/,float *const * /*insigs*/,float *const * /*outsigs*/) {}
thomas's avatar
thomas committed
60

thomas's avatar
thomas committed
61
void flext_dsp::cb_dsp(t_class *c,t_signal **sp) 
thomas's avatar
thomas committed
62
63
64
65
66
67
68
{ 
	flext_dsp *obj = thisObject(c); 

	// store current sample rate
	obj->srate = sp[0]->s_sr;

	// store in and out signal vectors
thomas's avatar
thomas committed
69
	int i,in = obj->CntInSig(),out = obj->CntOutSig();
thomas's avatar
thomas committed
70
	if(obj->invecs) delete[] obj->invecs;
thomas's avatar
thomas committed
71
	obj->invecs = new float *[in];
thomas's avatar
thomas committed
72
73
74
	for(i = 0; i < in; ++i) obj->invecs[i] = sp[i]->s_vec;

	if(obj->outvecs) delete[] obj->outvecs;
thomas's avatar
thomas committed
75
	obj->outvecs = new float *[out];
thomas's avatar
thomas committed
76
77
78
79
80
81
82
83
84
	for(i = 0; i < out; ++i) obj->outvecs[i] = sp[in+i]->s_vec;

	// with the following call derived classes can do their eventual DSP setup
	obj->m_dsp(sp[0]->s_n,obj->invecs,obj->outvecs);

	// set the DSP function
	dsp_add((t_dspmethod)dspmeth,2,obj,sp[0]->s_n);  
}

thomas's avatar
thomas committed
85
#ifndef MAXMSP
thomas's avatar
thomas committed
86
87
void flext_dsp::cb_enable(t_class *c,flint on) { thisObject(c)->m_enable(on != 0); }
void flext_dsp::m_enable(bool en) { dspon = en; }
thomas's avatar
thomas committed
88
#endif
thomas's avatar
thomas committed
89
90