Jamoma API  0.6.0.a19
TTAdsr.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspGeneratorLib
4  *
5  * @brief GeneratorLib: Generate classic ADSR envelope (attack, decay, sustain, release).
6  *
7  * @details
8  *
9  * @authors Tim Place, Dave Watson, Trond Lossius
10  *
11  * @copyright Copyright © 2009 by Timothy Place @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_ADSR_H__
18 #define __TT_ADSR_H__
19 
20 #include "TTDSP.h"
21 
22 
23 /** TTAdsr is an attack-decay-sustain-release envelope generator.
24  */
27 
28 protected:
29 
30  TTFloat64 attack_ms; ///< Attack duration in milliseconds.
31  TTInt32 attack_samples; ///< Attack duration in total number of samples.
32  TTFloat64 attack_step; ///< Stepsize for each sample in the attack phase.
33  TTFloat64 attack_step_db; ///< Stepasize in decibels for each sample in the attack phase.
34 
35  TTFloat64 decay_ms; ///< Decay duration in milliseconds.
36  TTInt32 decay_samples; ///< Decay duration in total number of samples.
37  TTFloat64 decay_step; ///< Stepsize for each sample during the decay phase.
38  TTFloat64 decay_step_db; ///< Stepsize in decibels for each sample during the decay phase.
39 
40  TTFloat64 sustain_amp; ///< Sustain level as linear amplitude.
41  TTFloat64 sustain_db; ///< Sustain level as decibel value.
42 
43  TTFloat64 release_ms; ///< Release duration in milliseconds.
44  TTInt32 release_samples; ///< Release duration in total number of samples.
45  TTFloat64 release_step; ///< Stepsize for each sample during the release phase.
46  TTFloat64 release_step_db; ///< Stepsize in decibels for each sample during the release phase.
47 
48  TTSampleValue output; ///< Current envelope value as linear amplitude.
49  TTSampleValue output_db; ///< Current envelope value as decibel value.
50 
51  TTInt16 eg_state; ///< The current state of the envelope. Tracks what envelope phase that we are currently in.
52  TTBoolean trigger;
53 
54  TTSymbol attrMode;
55 
56 
57  /** This method must be called when the sample rate change.
58  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
59  */
61 
62 
63  /** Send a dictionary from Jamoma Graph to this object in order to pass a MidiNoteEvent or set attributes.
64 
65  @details Sending a dictionary to this object may perform one of several functions.
66 
67  -# If the dictionary contains a MidiNoteEvent, then the midi note velocity
68  (second item of the value array for the dictionary) is used to set the ADSR trigger
69  as on or off.
70  -# For setting attributes, etc., we rely on the external system (e.g. Jamoma Graph) to
71  implement the infrastructure. By returning an error code if the dictionary is not a
72  MidiNoteEvent, we indicate to the calling system that it is free to perform other
73  tasks with the dictionary.
74 
75  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
76  */
77  TTErr dictionary(const TTValue& input, TTValue& output);
78 
79 
80  /** The Linear audio processing method use linear amplitude curves for all parts of the envelope.
81  @param inputs The input audio vector to process. For this unit generator this is basically ignored.
82  @param outputs The returned processed audio.
83  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
84  */
86 
87 
88  /** The Exponential processing methods use exponential curves for all sections of the envelope.
89  @param inputs The input audio vector to process. For this unit generator this is basically ignored.
90  @param outputs The returned processed audio.
91  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
92  */
94 
95 
96  /** The Hybrid processing method combines a linear attack with an exponential release.
97  @param inputs The input audio vector to process. For this unit generator this is basically ignored.
98  @param outputs The returned processed audio.
99  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
100  */
102 
103 
104  /**
105  @ingroup consts
106  */
107  enum constants {
108  NOISE_FLOOR = -120
109  };
110 
111 
112  /** Enumerations tracking the state of the envelope.
113  ingroup enums
114  */
115  enum eg_states {
116  k_eg_inactive, ///< The envelope is currently inactive (not being executed).
117  k_eg_attack, ///< The envelope is currently in the attack phase.
118  k_eg_decay, ///< The envelope is currently in the decay phase.
119  k_eg_sustain, ///< The envelope is currently in the sustain phase.
120  k_eg_release ///< The envelope is currently in the release phase.
121  };
122 
123 
124  /** Set the attack time for the enevelope.
125  @details The maximum attack amplitude is normalised to 0 dB.
126  @param newValue The desired attack time in milliseconds.
127  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
128  */
129  TTErr setAttack(const TTValue& newValue);
130 
131 
132  /** Set the decay time for the envelope.
133  @param newValue The desired decay time in milliseconds.
134  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
135  */
136  TTErr setDecay(const TTValue& newValue);
137 
138 
139  /** Set the signal level to use for the sustain, expressed in decibels.
140  @param newValue The desired sustain level in decibels.
141  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
142  */
143  TTErr setSustainDb(const TTValue& newValue);
144 
145 
146  /** Get the signal level currently used for the sustain, measured in decibels.
147  @param returnedValue Used to return the current sustain signal level in dB.
148  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
149  */
150  TTErr getSustainDb(TTValue& returnedValue);
151 
152 
153  /** Set the signal level to use for the sustain, expressed as linear amplitude.
154  @param newValue The desired sustain level in decibels.
155  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
156  */
157  TTErr setSustainAmp(const TTValue& newValue);
158 
159 
160  /** Set the release time in milliseconds.
161  *param newValue The desired release time in milliseconds.
162  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
163  */
164  TTErr setRelease(const TTValue& newValue);
165 
166 
167  /** Set the performance mode to use for the envelope.
168  @details Possible options are 'exponential', 'linear' and 'hybrid'
169  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
170  */
171  TTErr setMode(const TTValue& newValue);
172 };
173 
174 #endif
175 
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTSampleValue output
Current envelope value as linear amplitude.
Definition: TTAdsr.h:48
TTErr updateSampleRate(const TTValue &, TTValue &)
This method must be called when the sample rate change.
Definition: TTAdsr.cpp:82
TTErr setAttack(const TTValue &newValue)
Set the attack time for the enevelope.
Definition: TTAdsr.cpp:99
TTAudioObjectBase is the base class for all audio generating and processing objects in Jamoma DSP...
TTErr setSustainDb(const TTValue &newValue)
Set the signal level to use for the sustain, expressed in decibels.
Definition: TTAdsr.cpp:136
TTErr processAudioLinear(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
The Linear audio processing method use linear amplitude curves for all parts of the envelope...
Definition: TTAdsr.cpp:165
TTFloat64 release_ms
Release duration in milliseconds.
Definition: TTAdsr.h:43
TTErr processAudioHybrid(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
The Hybrid processing method combines a linear attack with an exponential release.
Definition: TTAdsr.cpp:295
TTInt32 attack_samples
Attack duration in total number of samples.
Definition: TTAdsr.h:31
TTInt16 eg_state
The current state of the envelope. Tracks what envelope phase that we are currently in...
Definition: TTAdsr.h:51
TTFloat64 decay_ms
Decay duration in milliseconds.
Definition: TTAdsr.h:35
Jamoma DSP Library.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
TTErr dictionary(const TTValue &input, TTValue &output)
Send a dictionary from Jamoma Graph to this object in order to pass a MidiNoteEvent or set attributes...
Definition: TTAdsr.cpp:52
TTFloat64 decay_step_db
Stepsize in decibels for each sample during the decay phase.
Definition: TTAdsr.h:38
#define TTCLASS_SETUP(className)
TODO Doxygen: need more comments here.
Definition: TTFoundation.h:54
std::int16_t TTInt16
16 bit signed integer
Definition: TTBase.h:175
TTFloat64 decay_step
Stepsize for each sample during the decay phase.
Definition: TTAdsr.h:37
The envelope is currently inactive (not being executed).
Definition: TTAdsr.h:116
TTErr processAudioExponential(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
The Exponential processing methods use exponential curves for all sections of the envelope...
Definition: TTAdsr.cpp:227
TTFloat64 attack_ms
Attack duration in milliseconds.
Definition: TTAdsr.h:30
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTSampleValue output_db
Current envelope value as decibel value.
Definition: TTAdsr.h:49
TTFloat64 sustain_db
Sustain level as decibel value.
Definition: TTAdsr.h:41
TTErr getSustainDb(TTValue &returnedValue)
Get the signal level currently used for the sustain, measured in decibels.
Definition: TTAdsr.cpp:143
std::int32_t TTInt32
32 bit signed integer
Definition: TTBase.h:177
The envelope is currently in the release phase.
Definition: TTAdsr.h:120
TTFloat64 attack_step
Stepsize for each sample in the attack phase.
Definition: TTAdsr.h:32
A simple container for an array of TTAudioSignal pointers.
TTInt32 release_samples
Release duration in total number of samples.
Definition: TTAdsr.h:44
TTErr setSustainAmp(const TTValue &newValue)
Set the signal level to use for the sustain, expressed as linear amplitude.
Definition: TTAdsr.cpp:129
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
eg_states
Enumerations tracking the state of the envelope.
Definition: TTAdsr.h:115
The envelope is currently in the decay phase.
Definition: TTAdsr.h:118
TTAdsr is an attack-decay-sustain-release envelope generator.
Definition: TTAdsr.h:25
TTErr setMode(const TTValue &newValue)
Set the performance mode to use for the envelope.
Definition: TTAdsr.cpp:150
The envelope is currently in the sustain phase.
Definition: TTAdsr.h:119
TTFloat64 sustain_amp
Sustain level as linear amplitude.
Definition: TTAdsr.h:40
TTFloat64 release_step_db
Stepsize in decibels for each sample during the release phase.
Definition: TTAdsr.h:46
The envelope is currently in the attack phase.
Definition: TTAdsr.h:117
TTFloat64 attack_step_db
Stepasize in decibels for each sample in the attack phase.
Definition: TTAdsr.h:33
TTInt32 decay_samples
Decay duration in total number of samples.
Definition: TTAdsr.h:36
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTErr setDecay(const TTValue &newValue)
Set the decay time for the envelope.
Definition: TTAdsr.cpp:109
TTFloat64 release_step
Stepsize for each sample during the release phase.
Definition: TTAdsr.h:45
TTErr setRelease(const TTValue &newValue)
Set the release time in milliseconds.
Definition: TTAdsr.cpp:119