Jamoma API  0.6.0.a19
TTAudioSignalArray.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspLibrary
4  *
5  * @brief Container for an array of #TTAudioSignal pointers.
6  *
7  * @details TODO: put more info here
8  *
9  * @see TTAudioSignal
10  *
11  * @authors Tim Place
12  *
13  * @copyright Copyright © 2008 by Timothy Place @n
14  * This code is licensed under the terms of the "New BSD License" @n
15  * http://creativecommons.org/licenses/BSD/
16  */
17 
18 #ifndef __TT_AUDIO_SIGNAL_ARRAY_H__
19 #define __TT_AUDIO_SIGNAL_ARRAY_H__
20 
21 #include "TTAudioSignal.h"
22 
23 
24 /****************************************************************************************************/
25 // Class Specification
26 
27 /** A simple container for an array of TTAudioSignal pointers.
28  This class does not automatically manage the signals themselves, instantiate, or free them. */
29 class TTDSP_EXPORT TTAudioSignalArray : public TTDataObjectBase {
31 
32 protected:
33 
34  TTAudioSignalPtr* mAudioSignals; ///< The actual array of audio signal pointers.
35  TTChannelCount mAudioSignalMaxCount; ///< The maximum number of audio signals that can be passed in this array.
36 
37 public:
38 
39  TTChannelCount numAudioSignals; ///< The number of audio signal pointers which are actually valid.
40 
41  void chuck();
42  void init();
43  void releaseAll();
44 
45  void clearAll()
46  {
47  for (TTChannelCount i=0; i<mAudioSignalMaxCount; i++)
48  mAudioSignals[i]->clear();
49  }
50 
51  void allocAllWithVectorSize(TTUInt16 vs);
52  TTUInt16 getVectorSize();
53  void setAllMaxNumChannels(TTChannelCount newMaxNumChannels);
54  void setAllNumChannels(TTChannelCount newNumChannels);
55 
56  void setAllSampleRates(TTUInt32 newSampleRate)
57  {
58  for (TTChannelCount i=0; i<numAudioSignals; i++)
59  mAudioSignals[i]->setSampleRate(newSampleRate);
60  }
61 
62  /** Note: calling this function will invalidate all audioSignal pointers contained within the array. */
63  void setMaxNumAudioSignals(TTChannelCount newMaxNumAudioSignals)
64  {
65  if (newMaxNumAudioSignals != mAudioSignalMaxCount) {
66  chuck();
67  mAudioSignalMaxCount = newMaxNumAudioSignals;
68  init();
69  }
70  }
71 
72  TTChannelCount getMaxNumAudioSignals()
73  {
74  return mAudioSignalMaxCount;
75  }
76 
77 
78  TTAudioSignal& getSignal(TTChannelCount index)
79  {
80  return *mAudioSignals[index];
81  }
82 
83 
84  TTErr setSignal(TTChannelCount index, const TTAudioSignalPtr aSignal);
85 
86 
87  void matchNumChannels(TTAudioSignalArray* anotherArray)
88  {
89  matchNumChannels(*anotherArray);
90  }
91 
92  void matchNumChannels(TTAudioSignalArray& anotherArray)
93  {
94  TTChannelCount audioSignalCount = TTClip<TTChannelCount>(mAudioSignalMaxCount, 0, anotherArray.mAudioSignalMaxCount);
95  TTValue v;
96 
97  for (int i=0; i<audioSignalCount; i++) {
98  TTChannelCount numChannels = anotherArray.mAudioSignals[i]->getNumChannelsAsInt();
99 
100  v = numChannels;
101  // TODO: for efficiency, we should only set the maxNumChannels if it is larger than the current so we aren't allocing memory on the heap!
102  mAudioSignals[i]->setMaxNumChannels(v);
103  mAudioSignals[i]->setNumChannels(v);
104  }
105 
106  // TODO, for all channels that are not in this array, but are in another array, we should zero the numChannels
107  }
108 
109  TTChannelCount getMaxNumChannels()
110  {
111  TTChannelCount maxNumChannels = 0;
112 
113  for (TTChannelCount i=0; i<mAudioSignalMaxCount; i++) {
114  if (mAudioSignals[i]->getMaxNumChannelsAsInt() > maxNumChannels)
115  maxNumChannels = mAudioSignals[i]->getMaxNumChannelsAsInt();
116  }
117  return maxNumChannels;
118  }
119 
120 };
121 
122 
124 
125 #endif // __TT_AUDIO_SIGNAL_ARRAY_H__
126 
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
void setMaxNumAudioSignals(TTChannelCount newMaxNumAudioSignals)
Note: calling this function will invalidate all audioSignal pointers contained within the array...
TTDataObjectBase is the base class for all data generating and processing objects.
TTChannelCount mAudioSignalMaxCount
The maximum number of audio signals that can be passed in this array.
#define TTCLASS_SETUP(className)
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:54
TTErr setMaxNumChannels(const TTValue &newMaxNumChannels)
Attribute accessor.
The TTAudioSignal class represents N vectors of audio samples for M channels.
Definition: TTAudioSignal.h:57
Represents M channels containing N vectors of audio samples.
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
TTAudioSignalPtr * mAudioSignals
The actual array of audio signal pointers.
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTChannelCount numAudioSignals
The number of audio signal pointers which are actually valid.