17 #include "TTClassWrapperMax.h"
20 #include "ext_strings.h"
21 #include "commonsyms.h"
28 typedef struct _balance {
42 void* balance_new(t_symbol *msg,
short argc, t_atom *argv);
43 void balance_free(t_balance *x);
44 void balance_assist(t_balance *x,
void *b,
long msg,
long arg,
char *dst);
45 t_int* balance_perform(t_int *w);
46 void balance_dsp(t_balance *x, t_signal **sp,
short *count);
47 void balance_dsp64(t_balance *x, t_object *dsp64,
short *count,
double samplerate,
long maxvectorsize,
long flags);
48 void balance_clear(t_balance *x);
49 t_max_err balance_setBypass(t_balance *x,
void *attr,
long argc, t_atom *argv);
50 t_max_err balance_setFrequency(t_balance *x,
void *attr,
long argc, t_atom *argv);
54 t_class *balance_class;
67 common_symbols_init();
69 c = class_new(
"j.balance~",(method)balance_new, (method)balance_free, (
short)
sizeof(t_balance),
70 (method)0L, A_GIMME, 0);
72 class_addmethod(c, (method)balance_clear,
"clear", 0L);
73 class_addmethod(c, (method)balance_dsp,
"dsp", A_CANT, 0L);
74 class_addmethod(c, (method)balance_dsp64,
"dsp64", A_CANT, 0);
75 class_addmethod(c, (method)balance_assist,
"assist", A_CANT, 0L);
77 attr = attr_offset_new(
"bypass", _sym_long, attrflags,
78 (method)0L,(method)balance_setBypass, calcoffset(t_balance, attrBypass));
79 class_addattr(c, attr);
81 attr = attr_offset_new(
"frequency", _sym_float32, attrflags,
82 (method)0L,(method)balance_setFrequency, calcoffset(t_balance, attrFrequency));
83 class_addattr(c, attr);
86 class_register(CLASS_BOX, c);
96 void* balance_new(t_symbol *msg,
short argc, t_atom *argv)
100 long attrstart = attr_args_offset(argc, argv);
103 x = (t_balance *)object_alloc(balance_class);
106 x->attrFrequency = 10;
110 x->maxNumChannels = 1;
111 if (attrstart && argv)
112 x->maxNumChannels = atom_getlong(argv);
119 attr_args_process(x,argc,argv);
121 object_obex_store((
void *)x, _sym_dumpout, (
object *)outlet_new(x,NULL));
122 dsp_setup((t_pxobject *)x, x->maxNumChannels*2);
123 for (i=0; i < x->maxNumChannels; i++)
124 outlet_new((t_pxobject *)x,
"signal");
126 x->obj.z_misc = Z_NO_INPLACE;
132 void balance_free(t_balance *x)
134 dsp_free((t_pxobject *)x);
145 void balance_assist(t_balance *x,
void *b,
long msg,
long arg,
char *dst)
149 snprintf(dst, 256,
"(signal) to balance (ch. %ld), control messages", arg+1);
150 else if (arg < x->maxNumChannels)
151 snprintf(dst, 256,
"(signal) to balance (ch. %ld)", arg+1);
152 else if (arg >= x->maxNumChannels)
153 snprintf(dst, 256,
"(signal) Comperator (ch. %ld)", arg-x->maxNumChannels+1);
156 if (arg == x->maxNumChannels)
157 strcpy(dst,
"dumpout");
159 snprintf(dst, 256,
"(signal) Balanced output %ld", arg+1);
164 void balance_clear(t_balance *x)
166 x->balance->sendMessage(
TT(
"clear"));
171 t_int *balance_perform(t_int *w)
173 t_balance *x = (t_balance *)(w[1]);
175 TTUInt16 vs = x->audioIn->getVectorSizeAsInt();
178 for (i=0; i < x->numChannels; i++) {
180 k = i + x->numChannels;
181 x->audioIn->setVector(i, vs, (t_float *)w[j+1]);
182 x->audioIn->setVector(k, vs, (t_float *)w[j+2]);
185 if (!x->obj.z_disabled)
186 x->balance->process(*x->audioIn, *x->audioOut);
188 for (i=0; i < x->numChannels; i++) {
190 x->audioOut->getVector(i, vs, (t_float *)w[j+3]);
193 return w + ((x->numChannels*3)+2);
198 void balance_dsp(t_balance *x, t_signal **sp,
short *count)
201 void **audioVectors = NULL;
203 audioVectors = (
void**)sysmem_newptr(
sizeof(
void*) * ((x->maxNumChannels * 3) + 1));
210 for (i=0; i < x->maxNumChannels; i++) {
211 j = x->maxNumChannels + i;
212 k = x->maxNumChannels*2 + i;
213 if (count[i] && count[j] && count[k]) {
215 if (sp[i]->s_n > x->vs)
218 audioVectors[l] = sp[i]->s_vec;
220 audioVectors[l] = sp[j]->s_vec;
222 audioVectors[l] = sp[k]->s_vec;
227 x->audioOut->setAttributeValue(kTTSym_numChannels, x->numChannels*2);
228 x->audioOut->setAttributeValue(kTTSym_numChannels, x->numChannels);
229 x->audioIn->setAttributeValue(kTTSym_vectorSize, x->vs);
230 x->audioOut->setAttributeValue(kTTSym_vectorSize, x->vs);
232 x->audioOut->sendMessage(
TT(
"alloc"));
234 x->balance->setAttributeValue(kTTSym_sampleRate, sp[0]->s_sr);
236 dsp_addv(balance_perform, l, audioVectors);
237 sysmem_freeptr(audioVectors);
241 t_max_err balance_setBypass(t_balance *x,
void *attr,
long argc, t_atom *argv)
244 x->attrBypass = atom_getlong(argv);
245 x->balance->setAttributeValue(kTTSym_bypass, (
TTBoolean)x->attrBypass);
251 t_max_err balance_setFrequency(t_balance *x,
void *attr,
long argc, t_atom *argv)
254 x->attrFrequency = atom_getfloat(argv);
255 x->balance->setAttributeValue(
TT(
"frequency"), x->attrFrequency);
261 void balance_perform64(t_balance *x, t_object *dsp64,
double **ins,
long numins,
double **outs,
long numouts,
long sampleframes,
long flags,
void *userparam)
265 TTUInt16 vs = x->audioIn->getVectorSizeAsInt();
268 for (i=0; i < numouts; i++) {
269 x->audioIn->setVector(i, vs, ins[i]);
270 x->audioIn->setVector(i+numouts, vs, ins[i+numouts]);
273 x->balance->process(*x->audioIn, *x->audioOut);
275 for (i=0; i < x->numChannels; i++)
276 x->audioOut->getVectorCopy(i, vs, outs[i]);
283 void balance_dsp64(t_balance *x, t_object *dsp64,
short *count,
double samplerate,
long maxvectorsize,
long flags)
288 x->vs = maxvectorsize;
289 for (i=0; i < x->maxNumChannels; i++) {
290 j = x->maxNumChannels + i;
291 k = x->maxNumChannels*2 + i;
292 if (count[i] && count[j] && count[k])
296 x->audioOut->setAttributeValue(kTTSym_numChannels, x->numChannels*2);
297 x->audioOut->setAttributeValue(kTTSym_numChannels, x->numChannels);
298 x->audioIn->setAttributeValue(kTTSym_vectorSize, (
TTUInt16)maxvectorsize);
299 x->audioOut->setAttributeValue(kTTSym_vectorSize, (
TTUInt16)maxvectorsize);
301 x->audioOut->sendMessage(
TT(
"alloc"));
303 x->balance->setAttributeValue(kTTSym_sampleRate, samplerate);
304 object_method(dsp64, gensym(
"dsp_add64"), x, balance_perform64, 0, NULL);
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
std::uint16_t TTUInt16
16 bit unsigned integer
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
TTFOUNDATION_EXPORT TTEnvironment * ttEnvironment
The environment object has one instance, which is global in scope.
TTAudioObjectBase is the base class for all audio generating and processing objects in Jamoma DSP...
TTErr setAttributeValue(const TTSymbol name, TTValue &value)
Set an attribute value for an object.
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
int C74_EXPORT main(void)
Set up this class as a Max external the first time an object of this kind is instantiated.
TTErr TTObjectBaseInstantiate(const TTSymbol className, TTObjectBasePtr *returnedObjectPtr, const TTValue arguments)
DEPRECATED.
The TTAudioSignal class represents N vectors of audio samples for M channels.
void TTDSP_EXPORT TTDSPInit(const char *pathToBinaries=NULL)
Initialise the Jamoma DSP library, as well as Jamoma Foundation foundation if needed.
[doxygenAppendixC_copyExample]