Jamoma API  0.6.0.a19
TTAudioGraphOffset.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup audioGraphUtilityLib
4  *
5  * @brief offset≈: dynamically shift channels in multichannel signal
6  *
7  * @details
8  *
9  * @authors Nils Peters
10  *
11  * @copyright Copyright © 2011 by Nils Peters @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 
17 #include "TTAudioGraphOffset.h"
18 
19 #define thisTTClass TTAudioGraphOffset
20 #define thisTTClassName "audio.offset"
21 #define thisTTClassTags "audio, graph"
22 
23 
24 TT_AUDIO_CONSTRUCTOR,
25 mOffset(0)
26 {
28  setAttributeValue(TT("maxNumChannels"), arguments);
29  setProcessMethod(processAudioBypass);
30 }
31 
32 
33 // Destructor
34 TTAudioGraphOffset::~TTAudioGraphOffset()
35 {
36  ;
37 }
38 
39 TTErr TTAudioGraphOffset::setOffset(const TTValue& value)
40 {
41  mOffset = value;
42  if (mOffset < 0)
43  setProcessMethod(processAudioNegativeOffset);
44  else if (mOffset > 0)
45  setProcessMethod(processAudioPositiveOffset);
46  else
47  setProcessMethod(processAudioBypass);
48 
49  return kTTErrNone;
50 }
51 
52 TTErr TTAudioGraphOffset::processAudioNegativeOffset(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
53 {
54  TTAudioSignal& in = inputs->getSignal(0);
55  TTAudioSignal& out = outputs->getSignal(0);
56  TTSampleValuePtr inSample, outSample;
57  TTChannelCount inputChannelCount = in.getNumChannelsAsInt();
58  TTUInt16 vs = out.getVectorSizeAsInt();
59 
60  if (inputChannelCount+mOffset >= 1){
61  out.setMaxNumChannels(inputChannelCount+mOffset); //mOffset is negative here
62  out.setNumChannels(inputChannelCount+mOffset);
63 
64  for (TTChannelCount i=0; i < inputChannelCount+mOffset; i++) {
65  outSample = out.mSampleVectors[i];
66  inSample = in.mSampleVectors[i-mOffset];
67  memcpy(outSample, inSample, sizeof(TTSampleValue) * vs);
68  }
69  }
70  return kTTErrNone;
71 }
72 
73 TTErr TTAudioGraphOffset::processAudioPositiveOffset(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
74 {
75  TTAudioSignal& in = inputs->getSignal(0);
76  TTAudioSignal& out = outputs->getSignal(0);
77  TTSampleValuePtr inSample, outSample;
78  TTChannelCount inputChannelCount = in.getNumChannelsAsInt();
79  TTUInt16 vs = out.getVectorSizeAsInt();
80 
81  //TODO: make sure inputChannelCount+mOffset doesn't exeed JAG channel limit
82 
83  out.setMaxNumChannels(inputChannelCount+mOffset);
84  out.setNumChannels(inputChannelCount+mOffset);
85 
86 
87  for (TTUInt16 i=0; i < mOffset; i++) {
88  outSample = out.mSampleVectors[i];
89  memset(outSample, 0, sizeof(TTSampleValue) * vs);
90  }
91 
92  for (TTChannelCount i=0; i < inputChannelCount; i++) {
93  outSample = out.mSampleVectors[mOffset+i];
94  inSample = in.mSampleVectors[i];
95  memcpy(outSample, inSample, sizeof(TTSampleValue) * vs);
96  }
97 
98  return kTTErrNone;
99 }
100 
101 TTErr TTAudioGraphOffset::processAudioBypass(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
102 {
103  TTAudioSignal& in = inputs->getSignal(0);
104  TTAudioSignal& out = outputs->getSignal(0);
105  TTSampleValuePtr inSample, outSample;
106  TTChannelCount inputChannelCount = in.getNumChannelsAsInt();
107  TTUInt16 vs = out.getVectorSizeAsInt();
108 
109  out.setMaxNumChannels(inputChannelCount);
110  out.setNumChannels(inputChannelCount);
111 
112  for (TTChannelCount i=0; i < inputChannelCount; i++) {
113  outSample = out.mSampleVectors[i];
114  inSample = in.mSampleVectors[i];
115  memcpy(outSample, inSample, sizeof(TTSampleValue) * vs);
116  }
117 
118  return kTTErrNone;
119 }
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
16-bit unsigned integer, range is 0 through 65,535.
Definition: TTBase.h:276
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
TTErr setMaxNumChannels(const TTValue &newMaxNumChannels)
Attribute accessor.
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
offset≈: dynamically shift channels in multichannel signal
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.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
#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
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34