Jamoma API  0.6.0.a19
TTMatrixGain.cpp
1 /*
2  * Jamoma MatrixProcessingLib: Gain
3  * Copyright © 2011, 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 "TTMatrixGain.h"
10 
11 #define thisTTClass TTMatrixGain
12 #define thisTTClassName "matrix.gain"
13 #define thisTTClassTags "foundationMatrixProcessingLib, matrix"
14 
15 
17  mGain(1.0)
18 {
20  setMatrixCalculateMethod(matrixCalculateGain);
21 }
22 
23 
24 TTMatrixGain::~TTMatrixGain()
25 {
26  ;
27 }
28 
29 
30 template<typename T>
31 TTErr TTMatrixGain::doCalculateGain(const TTMatrixBasePtr inMatrix, TTMatrixBasePtr outMatrix)
32 {
33  T* inData = (T*)inMatrix->getLockedPointer();
34  T* outData = (T*)outMatrix->getLockedPointer();
35  TTUInt32 valueCount = inMatrix->getDataCount();
36 
37  for (TTUInt32 i=0; i<valueCount; i++)
38  *outData++ = *inData++ * mGain;
39 
40  outMatrix->releaseLockedPointer();
41  inMatrix->releaseLockedPointer();
42  return kTTErrNone;
43 }
44 
45 
46 TTErr TTMatrixGain::matrixCalculateGain(TTMatrixArray& inputMatrices, TTMatrixArray& outputMatrices)
47 {
48  TTMatrixBasePtr inMatrix = inputMatrices.getMatrix(0);
49  TTMatrixBasePtr outMatrix = outputMatrices.getMatrix(0);
50  TTErr err;
51 
52  outMatrix->adaptTo(inMatrix); // set dimensions, element count, datatype, etc.
53 
54  TTMATRIX_PROCESS_MATRICES_WITH_NAMED_TEMPLATE(doCalculateGain, inMatrix, outMatrix);
55 
56  return err;
57 }
58 
TTBytePtr getLockedPointer()
Return a pointer to the matrix data, and lock the matrix so that others cannot access the data...
Definition: TTMatrixBase.h:547
#define addAttribute(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
Definition: TTAttribute.h:29
TTUInt32 getDataCount()
Simple data accessor.
Definition: TTMatrixBase.h:203
TTErr adaptTo(const TTMatrixBase &anotherMatrix)
Set dimensions, element count, datatype, etc.
2-dimensional matrix of compound values with N elements each.
Definition: TTMatrixBase.h:41
64-bit floating point
Definition: TTBase.h:272
An array of TTMatrix instance pointers.
Definition: TTMatrixArray.h:25
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
void releaseLockedPointer()
Release a locked pointer obtained using getLockedPointer().
Definition: TTMatrixBase.h:556
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
No Error.
Definition: TTBase.h:343
TT_OBJECT_CONSTRUCTOR
Constructor macro.