Jamoma API  0.6.0.a19
TTStaircase.cpp
1 /*
2  * Resample
3  * Extension Class for Jamoma DSP
4  * Copyright © 2010, Timothy Place
5  *
6  * License: This code is licensed under the terms of the "New BSD License"
7  * http://creativecommons.org/licenses/BSD/
8  */
9 
10 #include "TTStaircase.h"
11 
12 #define thisTTClass TTStaircase
13 #define thisTTClassName "staircase"
14 #define thisTTClassTags "audio, processor, resample"
15 
16 
17 TT_AUDIO_CONSTRUCTOR
18 {
20  setAttributeValue(TT("mode"), TT("down"));
21 }
22 
23 
24 TTStaircase::~TTStaircase()
25 {
26  ;
27 }
28 
29 
30 TTErr TTStaircase::setMode(const TTValue& newMode)
31 {
32  mMode = newMode;
33  if (mMode == TT("upsample"))
34  setProcessMethod(processUpsample);
35  else // mMode == TT("downsample")
36  setProcessMethod(processDownsample);
37  return kTTErrNone;
38 }
39 
40 
41 TTErr TTStaircase::processDownsample(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
42 {
43  TTAudioSignal& in = inputs->getSignal(0);
44  TTAudioSignal& out = outputs->getSignal(0);
45  TTSampleValue* inSample;
46  TTSampleValue* outSample;
48  TTPtrSizedInt channel;
49  TTUInt16 targetVectorSize = in.getVectorSizeAsInt() / 2;
50 
51  out.changeVectorSize(targetVectorSize);
52  out.setSampleRate(in.getSampleRate() / 2);
53  for (channel=0; channel<numchannels; channel++) {
54  TTUInt16 n = targetVectorSize;
55 
56  inSample = in.mSampleVectors[channel];
57  outSample = out.mSampleVectors[channel];
58 
59  while (n--) {
60  *outSample++ = * inSample++;
61  inSample++;
62  }
63  }
64  return kTTErrNone;
65 }
66 
67 
68 TTErr TTStaircase::processUpsample(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
69 {
70  TTAudioSignal& in = inputs->getSignal(0);
71  TTAudioSignal& out = outputs->getSignal(0);
72  TTSampleValue* inSample;
73  TTSampleValue* outSample;
75  TTPtrSizedInt channel;
76  TTUInt16 targetVectorSize = in.getVectorSizeAsInt() * 2;
77  TTErr err;
78 
79  err = out.changeVectorSize(targetVectorSize);
80  if (!err) {
81  out.setSampleRate(in.getSampleRate() * 2);
82  for (channel=0; channel<numchannels; channel++) {
83  TTUInt16 n = in.getVectorSizeAsInt();
84  TTSampleValue x;
85 
86  inSample = in.mSampleVectors[channel];
87  outSample = out.mSampleVectors[channel];
88 
89  while (n--) {
90  x = *inSample++;
91  *outSample++ = x;
92  *outSample++ = x;
93  }
94  }
95  }
96  return kTTErrNone;
97 }
98 
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.
Symbol type.
Definition: TTBase.h:282
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
static TTChannelCount getMinChannelCount(const TTAudioSignal &signal1, const TTAudioSignal &signal2)
Use this class method to determine the least number of channels the two signals have in common...
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.
long TTPtrSizedInt
An integer that is the same size as a pointer.
Definition: TTBase.h:240
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