Jamoma API  0.6.0.a19
TTPhasor.cpp
1 /*
2  * TTBlue Cycling Ramp Generator
3  * Copyright © 2003, Timothy Place
4  *
5  * License: This code is licensed under the terms of the "New BSD License"
6  * http://creativecommons.org/licenses/BSD/
7  */
8 
9 #include "TTPhasor.h"
10 
11 #define thisTTClass TTPhasor
12 #define thisTTClassName "phasor"
13 #define thisTTClassTags "dspGeneratorLib, audio, generator, oscillator"
14 
15 
16 TT_AUDIO_CONSTRUCTOR
17 , mFrequency(1.0), mPhase(0.0), mOffset(0.0), step(0.0), linearGain(1.0)
18 {
22  addAttribute( Offset, kTypeFloat64);
23  // TODO: More Attributes left to add...
24  // linearGain
25  // period in ms
26  // period in samples
27 
28  addUpdates(SampleRate);
29 
30  setAttributeValue(TT("frequency"), 1.0);
31  setAttributeValue(TT("gain"), 0.0);
32  setProcessMethod(processAudio);
33 }
34 
35 
36 TTPhasor::~TTPhasor()
37 {
38  ;
39 }
40 
41 
43 {
45  return setFrequency(v);
46 }
47 
48 
50 {
51  mFrequency = newValue;
52  if (mFrequency == 0) {
53  rampSamples = 0xFFFFFFFF;
54  rampMilliseconds = 0;
55  }
56  else {
57  rampSamples = TTUInt32(sr / fabs(mFrequency));
58  // FIXME: we never use rampMilliseconds, so why computing this?
59  rampMilliseconds = 1000.0 * (rampSamples / TTFloat64(sr));
60  }
61  setStep();
62  return kTTErrNone;
63 }
64 
66 {
67  step = 1.0 / TTFloat64(rampSamples - 1.0); // 1.0 is the destination
68  if (mFrequency < 0){
69  step = -step;
70  }
71  TTZeroDenormal(step);
72 }
73 
74 
76 {
77  mPhase = newValue;
78  phaseInternal = mPhase;
79  if (mFrequency < 0)
80  phaseInternal += 1.0;
81 
82  return kTTErrNone;
83 }
84 
85 
87 {
89  return kTTErrNone;
90 }
91 
93 {
95  return kTTErrNone;
96 }
97 
98 
99 // TODO: add flags so that TTAudioObjectBase can call a process method with a different number audio signals?
100 
102 {
103  TTAudioSignal& out = outputs->getSignal(0);
104  TTSampleValue *outSample;
105  TTChannelCount numchannels = out.getNumChannelsAsInt();
106  TTChannelCount channel;
107  TTUInt16 vs;
108 
109  for (channel=0; channel<numchannels; channel++) {
110  outSample = out.mSampleVectors[channel];
111  vs = out.getVectorSizeAsInt();
112 
113  while (vs--) {
114  if (phaseInternal > 1.0)
115  phaseInternal = 0.0;
116  else if (phaseInternal < 0.0)
117  phaseInternal = 1.0;
118 
119  *outSample++ = (phaseInternal * linearGain) + mOffset;
120  phaseInternal += step;
121  }
122  }
123  return kTTErrNone;
124 }
TTFloat64 TTDecibelsToLinearGain(TTFloat64 value)
Convert decibels into linear ampliude.
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTFloat64 TTLinearGainToDecibels(const TTFloat64 value)
Convert linear amplitude into deciBels.
TTSampleValue phaseInternal
current location in the ramp
Definition: TTPhasor.h:22
#define addAttribute(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
Definition: TTAttribute.h:29
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTUInt32 rampSamples
ramp time in samples
Definition: TTPhasor.h:26
TTFloat64 linearGain
actual gain coefficient derived from attrGain
Definition: TTPhasor.h:28
TTFloat64 rampMilliseconds
ramp time in milliseconds
Definition: TTPhasor.h:25
TTFloat64 mOffset
offset value (adding DC)
Definition: TTPhasor.h:23
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
64-bit floating point
Definition: TTBase.h:272
TTFloat64 mFrequency
ramp time in milliseconds
Definition: TTPhasor.h:21
TTErr setFrequency(const TTValue &newValue)
Setter for the frequency attribute in Hertz.
Definition: TTPhasor.cpp:49
The TTAudioSignal class represents N vectors of audio samples for M channels.
Definition: TTAudioSignal.h:57
void setStep()
Internal method called when the ramp is triggered (by setting the rampTime)
Definition: TTPhasor.cpp:65
TTSampleValue ** mSampleVectors
An array of pointers to the first sample in each vector. Declared Public for fast access...
Definition: TTAudioSignal.h:74
TTErr setGain(const TTValue &newValue)
Setter the gain attribute in dB.
Definition: TTPhasor.cpp:86
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
Process method – This method is special! It does not use it's input!
Definition: TTPhasor.cpp:101
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
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
TTErr updateSampleRate(const TTValue &, TTValue &)
Receives notifications when there are changes to the inherited sr attribute.
Definition: TTPhasor.cpp:42
No Error.
Definition: TTBase.h:343
TTErr setPhase(const TTValue &newValue)
Setter for the frequency attribute in Hertz.
Definition: TTPhasor.cpp:75
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTFloat64 step
step size
Definition: TTPhasor.h:27
TTErr getGain(TTValue &value)
Getter for the gain attribute.
Definition: TTPhasor.cpp:92
#define addUpdates(updateName)
An 'update' is a message sent to a subclass instance from its parent class.
Definition: TTMessage.h:44
#define addAttributeWithGetterAndSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter and sett...
Definition: TTAttribute.h:57
TTUInt32 sr
Current sample rate being used by this object.