Jamoma API  0.6.0.a19
TTAudioObject.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspLibrary
4  *
5  * @brief #TTAudioObjectBase is the Jamoma DSP Audio Object Base Class
6  *
7  * @details
8  *
9  * @authors Tim Place, Nils Peters, Trond Lossius
10  *
11  * @copyright Copyright © 2008 by Timothy Place @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 #ifndef __TT_AUDIO_OBJECT_H__
18 #define __TT_AUDIO_OBJECT_H__
19 
20 #include "TTObject.h"
21 #include "TTAudioObjectBase.h"
22 
23 
24 /** Wrap TTAudioSignal instances for convenience. */
25 class TTAudio : public TTObject {
26 public:
27  TTAudio(int aChannelCount):
28  TTObject(kTTSym_audiosignal, aChannelCount)
29  {}
30 
31  TTAudioSignalPtr instance() const
32  {
33  return (TTAudioSignalPtr)mObjectInstance;
34  }
35 
36  int getVectorSizeAsInt()
37  {
38  return instance()->getVectorSizeAsInt();
39  }
40 
41  void setVectorSizeWithInt(int aVectorSize)
42  {
43  instance()->setVectorSizeWithInt(aVectorSize);
44  }
45 
46  void alloc()
47  {
48  instance()->alloc();
49  }
50 
51  TTErr allocWithVectorSize(const TTUInt16 aNewVectorSize)
52  {
53  return instance()->allocWithVectorSize(aNewVectorSize);
54  }
55 
56  void setNumChannels(int aChannelCount)
57  {
58  instance()->setNumChannels(aChannelCount);
59  }
60 
61 
62  TTErr setVector(const TTChannelCount channel, const TTUInt16 vectorSize, const TTSampleValuePtr newVector)
63  {
64  return instance()->setVector(channel, vectorSize, newVector);
65  }
66 
67 
68  TTErr getVectorCopy(const TTChannelCount channel, const TTUInt16 theVectorSize, TTSampleValue* returnedVector)
69  {
70  return instance()->getVectorCopy(channel, theVectorSize, returnedVector);
71  }
72 
73 
74  TTSampleValue** rawSamples()
75  {
76  return instance()->mSampleVectors;
77  }
78 
79  void clear()
80  {
81  instance()->clear();
82  }
83 
84 };
85 
86 
87 /** Wrap TTAudioSignalArray instances for convenience. */
88 class TTAudioArray : public TTObject {
89 public:
90  TTAudioArray(int aChannelCount):
91  TTObject(kTTSym_audiosignalarray, aChannelCount)
92  {}
93 
94  TTAudioSignalArrayPtr instance()
95  {
96  return (TTAudioSignalArrayPtr)mObjectInstance;
97  }
98 
99  void setStreamCount(TTInt32 newStreamCount)
100  {
101  instance()->setMaxNumAudioSignals(newStreamCount);
102  instance()->numAudioSignals = newStreamCount;
103  }
104 
105  TTErr setStream(TTChannelCount index, const TTAudio& aStream)
106  {
107  //instance()->setSignal(index, (TTAudioSignalPtr)TTObjectBaseReference((TTObjectBasePtr)aStream.instance()));
108  // above reference incrementing now moved into the setSignal() method below
109  instance()->setSignal(index, aStream.instance());
110  return kTTErrNone;
111  }
112 
113  TTErr setStream(TTChannelCount index, const TTAudioSignalPtr aSignal)
114  {
115  //instance()->setSignal(index, (TTAudioSignalPtr)TTObjectBaseReference((TTObjectBasePtr)aSignal));
116  // above reference incrementing now moved into the setSignal() method below
117  instance()->setSignal(index, aSignal);
118  return kTTErrNone;
119  }
120 
121  TTAudioSignal& getSignal(TTChannelCount index)
122  {
123  return instance()->getSignal(index);
124  }
125 
126  void allocAllWithVectorSize(TTUInt16 vs)
127  {
128  instance()->allocAllWithVectorSize(vs);
129  }
130 
131  TTUInt16 getVectorSize()
132  {
133  return instance()->getVectorSize();
134  }
135 
136  TTChannelCount getMaxChannelCount()
137  {
138  return instance()->getMaxNumChannels();
139  }
140 
141  void matchNumChannels(TTAudioArray& anotherArray)
142  {
143  instance()->matchNumChannels(anotherArray.instance());
144  }
145 };
146 
147 
148 inline TTErr TTAudioObjectBase::process(TTAudio& inputs, TTAudio& outputs)
149 {
150  return process(inputs.instance(), outputs.instance());
151 }
152 
153 
154 /** Wrap audio objects for convenience. */
155 class TTAudioObject : public TTObject {
156 
157 public:
158  TTAudioObject(const TTSymbol aClassName, const TTValue arguments = kTTValNONE):
159  TTObject(aClassName, arguments)
160  {}
161 
162  // copy constructor is fully implemented in the super-class
163 
164  /** like a copy constructor -- but from TTObject to TTAudioObject */
165  TTAudioObject(const TTObject& anOtherObject) :
166  TTObject(anOtherObject)
167  {}
168 
169 
170  /** Set the object's sample rate. */
171  TTErr setSampleRate(const TTUInt32& newSampleRate)
172  {
173  return TTAudioObjectBasePtr(mObjectInstance)->setSampleRate(newSampleRate);
174  }
175 
176 
177  /** Allocate neccessary memory and make configuration adjustments so the object is able
178  to process additional channels of audio. */
179  TTErr adaptMaxChannelCount(const TTUInt16 aNewChannelCount)
180  {
181  return TTAudioObjectBasePtr(mObjectInstance)->adaptMaxNumChannels(aNewChannelCount);
182  }
183 
184 
185  TTErr process(TTAudioSignal& out)
186  {
187  return TTAudioObjectBasePtr(mObjectInstance)->process(out);
188  }
189 
190  TTErr process(TTAudio& out)
191  {
192  return process(*out.instance());
193  }
194 
196  {
197  return TTAudioObjectBasePtr(mObjectInstance)->process(in, out);
198  }
199 
200  TTErr process(TTAudioSignal& in, TTAudioSignal& out)
201  {
202  return TTAudioObjectBasePtr(mObjectInstance)->process(in, out);
203  }
204 
205  TTErr process(TTAudio* in, TTAudio* out)
206  {
207  return TTAudioObjectBasePtr(mObjectInstance)->process(in->instance(), out->instance());
208  }
209 
210  TTErr process(TTAudioArray& in, TTAudioArray& out)
211  {
212  return TTAudioObjectBasePtr(mObjectInstance)->process(in.instance(), out.instance());
213  }
214 
215 
216  /** Calculate a single sample of output for a single sample of input.
217  @param x The input to the function.
218  @param y The output of the function.
219  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
220  */
222  {
223  return TTAudioObjectBasePtr(mObjectInstance)->calculate(x, y);
224  }
225 
226 
227  /** Calculate a single sample of output for a single sample of input.
228  @param x The input to the function.
229  @param y The output of the function.
230  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
231  */
233  {
234  return TTAudioObjectBasePtr(mObjectInstance)->calculate(x, y);
235  }
236 
237 
238 };
239 
240 
241 
242 #endif // __TT_AUDIO_OBJECT_H__
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTErr calculate(const TTFloat64 &x, TTFloat64 &y)
Calculate a single sample of output for a single sample of input.
Create Jamoma object instances.
void setMaxNumAudioSignals(TTChannelCount newMaxNumAudioSignals)
Note: calling this function will invalidate all audioSignal pointers contained within the array...
TTErr adaptMaxChannelCount(const TTUInt16 aNewChannelCount)
Allocate neccessary memory and make configuration adjustments so the object is able to process additi...
Wrap TTAudioSignalArray instances for convenience.
Definition: TTAudioObject.h:88
TTObject()
Constructor to create an empyt container which will be assigned/copied-to at a later point...
Definition: TTObject.cpp:44
Create and use Jamoma object instances.
Definition: TTObject.h:29
TTErr calculate(const TTFloat64 &x, TTFloat64 &y)
Calculate a single sample of output for a single sample of input.
TTAudioObjectBase is the Jamoma DSP Audio Object Base Class
Wrap audio objects for convenience.
TTAudioObject(const TTObject &anOtherObject)
like a copy constructor – but from TTObject to TTAudioObject
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTErr setVector(const TTChannelCount channel, const TTUInt16 vectorSize, const TTSampleValuePtr newVector)
[doxygenAppendixC_methodExample]
TTAudioObjectBase * TTAudioObjectBasePtr
Pointer to a TTAudioObjectBase.
TTErr clear()
Zero out all of the sample values in the audio signal.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTErr adaptMaxNumChannels(const TTChannelCount newMaxNumChannels)
Increase the maxNumChannels attribute, if neccessary.
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
TTErr process(TTAudioSignal &in, TTAudioSignal &out)
Process the input signal, resulting in an output signal.
std::int32_t TTInt32
32 bit signed integer
Definition: TTBase.h:177
TTUInt16 TTChannelCount
Data type used when counting the number of channels in multi-channel audio signals and processes...
Definition: TTAudioSignal.h:31
TTErr calculate(const TTValue &x, TTValue &y)
Calculate a single sample of output for a single sample of input.
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
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
No Error.
Definition: TTBase.h:343
TTErr setSampleRate(const TTUInt32 &newSampleRate)
Convenience method for updating the sample-rate.
TTErr allocWithVectorSize(const TTUInt16 newVectorSize)
Allocate memory for all channels at the specified vectorsize, if the vectorsize is different from the...
TTErr setSampleRate(const TTUInt32 &newSampleRate)
Set the object's sample rate.
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
Wrap TTAudioSignal instances for convenience.
Definition: TTAudioObject.h:25
TTChannelCount numAudioSignals
The number of audio signal pointers which are actually valid.
TTErr alloc()
Allocate memory for all channels at the current vectorsize.