Jamoma API  0.6.0.a19
TTResample.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 "TTResample.h"
11 
12 #define thisTTClass TTResample
13 #define thisTTClassName "resample"
14 #define thisTTClassTags "audio, processor, resample"
15 
16 
17 TT_AUDIO_CONSTRUCTOR,
18  mResamplingFilter(NULL),
19  mDirection(TT("Down"))
20 {
21  TTChannelCount initialMaxNumChannels = arguments;
22 
25  addUpdates(MaxNumChannels);
26 
27  setAttributeValue(TT("mode"), TT("staircase"));
28  setAttributeValue(TT("direction"), TT("down"));
29  setAttributeValue(kTTSym_maxNumChannels, initialMaxNumChannels);
30 
31  setProcessMethod(processAudio);
32 }
33 
34 
35 TTResample::~TTResample()
36 {
37  TTObjectBaseRelease((TTObjectBasePtr*)&mResamplingFilter);
38 }
39 
40 
41 TTErr TTResample::setDirection(const TTValue& newDirection)
42 {
43  mDirection = newDirection;
44  if (mDirection == TT("up"))
45  return mResamplingFilter->setAttributeValue(TT("mode"), TT("upsample"));
46  else // mDirection == TT("down")
47  return mResamplingFilter->setAttributeValue(TT("mode"), TT("downsample"));
48 }
49 
50 
51 TTErr TTResample::setMode(const TTValue& newMode)
52 {
53  TTErr err;
54 
55  // With the 3rd-order filter, when trying to a 1-2 upsampling, we end up with a result that copies
56  // every other sample directly, and filters the other samples, resulting in other samples all being of
57  // lesser value than the directly copied samples ???
58  //
59  // The sonograph shows spectral mirroring, indicating that high frequencies are not properly filtered.
60  //
61  // err = TTObjectBaseInstantiate(TT("halfband.3"), (TTObjectBasePtr*)&mResamplingFilter, initialMaxNumChannels);
62  //
63 
64  mMode = newMode;
65  if (mMode == TT("third"))
66  err = TTObjectBaseInstantiate(TT("halfband.3"), (TTObjectBasePtr*)&mResamplingFilter, mMaxNumChannels);
67  else if (mMode == TT("fifth"))
68  err = TTObjectBaseInstantiate(TT("halfband.5"), (TTObjectBasePtr*)&mResamplingFilter, mMaxNumChannels);
69  else if (mMode == TT("ninth"))
70  err = TTObjectBaseInstantiate(TT("halfband.9"), (TTObjectBasePtr*)&mResamplingFilter, mMaxNumChannels);
71  else // mMode == TT("staircase")
72  err = TTObjectBaseInstantiate(TT("staircase"), (TTObjectBasePtr*)&mResamplingFilter, mMaxNumChannels);
73 
74  setAttributeValue(TT("direction"), mDirection);
75 
76  return err;
77 }
78 
79 
80 TTErr TTResample::updateMaxNumChannels(const TTValue& oldMaxNumChannels, TTValue&)
81 {
82  return mResamplingFilter->setAttributeValue(kTTSym_maxNumChannels, mMaxNumChannels);
83 }
84 
85 
86 TTErr TTResample::processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
87 {
88  return mResamplingFilter->process(inputs, outputs);
89 }
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
TTChannelCount mMaxNumChannels
This is the maximum number of channels that can be guaranteed to work.
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
TTErr setAttributeValue(const TTSymbol name, TTValue &value)
Set an attribute value for an object.
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
TTErr TTObjectBaseInstantiate(const TTSymbol className, TTObjectBasePtr *returnedObjectPtr, const TTValue arguments)
DEPRECATED.
TTErr process(TTAudioSignal &in, TTAudioSignal &out)
Process the input signal, resulting in an output signal.
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
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
#define addUpdates(updateName)
An 'update' is a message sent to a subclass instance from its parent class.
Definition: TTMessage.h:44