Jamoma API  0.6.0.a19
TTDegrade.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspEffectsLib
4  *
5  * @brief #TTDegrade distorts signal by reducing bit resolution and/or sample rate.
6  *
7  * @authors Tim Place, Trond Lossius
8  *
9  * @copyright Copyright © 2008, Tim Place @n
10  * This code is licensed under the terms of the "New BSD License" @n
11  * http://creativecommons.org/licenses/BSD/
12  */
13 
14 
15 #include "TTDegrade.h"
16 
17 #define thisTTClass TTDegrade
18 #define thisTTClassName "degrade"
19 #define thisTTClassTags "dspEffectsLib, audio, processor, distortion"
20 
21 #define BIG_INT 0x00800000
22 #define ONE_OVER_BIG_INT 1.1920928955E-7
23 
24 
25 TT_AUDIO_CONSTRUCTOR
26 {
27  TTChannelCount initialMaxNumChannels = arguments;
28 
29  // register attributes
31  addAttribute(SrRatio, kTypeFloat64);
32 
33  // register for notifications from the parent class so we can allocate memory as required
34  addUpdates(MaxNumChannels);
35 
36  // Set Defaults...
37  setAttributeValue(kTTSym_maxNumChannels, initialMaxNumChannels);
38  setAttributeValue(TT("bitdepth"), 24);
39  setAttributeValue(TT("srRatio"), 1.0);
40  setProcessMethod(processAudio);
41 }
42 
43 
44 TTDegrade::~TTDegrade()
45 {;}
46 
47 
49 {
51  mAccumulator.assign(mMaxNumChannels, 0.0);
52 
53  mOutput.resize(mMaxNumChannels);
54  mOutput.assign(mMaxNumChannels, 0.0);
55 
56  return kTTErrNone;
57 }
58 
59 
61 {
62  mBitdepth = TTClip<TTInt32>(newValue, 1, 24);
63  mBitShift = 24 - mBitdepth;
64  return kTTErrNone;
65 }
66 
67 
69 {
70  TTAudioSignal& in = inputs->getSignal(0);
71  TTAudioSignal& out = outputs->getSignal(0);
72  TTUInt16 vs;
73  TTSampleValue *inSample,
74  *outSample;
76  TTChannelCount channel;
77  long l;
78 
79  for (channel=0; channel<numchannels; channel++) {
80  inSample = in.mSampleVectors[channel];
81  outSample = out.mSampleVectors[channel];
82  vs = in.getVectorSizeAsInt();
83 
84  while (vs--) {
85  // SampeRate Reduction
86  mAccumulator[channel] += mSrRatio;
87  if (mAccumulator[channel] >= 1.0) {
88  mOutput[channel] = *inSample++;
89  mAccumulator[channel] -= 1.0;
90  }
91 
92  // BitDepth Reduction
93  l = (long)(mOutput[channel] * BIG_INT); // change float to long int
94  l >>= mBitShift; // shift away the least-significant bits
95  l <<= mBitShift; // shift back to the correct registers
96  *outSample++ = (float) l * ONE_OVER_BIG_INT; // back to float
97  }
98  }
99  return kTTErrNone;
100 }
101 
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
#define addAttribute(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
Definition: TTAttribute.h:29
TTChannelCount mMaxNumChannels
This is the maximum number of channels that can be guaranteed to work.
8-bit unsigned integer, range is 0 through 255.
Definition: TTBase.h:274
TTFloat64 mSrRatio
Use a range of 0.0 to 1.0 to specify a ratio of the current sample-rate to emulate in order to intent...
Definition: TTDegrade.h:35
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTSampleVector mOutput
Holds values over from one vector to the next for each channel..
Definition: TTDegrade.h:33
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
TTDegrade distorts signal by reducing bit resolution and/or sample rate.
64-bit floating point
Definition: TTBase.h:272
TTErr updateMaxNumChannels(const TTValue &oldMaxNumChannels, TTValue &)
[doxygenAppendixC_variableExample]
Definition: TTDegrade.cpp:48
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.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTErr setBitdepth(const TTValue &value)
Setter for the bitdepth attribute.
Definition: TTDegrade.cpp:60
#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
TTUInt16 mBitShift
[doxygenAppendixC_variableExample]
Definition: TTDegrade.h:31
TTUInt8 mBitdepth
Use a range of 1 to 24 to emulate the specified bitdepth.
Definition: TTDegrade.h:34
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Standard audio processing method as used by TTBlue objects.
Definition: TTDegrade.cpp:68
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTSampleVector mAccumulator
Holds values over from one vector to the next for each channel.
Definition: TTDegrade.h:32
#define addUpdates(updateName)
An 'update' is a message sent to a subclass instance from its parent class.
Definition: TTMessage.h:44