Jamoma API  0.6.0.a19
TTAudioGraphPick.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup audioGraphUtilityLib
4  *
5  * @brief pick≈: extract N specific audio signals from 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 #ifndef __TT_PICK_H__
18 #define __TT_PICK_H__
19 
20 #include "TTDSP.h"
21 
22 
23 class TTAudioGraphPick : public TTAudioObjectBase {
24  TTCLASS_SETUP(TTAudioGraphPick)
25 
26 protected:
27 
28  std::vector<TTChannelCount> mPickChannels; ///< The specific channels we want to pick
29  TTChannelCount mNumPickChannels; ///< The number of channels we pick
30  TTBoolean outputNeedsResize;
31 
32  TTErr setPicks(const TTValueRef args)
33  {
34  if (args.size() != mNumPickChannels){
35  mNumPickChannels = args.size();
36  mPickChannels.resize(mNumPickChannels);
37  outputNeedsResize = true;
38  }
39 
40  for (TTChannelCount i=0; i<mNumPickChannels; i++) {
41  mPickChannels[i] = args[i]; //substracting offset (channel 1 is JAG-channel 0)
42  mPickChannels[i] = mPickChannels[i] - 1;
43  }
44  return kTTErrNone;
45  }
46 
47  TTErr getPicks(TTValueRef args)
48  {
49  args.resize(mNumPickChannels);
50  for (TTChannelCount i=0; i<mNumPickChannels; i++)
51  args[i] = mPickChannels[i] + 1; //re-adding offset
52  return kTTErrNone;
53  }
54 
55  TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
56  {
57  TTAudioSignal& in = inputs->getSignal(0);
58  TTAudioSignal& out = outputs->getSignal(0);
59  TTSampleValuePtr inSample, outSample;
60  TTChannelCount inputChannelCount = in.getNumChannelsAsInt();
61  TTUInt16 vs = out.getVectorSizeAsInt();
62  TTChannelCount currentPick;
63 
64  if (outputNeedsResize){
65  out.setMaxNumChannels(mNumPickChannels);
66  out.setNumChannels(mNumPickChannels);
67  outputNeedsResize = false;
68  }
69 
70  for (TTChannelCount i=0; i < mNumPickChannels; i++) {
71  outSample = out.mSampleVectors[i];
72  //n = vs;
73  currentPick = mPickChannels[i];
74  if (currentPick <= inputChannelCount) {
75  inSample = in.mSampleVectors[mPickChannels[i]];
76  //while (n--)
77  // *outSample++ = *inSample++;
78  memcpy(outSample, inSample, sizeof(TTSampleValue) * vs);
79  }
80  else {
81  memset(outSample, 0, sizeof(TTSampleValue) * vs);
82  //while (n--)
83  // *outSample++ = 0.0;
84  }
85 
86  }
87 
88  return kTTErrNone;
89  }
90 
91 };
92 
93 
94 
95 #endif // __TT_PICK_H__
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
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...
STL namespace.
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
TTSampleValue ** mSampleVectors
An array of pointers to the first sample in each vector. Declared Public for fast access...
Definition: TTAudioSignal.h:74
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.
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34