Jamoma API  0.6.0.a19
TTOperator.cpp
1 /*
2  * Jamoma DSP Operator Object
3  * Copyright © 2008, Timothy Place
4  *
5  * License: This code is licensed under the terms of the "New BSD License"
6  * http://creativecommons.org/licenses/BSD/
7  */
8 
9 #include "TTOperator.h"
10 
11 #define thisTTClass TTOperator
12 #define thisTTClassName "operator"
13 #define thisTTClassTags "audio, processor, math"
14 
15 
16 TT_AUDIO_CONSTRUCTOR
17 {
20 
21  // Set Defaults...
22  setAttributeValue(TT("operator"), TT("+"));
23  setAttributeValue(TT("operand"), 1.0);
24 }
25 
26 
27 TTOperator::~TTOperator()
28 {
29  ;
30 }
31 
32 
34 {
35 #define SWITCH_OPERATOR_METHODS(opName, opFunctionName) \
36  else if (mOperator == TT( #opName )) {\
37  setCalculateMethod(calculate ## opFunctionName);\
38  setProcessMethod(process ## opFunctionName);\
39  }
40 
41  mOperator = newValue;
42  if (mOperator == TT("+")) {
43  setCalculateMethod(calculateAdd);
45  }
46  else if (mOperator == TT("-")) {
47  setCalculateMethod(calculateSubtract);
48  setProcessMethod(processSubtract);
49  }
50  else if (mOperator == TT("*")) {
51  setCalculateMethod(calculateMultiply);
52  setProcessMethod(processMultiply);
53  }
54  else if (mOperator == TT("/")) {
55  setCalculateMethod(calculateDivide);
56  setProcessMethod(processDivide);
57  }
58  else if (mOperator == TT("%")) {
59  setCalculateMethod(calculateModulo);
60  setProcessMethod(processModulo);
61  }
62  else if (mOperator == TT("sqrt")) {
63  setCalculateMethod(calculateSqrt);
64  setProcessMethod(processSqrt);
65  }
66  else if (mOperator == TT("abs")) {
67  setCalculateMethod(calculateFabs);
68  setProcessMethod(processFabs);
69  }
70  else if (mOperator == TT("==")) {
71  setCalculateMethod(calculateEqual);
72  setProcessMethod(processEqual);
73  }
74  else if (mOperator == TT("!=")) {
75  setCalculateMethod(calculateNotEqual);
76  setProcessMethod(processNotEqual);
77  }
78  else if (mOperator == TT(">")) {
79  setCalculateMethod(calculateGreater);
80  setProcessMethod(processGreater);
81  }
82  else if (mOperator == TT(">=")) {
83  setCalculateMethod(calculateGreaterEqual);
84  setProcessMethod(processGreaterEqual);
85  }
86  else if (mOperator == TT("<")) {
87  setCalculateMethod(calculateSmaller);
88  setProcessMethod(processSmaller);
89  }
90  else if (mOperator == TT("<=")) {
91  setCalculateMethod(calculateSmallerEqual);
92  setProcessMethod(processSmallerEqual);
93  }
94  SWITCH_OPERATOR_METHODS(acos, Acos)
95  SWITCH_OPERATOR_METHODS(asin, Asin)
96  SWITCH_OPERATOR_METHODS(atan, Atan)
97  //SWITCH_OPERATOR_METHODS(atan2, Atan2)
98  SWITCH_OPERATOR_METHODS(ceil, Ceil)
99  SWITCH_OPERATOR_METHODS(cos, Cos)
100  SWITCH_OPERATOR_METHODS(cosh, Cosh)
101  SWITCH_OPERATOR_METHODS(exp, Exp)
102  SWITCH_OPERATOR_METHODS(floor, Floor)
103  SWITCH_OPERATOR_METHODS(log, Log)
104  SWITCH_OPERATOR_METHODS(log10, Log10)
105  SWITCH_OPERATOR_METHODS(sin, Sin)
106  SWITCH_OPERATOR_METHODS(sinh, Sinh)
107  SWITCH_OPERATOR_METHODS(tan, Tan)
108  SWITCH_OPERATOR_METHODS(tanh, Tanh)
109  else
110  return kTTErrInvalidValue;
111 
112  return kTTErrNone;
113 }
114 
115 
117 {
118  TTInt64 i;
119  TTUInt32 count;
120 
121  mOperand = newValue;
122  mOperandIsPowerOfTwo = false;
123 
124  i = (TTInt64)mOperand;
125  if (i - mOperand)
126  mOperandIsInteger = false;
127  else
128  mOperandIsInteger = true;
129 
130  if (mOperandIsInteger) {
131  for (count = 0; i != 0; count++)
132  i &= i-1;
133  if (count == 1)
134  mOperandIsPowerOfTwo = true;
135  }
136  return kTTErrNone;
137 }
138 
139 #if 0
140 #pragma mark -
141 #pragma mark operands
142 #endif
143 
144 TTErr TTOperator::calculateAdd(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
145 {
146  y = x + mOperand;
147  return kTTErrNone;
148 }
149 
150 TTErr TTOperator::calculateSubtract(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
151 {
152  y = x - mOperand;
153  return kTTErrNone;
154 }
155 
156 TTErr TTOperator::calculateMultiply(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
157 {
158  y = x * mOperand;
159  return kTTErrNone;
160 }
161 
162 TTErr TTOperator::calculateDivide(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
163 {
164  y = x / mOperand;
165  return kTTErrNone;
166 }
167 
168 TTErr TTOperator::calculateModulo(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
169 {
170  TTUInt64 operander = (TTUInt64)mOperand;
171 
172  y = fmod(x, operander);
173  return kTTErrNone;
174 }
175 
176 TTErr TTOperator::calculateSqrt(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
177 {
178  y = sqrt(x);
179  return kTTErrNone;
180 }
181 
182 
183 TTErr TTOperator::calculateFabs(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
184 {
185  y = fabs(x);
186  return kTTErrNone;
187 }
188 
189 
190 
192 {
193  if (inputs->numAudioSignals != 1)
194  return processAddSignal(inputs, outputs);
195  else {
196  TT_WRAP_CALCULATE_METHOD(calculateAdd);
197  }
198 }
199 
200 TTErr TTOperator::processAddSignal(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
201 {
202  TTAudioSignal& in1 = inputs->getSignal(0);
203  TTAudioSignal& in2 = inputs->getSignal(1);
204  TTAudioSignal& out = outputs->getSignal(0);
205  TTUInt16 vs;
206  TTSampleValuePtr in1Sample;
207  TTSampleValuePtr in2Sample;
208  TTSampleValuePtr outSample;
209  TTChannelCount numChannels;
210  TTChannelCount channel;
211 
212  if (in2.getNumChannelsAsInt() == 1) { // If the operand signal is one only channel, then we apply that to all channels of in1
213  numChannels = in1.getNumChannelsAsInt();
214  for (channel=0; channel<numChannels; channel++) {
215  in2Sample = in2.mSampleVectors[0];
216  in1Sample = in1.mSampleVectors[channel];
217  outSample = out.mSampleVectors[channel];
218  vs = in1.getVectorSizeAsInt();
219  while (vs--)
220  *outSample++ = *in1Sample++ + *in2Sample++;
221  }
222  }
223  else { // Otherwise we apply channel 1 to channel 1, channel 2 to channel 2, etc.
224  numChannels = TTAudioSignal::getMinChannelCount(in1, in2);
225  out.setNumChannels(numChannels);
226  for (channel=0; channel<numChannels; channel++) {
227  in1Sample = in1.mSampleVectors[channel];
228  in2Sample = in2.mSampleVectors[channel];
229  outSample = out.mSampleVectors[channel];
230  vs = in1.getVectorSizeAsInt();
231  while (vs--)
232  *outSample++ = *in1Sample++ + *in2Sample++;
233  }
234  }
235  return kTTErrNone;
236 }
237 
238 
239 
240 TTErr TTOperator::processSubtract(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
241 {
242  if (inputs->numAudioSignals != 1)
243  return processSubtractSignal(inputs, outputs);
244  else {
245  TT_WRAP_CALCULATE_METHOD(calculateSubtract);
246  }
247 }
248 
249 
250 TTErr TTOperator::processSubtractSignal(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
251 {
252  TTAudioSignal& in1 = inputs->getSignal(0);
253  TTAudioSignal& in2 = inputs->getSignal(1);
254  TTAudioSignal& out = outputs->getSignal(0);
255  TTUInt16 vs;
256  TTSampleValuePtr in1Sample;
257  TTSampleValuePtr in2Sample;
258  TTSampleValuePtr outSample;
259  TTChannelCount numChannels;
260  TTChannelCount channel;
261 
262  if (in2.getNumChannelsAsInt() == 1) { // If the operand signal is one only channel, then we apply that to all channels of in1
263  numChannels = in1.getNumChannelsAsInt();
264  for (channel=0; channel<numChannels; channel++) {
265  in2Sample = in2.mSampleVectors[0];
266  in1Sample = in1.mSampleVectors[channel];
267  outSample = out.mSampleVectors[channel];
268  vs = in1.getVectorSizeAsInt();
269  while (vs--)
270  *outSample++ = *in1Sample++ - *in2Sample++;
271  }
272  }
273  else { // Otherwise we apply channel 1 to channel 1, channel 2 to channel 2, etc.
274  numChannels = TTAudioSignal::getMinChannelCount(in1, in2);
275  out.setNumChannels(numChannels);
276  for (channel=0; channel<numChannels; channel++) {
277  in1Sample = in1.mSampleVectors[channel];
278  in2Sample = in2.mSampleVectors[channel];
279  outSample = out.mSampleVectors[channel];
280  vs = in1.getVectorSizeAsInt();
281  while (vs--)
282  *outSample++ = *in1Sample++ - *in2Sample++;
283  }
284  }
285  return kTTErrNone;
286 }
287 
288 
289 
290 TTErr TTOperator::processMultiply(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
291 {
292  if (inputs->numAudioSignals != 1)
293  return processMultiplySignal(inputs, outputs);
294  else {
295  TT_WRAP_CALCULATE_METHOD(calculateMultiply);
296  }
297 }
298 
299 TTErr TTOperator::processMultiplySignal(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
300 {
301  TTAudioSignal& in1 = inputs->getSignal(0);
302  TTAudioSignal& in2 = inputs->getSignal(1);
303  TTAudioSignal& out = outputs->getSignal(0);
304  TTUInt16 vs;
305  TTSampleValuePtr in1Sample;
306  TTSampleValuePtr in2Sample;
307  TTSampleValuePtr outSample;
308  TTChannelCount numChannels;
309  TTChannelCount channel;
310 
311  if (in2.getNumChannelsAsInt() == 1) { // If the operand signal is one only channel, then we apply that to all channels of in1
312  numChannels = in1.getNumChannelsAsInt();
313  for (channel=0; channel<numChannels; channel++) {
314  in2Sample = in2.mSampleVectors[0];
315  in1Sample = in1.mSampleVectors[channel];
316  outSample = out.mSampleVectors[channel];
317  vs = in1.getVectorSizeAsInt();
318  while (vs--)
319  *outSample++ = *in1Sample++ * *in2Sample++;
320  }
321  }
322  else { // Otherwise we apply channel 1 to channel 1, channel 2 to channel 2, etc.
323  numChannels = TTAudioSignal::getMinChannelCount(in1, in2);
324  out.setNumChannels(numChannels);
325  for (channel=0; channel<numChannels; channel++) {
326  in1Sample = in1.mSampleVectors[channel];
327  in2Sample = in2.mSampleVectors[channel];
328  outSample = out.mSampleVectors[channel];
329  vs = in1.getVectorSizeAsInt();
330  while (vs--)
331  *outSample++ = *in1Sample++ * *in2Sample++;
332  }
333  }
334  return kTTErrNone;
335 }
336 
337 
338 
339 TTErr TTOperator::processDivide(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
340 {
341  if (inputs->numAudioSignals != 1)
342  return processDivideSignal(inputs, outputs);
343  else {
344  TT_WRAP_CALCULATE_METHOD(calculateDivide);
345  }
346 }
347 
348 
349 TTErr TTOperator::processDivideSignal(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
350 {
351  TTAudioSignal& in1 = inputs->getSignal(0);
352  TTAudioSignal& in2 = inputs->getSignal(1);
353  TTAudioSignal& out = outputs->getSignal(0);
354  TTUInt16 vs;
355  TTSampleValuePtr in1Sample;
356  TTSampleValuePtr in2Sample;
357  TTSampleValuePtr outSample;
358  TTChannelCount numChannels;
359  TTChannelCount channel;
360 
361  if (in2.getNumChannelsAsInt() == 1) { // If the operand signal is one only channel, then we apply that to all channels of in1
362  numChannels = in1.getNumChannelsAsInt();
363  for (channel=0; channel<numChannels; channel++) {
364  in2Sample = in2.mSampleVectors[0];
365  in1Sample = in1.mSampleVectors[channel];
366  outSample = out.mSampleVectors[channel];
367  vs = in1.getVectorSizeAsInt();
368  while (vs--)
369  *outSample++ = *in1Sample++ / *in2Sample++;
370  }
371  }
372  else { // Otherwise we apply channel 1 to channel 1, channel 2 to channel 2, etc.
373  numChannels = TTAudioSignal::getMinChannelCount(in1, in2);
374  out.setNumChannels(numChannels);
375  for (channel=0; channel<numChannels; channel++) {
376  in1Sample = in1.mSampleVectors[channel];
377  in2Sample = in2.mSampleVectors[channel];
378  outSample = out.mSampleVectors[channel];
379  vs = in1.getVectorSizeAsInt();
380  while (vs--)
381  *outSample++ = *in1Sample++ / *in2Sample++;
382  }
383  }
384  return kTTErrNone;
385 }
386 
387 
388 
389 TTErr TTOperator::processEqual(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
390 {
391  if (inputs->numAudioSignals != 1)
392  return processEqualSignal(inputs, outputs);
393  else {
394  TT_WRAP_CALCULATE_METHOD(calculateEqual);
395  }
396 }
397 
398 TTErr TTOperator::calculateEqual(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
399 {
400  y = (x == mOperand);
401  return kTTErrNone;
402 }
403 
404 TTErr TTOperator::processEqualSignal(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
405 { //TODO
406  TTAudioSignal& in1 = inputs->getSignal(0);
407  TTAudioSignal& in2 = inputs->getSignal(1);
408  TTAudioSignal& out = outputs->getSignal(0);
409  TTUInt16 vs;
410  TTSampleValuePtr in1Sample;
411  TTSampleValuePtr in2Sample;
412  TTSampleValuePtr outSample;
413  TTChannelCount numChannels;
414  TTChannelCount channel;
415 
416  if (in2.getNumChannelsAsInt() == 1) { // If the operand signal is one only channel, then we apply that to all channels of in1
417  numChannels = in1.getNumChannelsAsInt();
418  for (channel=0; channel<numChannels; channel++) {
419  in2Sample = in2.mSampleVectors[0];
420  in1Sample = in1.mSampleVectors[channel];
421  outSample = out.mSampleVectors[channel];
422  vs = in1.getVectorSizeAsInt();
423  while (vs--)
424  *outSample++ = (*in1Sample++ == *in2Sample++);
425  }
426  }
427  else { // Otherwise we apply channel 1 to channel 1, channel 2 to channel 2, etc.
428  numChannels = TTAudioSignal::getMinChannelCount(in1, in2);
429  out.setNumChannels(numChannels);
430  for (channel=0; channel<numChannels; channel++) {
431  in1Sample = in1.mSampleVectors[channel];
432  in2Sample = in2.mSampleVectors[channel];
433  outSample = out.mSampleVectors[channel];
434  vs = in1.getVectorSizeAsInt();
435  while (vs--)
436  *outSample++ = (*in1Sample++ == *in2Sample++);
437  }
438  }
439  return kTTErrNone;
440 }
441 
442 TTErr TTOperator::processNotEqual(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
443 {
444  if (inputs->numAudioSignals != 1)
445  return processNotEqualSignal(inputs, outputs);
446  else {
447  TT_WRAP_CALCULATE_METHOD(calculateNotEqual);
448  }
449 }
450 
451 TTErr TTOperator::calculateNotEqual(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
452 {
453  y = (x == mOperand);
454  return kTTErrNone;
455 }
456 
457 TTErr TTOperator::processNotEqualSignal(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
458 { //TODO
459  TTAudioSignal& in1 = inputs->getSignal(0);
460  TTAudioSignal& in2 = inputs->getSignal(1);
461  TTAudioSignal& out = outputs->getSignal(0);
462  TTUInt16 vs;
463  TTSampleValuePtr in1Sample;
464  TTSampleValuePtr in2Sample;
465  TTSampleValuePtr outSample;
466  TTChannelCount numChannels;
467  TTChannelCount channel;
468 
469  if (in2.getNumChannelsAsInt() == 1) { // If the operand signal is one only channel, then we apply that to all channels of in1
470  numChannels = in1.getNumChannelsAsInt();
471  for (channel=0; channel<numChannels; channel++) {
472  in2Sample = in2.mSampleVectors[0];
473  in1Sample = in1.mSampleVectors[channel];
474  outSample = out.mSampleVectors[channel];
475  vs = in1.getVectorSizeAsInt();
476  while (vs--)
477  *outSample++ = (*in1Sample++ != *in2Sample++);
478  }
479  }
480  else { // Otherwise we apply channel 1 to channel 1, channel 2 to channel 2, etc.
481  numChannels = TTAudioSignal::getMinChannelCount(in1, in2);
482  out.setNumChannels(numChannels);
483  for (channel=0; channel<numChannels; channel++) {
484  in1Sample = in1.mSampleVectors[channel];
485  in2Sample = in2.mSampleVectors[channel];
486  outSample = out.mSampleVectors[channel];
487  vs = in1.getVectorSizeAsInt();
488  while (vs--)
489  *outSample++ = (*in1Sample++ != *in2Sample++);
490  }
491  }
492  return kTTErrNone;
493 }
494 
495 
496 TTErr TTOperator::processGreaterEqual(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
497 {
498  if (inputs->numAudioSignals != 1)
499  return processGreaterEqualSignal(inputs, outputs);
500  else {
501  TT_WRAP_CALCULATE_METHOD(calculateGreaterEqual);
502  }
503 }
504 
505 TTErr TTOperator::calculateGreaterEqual(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
506 {
507  y= (x >= mOperand);
508  return kTTErrNone;
509 }
510 
511 TTErr TTOperator::processGreaterEqualSignal(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
512 { //TODO
513  TTAudioSignal& in1 = inputs->getSignal(0);
514  TTAudioSignal& in2 = inputs->getSignal(1);
515  TTAudioSignal& out = outputs->getSignal(0);
516  TTUInt16 vs;
517  TTSampleValuePtr in1Sample;
518  TTSampleValuePtr in2Sample;
519  TTSampleValuePtr outSample;
520  TTChannelCount numChannels;
521  TTChannelCount channel;
522 
523  if (in2.getNumChannelsAsInt() == 1) { // If the operand signal is one only channel, then we apply that to all channels of in1
524  numChannels = in1.getNumChannelsAsInt();
525  for (channel=0; channel<numChannels; channel++) {
526  in2Sample = in2.mSampleVectors[0];
527  in1Sample = in1.mSampleVectors[channel];
528  outSample = out.mSampleVectors[channel];
529  vs = in1.getVectorSizeAsInt();
530  while (vs--)
531  *outSample++ = (*in1Sample++ >= *in2Sample++);
532  }
533  }
534  else { // Otherwise we apply channel 1 to channel 1, channel 2 to channel 2, etc.
535  numChannels = TTAudioSignal::getMinChannelCount(in1, in2);
536  out.setNumChannels(numChannels);
537  for (channel=0; channel<numChannels; channel++) {
538  in1Sample = in1.mSampleVectors[channel];
539  in2Sample = in2.mSampleVectors[channel];
540  outSample = out.mSampleVectors[channel];
541  vs = in1.getVectorSizeAsInt();
542  while (vs--)
543  *outSample++ = (*in1Sample++ >= *in2Sample++);
544  }
545  }
546  return kTTErrNone;
547 }
548 
549 TTErr TTOperator::processGreater(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
550 {
551  if (inputs->numAudioSignals != 1)
552  return processGreaterSignal(inputs, outputs);
553  else {
554  TT_WRAP_CALCULATE_METHOD(calculateGreater);
555  }
556 }
557 
558 TTErr TTOperator::calculateGreater(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
559 {
560  y = (x > mOperand);
561  return kTTErrNone;
562 }
563 
564 TTErr TTOperator::processGreaterSignal(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
565 { //TODO
566  TTAudioSignal& in1 = inputs->getSignal(0);
567  TTAudioSignal& in2 = inputs->getSignal(1);
568  TTAudioSignal& out = outputs->getSignal(0);
569  TTUInt16 vs;
570  TTSampleValuePtr in1Sample;
571  TTSampleValuePtr in2Sample;
572  TTSampleValuePtr outSample;
573  TTChannelCount numChannels;
574  TTChannelCount channel;
575 
576  if (in2.getNumChannelsAsInt() == 1) { // If the operand signal is one only channel, then we apply that to all channels of in1
577  numChannels = in1.getNumChannelsAsInt();
578  for (channel=0; channel<numChannels; channel++) {
579  in2Sample = in2.mSampleVectors[0];
580  in1Sample = in1.mSampleVectors[channel];
581  outSample = out.mSampleVectors[channel];
582  vs = in1.getVectorSizeAsInt();
583  while (vs--)
584  *outSample++ = (*in1Sample++ > *in2Sample++);
585  }
586  }
587  else { // Otherwise we apply channel 1 to channel 1, channel 2 to channel 2, etc.
588  numChannels = TTAudioSignal::getMinChannelCount(in1, in2);
589  out.setNumChannels(numChannels);
590  for (channel=0; channel<numChannels; channel++) {
591  in1Sample = in1.mSampleVectors[channel];
592  in2Sample = in2.mSampleVectors[channel];
593  outSample = out.mSampleVectors[channel];
594  vs = in1.getVectorSizeAsInt();
595  while (vs--)
596  *outSample++ = (*in1Sample++ > *in2Sample++);
597  }
598  }
599  return kTTErrNone;
600 }
601 
602 
603 TTErr TTOperator::processSmallerEqual(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
604 {
605  if (inputs->numAudioSignals != 1)
606  return processSmallerEqualSignal(inputs, outputs);
607  else {
608  TT_WRAP_CALCULATE_METHOD(calculateSmallerEqual);
609  }
610 }
611 
612 TTErr TTOperator::calculateSmallerEqual(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
613 {
614  y = (x <= mOperand);
615  return kTTErrNone;
616 }
617 
618 TTErr TTOperator::processSmallerEqualSignal(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
619 { //TODO
620  TTAudioSignal& in1 = inputs->getSignal(0);
621  TTAudioSignal& in2 = inputs->getSignal(1);
622  TTAudioSignal& out = outputs->getSignal(0);
623  TTUInt16 vs;
624  TTSampleValuePtr in1Sample;
625  TTSampleValuePtr in2Sample;
626  TTSampleValuePtr outSample;
627  TTChannelCount numChannels;
628  TTChannelCount channel;
629 
630  if (in2.getNumChannelsAsInt() == 1) { // If the operand signal is one only channel, then we apply that to all channels of in1
631  numChannels = in1.getNumChannelsAsInt();
632  for (channel=0; channel<numChannels; channel++) {
633  in2Sample = in2.mSampleVectors[0];
634  in1Sample = in1.mSampleVectors[channel];
635  outSample = out.mSampleVectors[channel];
636  vs = in1.getVectorSizeAsInt();
637  while (vs--)
638  *outSample++ = (*in1Sample++ <= *in2Sample++);
639  }
640  }
641  else { // Otherwise we apply channel 1 to channel 1, channel 2 to channel 2, etc.
642  numChannels = TTAudioSignal::getMinChannelCount(in1, in2);
643  out.setNumChannels(numChannels);
644  for (channel=0; channel<numChannels; channel++) {
645  in1Sample = in1.mSampleVectors[channel];
646  in2Sample = in2.mSampleVectors[channel];
647  outSample = out.mSampleVectors[channel];
648  vs = in1.getVectorSizeAsInt();
649  while (vs--)
650  *outSample++ = (*in1Sample++ <= *in2Sample++);
651  }
652  }
653  return kTTErrNone;
654 }
655 
656 TTErr TTOperator::processSmaller(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
657 {
658  if (inputs->numAudioSignals != 1)
659  return processSmallerSignal(inputs, outputs);
660  else {
661  TT_WRAP_CALCULATE_METHOD(calculateSmaller);
662  }
663 }
664 
665 TTErr TTOperator::calculateSmaller(const TTFloat64& x, TTFloat64& y, TTPtrSizedInt data)
666 {
667  y = (x < mOperand);
668  return kTTErrNone;
669 }
670 
671 TTErr TTOperator::processSmallerSignal(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
672 { //TODO
673  TTAudioSignal& in1 = inputs->getSignal(0);
674  TTAudioSignal& in2 = inputs->getSignal(1);
675  TTAudioSignal& out = outputs->getSignal(0);
676  TTUInt16 vs;
677  TTSampleValuePtr in1Sample;
678  TTSampleValuePtr in2Sample;
679  TTSampleValuePtr outSample;
680  TTChannelCount numChannels;
681  TTChannelCount channel;
682 
683  if (in2.getNumChannelsAsInt() == 1) { // If the operand signal is one only channel, then we apply that to all channels of in1
684  numChannels = in1.getNumChannelsAsInt();
685  for (channel=0; channel<numChannels; channel++) {
686  in2Sample = in2.mSampleVectors[0];
687  in1Sample = in1.mSampleVectors[channel];
688  outSample = out.mSampleVectors[channel];
689  vs = in1.getVectorSizeAsInt();
690  while (vs--)
691  *outSample++ = (*in1Sample++ < *in2Sample++);
692  }
693  }
694  else { // Otherwise we apply channel 1 to channel 1, channel 2 to channel 2, etc.
695  numChannels = TTAudioSignal::getMinChannelCount(in1, in2);
696  out.setNumChannels(numChannels);
697  for (channel=0; channel<numChannels; channel++) {
698  in1Sample = in1.mSampleVectors[channel];
699  in2Sample = in2.mSampleVectors[channel];
700  outSample = out.mSampleVectors[channel];
701  vs = in1.getVectorSizeAsInt();
702  while (vs--)
703  *outSample++ = (*in1Sample++ < *in2Sample++);
704  }
705  }
706  return kTTErrNone;
707 }
708 
709 
710 TTErr TTOperator::processModulo(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
711 {
712  if (inputs->numAudioSignals != 1)
713  return processModuloSignal(inputs, outputs);
714  else {
715  TT_WRAP_CALCULATE_METHOD(calculateModulo);
716  }
717 }
718 
719 TTErr TTOperator::processModuloSignal(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
720 {
721  TTAudioSignal& in1 = inputs->getSignal(0);
722  TTAudioSignal& in2 = inputs->getSignal(1);
723  TTAudioSignal& out = outputs->getSignal(0);
724  TTUInt16 vs;
725  TTSampleValuePtr in1Sample;
726  TTSampleValuePtr in2Sample;
727  TTSampleValuePtr outSample;
728  TTChannelCount numChannels;
729  TTChannelCount channel;
730  TTUInt64 temp;
731  TTUInt64 intOperand;
732 
733  if (in2.getNumChannelsAsInt() == 1) { // If the operand signal is one only channel, then we apply that to all channels of in1
734  numChannels = in1.getNumChannelsAsInt();
735  for (channel=0; channel<numChannels; channel++) {
736  in2Sample = in2.mSampleVectors[0];
737  in1Sample = in1.mSampleVectors[channel];
738  outSample = out.mSampleVectors[channel];
739  vs = in1.getVectorSizeAsInt();
740  if (mOperandIsPowerOfTwo) {
741  while (vs--) {
742  temp = TTUInt64(*in1Sample++);
743  intOperand = TTUInt64(*in2Sample++);
744  *outSample++ = TTSampleValue(temp & intOperand);
745  }
746  }
747  else {
748  while (vs--)
749  *outSample++ = fmod(*in1Sample++, *in2Sample++);
750  }
751  }
752  }
753  else { // Otherwise we apply channel 1 to channel 1, channel 2 to channel 2, etc.
754  numChannels = TTAudioSignal::getMinChannelCount(in1, in2);
755  out.setNumChannels(numChannels);
756  for (channel=0; channel<numChannels; channel++) {
757  in1Sample = in1.mSampleVectors[channel];
758  in2Sample = in2.mSampleVectors[channel];
759  outSample = out.mSampleVectors[channel];
760  vs = in1.getVectorSizeAsInt();
761 
762  if (mOperandIsPowerOfTwo) {
763  while (vs--) {
764  temp = TTUInt64(*in1Sample++);
765  intOperand = TTUInt64(*in2Sample++);
766  *outSample++ = TTSampleValue(temp & intOperand);
767  }
768  }
769  else {
770  while (vs--)
771  *outSample++ = fmod(*in1Sample++, *in2Sample++);
772  }
773  }
774  }
775  return kTTErrNone;
776 }
777 
778 
779 TTErr TTOperator::processSqrt(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
780 {
781  TT_WRAP_CALCULATE_METHOD(calculateSqrt);
782 
783 }
784 
785 
786 TTErr TTOperator::processFabs(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
787 {
788  TT_WRAP_CALCULATE_METHOD(calculateFabs);
789 
790 }
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
An inappropriate value was specified for an attribute or variable.
Definition: TTBase.h:349
TTSymbol mOperator
The type of calculation to perform.
Definition: TTOperator.h:21
std::uint64_t TTUInt64
64 bit unsigned integer
Definition: TTBase.h:180
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTBoolean mOperandIsInteger
Set to true if there is no fractional part.
Definition: TTOperator.h:23
Symbol type.
Definition: TTBase.h:282
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
TTErr processAdd(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
A standard audio processing method as used by TTBlue objects.
Definition: TTOperator.cpp:191
std::int64_t TTInt64
64 bit signed integer
Definition: TTBase.h:179
#define setCalculateMethod(methodName)
A convenience macro to be used by subclasses for setting the calculate method.
TTErr setOperator(const TTValue &newValue)
setter for the operator attribute.
Definition: TTOperator.cpp:33
64-bit floating point
Definition: TTBase.h:272
TTBoolean mOperandIsPowerOfTwo
Set to true is the operand is a power of two to optimize some operations.
Definition: TTOperator.h:24
TTFloat64 mOperand
The right-hand value of the calculation.
Definition: TTOperator.h:22
static TTChannelCount getMinChannelCount(const TTAudioSignal &signal1, const TTAudioSignal &signal2)
Use this class method to determine the least number of channels the two signals have in common...
The TTAudioSignal class represents N vectors of audio samples for M channels.
Definition: TTAudioSignal.h:57
TTSampleValue ** mSampleVectors
An array of pointers to the first sample in each vector. Declared Public for fast access...
Definition: TTAudioSignal.h:74
TTUInt16 TTChannelCount
Data type used when counting the number of channels in multi-channel audio signals and processes...
Definition: TTAudioSignal.h:31
A simple container for an array of TTAudioSignal pointers.
long TTPtrSizedInt
An integer that is the same size as a pointer.
Definition: TTBase.h:240
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
No Error.
Definition: TTBase.h:343
TTErr setOperand(const TTValue &newValue)
setter for the operand attribute.
Definition: TTOperator.cpp:116
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTChannelCount numAudioSignals
The number of audio signal pointers which are actually valid.