Jamoma API  0.6.0.a19
TTAudioGraphSplit.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup audioGraphUtilityLib
4  *
5  * @brief split≈: divide multichannel signal into N smaller multichannel signals
6  *
7  * @details
8  *
9  * @authors Timothy Place
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_SPLIT_H__
18 #define __TT_SPLIT_H__
19 
20 #include "TTDSP.h"
21 
22 
23 /** The split≈ object takes a single input signal and splits it out into N output signals */
26 
27 protected:
28 
29  std::vector<TTChannelCount> mSplitChannels; ///< The number of channels in each of N groups of signals
30 
31  TTErr setGroups(const TTValueRef args)
32  {
33  TTUInt16 numArgs = args.size();
34 
35  mSplitChannels.resize(numArgs);
36  for (TTUInt16 i=0; i<numArgs; i++)
37  mSplitChannels[i] = args[i];
38  return kTTErrNone;
39  }
40 
41  TTErr getGroups(TTValueRef args)
42  {
43  TTUInt16 numArgs = mSplitChannels.size();
44 
45  args.resize(numArgs);
46  for (TTUInt16 i=0; i<numArgs; i++)
47  args[i] = mSplitChannels[i];
48  return kTTErrNone;
49  }
50 
51  TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
52  {
53  TTAudioSignal& in = inputs->getSignal(0);
54  TTChannelCount inputChannelCount = in.getNumChannelsAsInt();
55  TTChannelCount channelOffset = 0;
56  TTChannelCount channelBound = 0;
57 
58  for (TTUInt16 i=0; i < outputs->numAudioSignals; i++) {
59  TTAudioSignal& out = outputs->getSignal(i);
60  TTChannelCount numChannels = mSplitChannels[i];
61 
62  // TODO: we don't really want to alloc this memory every time!
63  out.setMaxNumChannels(numChannels);
64  out.setNumChannels(numChannels);
65 
66  // if we have run out of channels to split, then stop splitting them.
67  if (channelOffset >= inputChannelCount)
68  break;
69 
70  channelBound = channelOffset+numChannels-1;
71  if (channelBound >= inputChannelCount)
72  channelBound = inputChannelCount-1;
73 
74  TTAudioSignal::copySubset(in, out, channelOffset, channelBound);
75  channelOffset += numChannels;
76  // TODO: what happens when the incomming multicable has more audio channels than we want to split? Should there be an extra 'overflow' outlet similar to 'route' or 'sel'?
77  }
78  return kTTErrNone;
79  }
80 
81 };
82 
83 
84 
85 #endif // __TT_SPLIT_H__
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTAudioObjectBase is the base class for all audio generating and processing objects in Jamoma DSP...
static TTErr copySubset(const TTAudioSignal &source, TTAudioSignal &dest, TTChannelCount startingChannel=0, TTChannelCount endingChannel=0)
Copy the audio from one signal into another.
size_type size() const noexcept
Return the number of elements.
The split≈ object takes a single input signal and splits it out into N output signals.
Jamoma DSP Library.
#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
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
No Error.
Definition: TTBase.h:343
void resize(size_type n)
Change the number of elements.
std::vector< TTChannelCount > mSplitChannels
The number of channels in each of N groups of signals.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTChannelCount numAudioSignals
The number of audio signal pointers which are actually valid.