Jamoma API  0.6.0.a19
TTAudioGraphOutput.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup audioGraphLibrary
4  *
5  * @brief Defines output interface at the bottom of AudioGraph
6  *
7  * @details TTAudioGraphOutput is an audio object that serves as the destination and master (terminal obejct or sink) for a #TTAudioGraph graph. In Jamoma AudioGraph audio processing is driven from a from a ‘terminal object’ or ‘sink’ at the bottom of the chain.
8  * This strategy for processing an audio graph is known as the ‘pull’ method.
9  * Typically sinks may be used for audio output, recording to disk, or for monitoring purposes.
10  * Sinks may have other #TTAudioGraphObjects connected upstream, but can not be connected to further downstream TTAudioGraphObjects.
11  *
12  * @authors Timothy Place, Trond Lossius
13  *
14  * @copyright Copyright © 2010, Timothy Place @n
15  * This code is licensed under the terms of the "New BSD License" @n
16  * http://creativecommons.org/licenses/BSD/
17  */
18 
19 
20 #include "TTAudioGraphObject.h"
21 #include "TTAudioGraphInlet.h" // required for windows build
22 #include "TTAudioGraphOutput.h"
23 //#include "TTAudioEngine.h"
24 
25 #define thisTTClass TTAudioGraphOutput
26 #define thisTTClassName "dac"
27 #define thisTTClassTags "audio, graph, output"
28 
29 TT_AUDIO_CONSTRUCTOR,
30  placeHolder(NULL),
31  mDevice(kTTSymEmpty),
32  mSampleStamp(0)
33 {
34  TTObjectBaseInstantiate(kTTSym_audiosignal, &placeHolder, 1);
35 // audioEngine = TTAudioEngine::create();
36  TTDictionary d("j@m0m@_audioengine");
37  TTPtr engine = NULL;
38  d.getValue(engine);
39  mAudioEngine = (TTAudioObjectBase*)engine;
40 
44 
45  addMessage(start);
46  addMessage(stop);
47 
48  addMessage(audioEngineWillProcess);
49  addMessageProperty(audioEngineWillProcess, hidden, YES);
50  addMessageWithArguments(setOwner);
51  addMessageProperty(setOwner, hidden, YES);
52 
53  addMessageWithArguments(getAvailableDeviceNames);
54  addMessageWithArguments(getCpuLoad);
55 
56  setProcessMethod(processAudio);
57 
58  me = new TTValue;
59  (*me) = (TTObjectBasePtr)this;
60  mAudioEngine->sendMessage(TT("addCallbackObserver"), *me, kTTValNONE);
61 }
62 
63 
64 TTAudioGraphOutput::~TTAudioGraphOutput()
65 {
66  mAudioEngine->sendMessage(TT("removeCallbackObserver"), *me, kTTValNONE);
67  delete me;
68  //TTAudioEngine::destroy();
70 }
71 
72 
74 {
75  TTValue v;
76 
77  getVectorSize(v);
78  mInitData.vectorSize = v;
79 
80  mAudioEngine->sendMessage(TT("start"));
81  return kTTErrNone;
82 }
83 
84 
86 {
87  mAudioEngine->sendMessage(TT("stop"));
88  return kTTErrNone;
89 }
90 
91 
93 {
94  TT_ASSERT("There must be an owner", owner);
95 
97  owner->preprocess(mInitData);
99  mSampleStamp += mInitData.vectorSize;
101  return kTTErrNone;
102 }
103 
104 
106 {
108  return kTTErrNone;
109 }
110 
111 
113 {
114  return mAudioEngine->sendMessage(TT("getAvailableOutputDeviceNames"), kTTValNONE, returnedDeviceNames);
115 }
116 
117 
119 {
120  return mAudioEngine->sendMessage(TT("getCpuLoad"), kTTValNONE, returnedValue);
121 }
122 
123 
125 {
126  return mAudioEngine->setAttributeValue(kTTSym_sampleRate, const_cast<TTValue&>(newValue));
127 }
128 
130 {
131  return mAudioEngine->getAttributeValue(kTTSym_sampleRate, returnedValue);
132 }
133 
134 
136 {
137  return mAudioEngine->setAttributeValue(kTTSym_vectorSize, const_cast<TTValue&>(newValue));
138 }
139 
141 {
142  return mAudioEngine->getAttributeValue(kTTSym_vectorSize, returnedValue);
143 }
144 
145 
147 {
148  return mAudioEngine->setAttributeValue(TT("outputDevice"), const_cast<TTValue&>(newValue));
149 }
150 
152 {
153  return mAudioEngine->getAttributeValue(TT("outputDevice"), returnedValue);
154 }
155 
156 
158 {
159  if(inputs->numAudioSignals){
160  TTAudioSignal& in = inputs->getSignal(0);
161  TTAudioSignal* out = NULL;
162 
163  TTValue dummy;
164  TTValue buffer;
165  mAudioEngine->sendMessage("getOutputSignalReference", dummy, buffer);
166  out = (TTAudioSignalPtr)TTPtr(buffer);
167 
168  //(*((TTAudioEnginePtr)mAudioEngine)->mOutputBuffer) += in;
169  (*out) += in;
170 
171  return kTTErrNone;
172  }
173  else
174  return kTTErrBadChannelConfig;
175 }
176 
TTErr sendMessage(const TTSymbol name)
TODO: Document this function.
TTErr getDevice(TTValue &returnedValue)
Get the current audio output device.
TTErr stop()
Stop audio processing.
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
TTAudioObjectBase is the base class for all audio generating and processing objects in Jamoma DSP...
TTErr processAudio(TTAudioSignalArrayPtr inputs, TTAudioSignalArrayPtr outputs)
A standard audio processing method as used by Jamoma DSP objects.
An invalid number of audio channels for a given context was encountered.
Definition: TTBase.h:353
void lockProcessing()
The thread protection for processing is important: we cannot have the graph nodes being deleted or re...
#define setProcessMethod(methodName)
A convenience macro to be used by subclasses for setting the process method.
TTErr getAttributeValue(const TTSymbol name, TTValue &value)
Get an attribute value for an object.
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
Defines a single 'inlet' from an individual AudioGraph object.
TTErr setAttributeValue(const TTSymbol name, TTValue &value)
Set an attribute value for an object.
TTErr getValue(T &aReturnedValue) const
Get the dictionary's primary value.
Definition: TTDictionary.h:202
Symbol type.
Definition: TTBase.h:282
16-bit unsigned integer, range is 0 through 65,535.
Definition: TTBase.h:276
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
A type that represents the key as a C-String and the value as a pointer to the matching TTSymbol obje...
Definition: TTDictionary.h:47
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
TTErr setSampleRate(const TTValue &newValue)
Set sample rate.
TTErr getAvailableDeviceNames(const TTValue &, TTValue &returnedDeviceNames)
Get a list of available audio devices.
TTAudioGraphObjectBasePtr owner
The owning AudioGraph instance.
TTUInt16 vectorSize
The global/recommended/initial vectorSize (which can be overriden during process) ...
Definition: TTAudioGraph.h:83
TTErr TTObjectBaseInstantiate(const TTSymbol className, TTObjectBasePtr *returnedObjectPtr, const TTValue arguments)
DEPRECATED.
TTErr setOwner(TTValue &newOwner, TTValue &)
TTErr setDevice(const TTValue &newValue)
Set what audio output device to use.
virtual TTErr preprocess(const TTAudioGraphPreprocessData &initData)
This method is called by an object about to process audio, prior to calling getAudioOutput().
The TTAudioSignal class represents N vectors of audio samples for M channels.
Definition: TTAudioSignal.h:57
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:27
TTErr getCpuLoad(const TTValue &, TTValue &returnedValue)
Get current CPU load for the system, monitoring how demanding current processing is on the processor...
Wraps an object from Jamoma DSP to function within AudioGraph.
void unlockProcessing()
The thread protection for processing is important: we cannot have the graph nodes being deleted or re...
TTUInt64 mSampleStamp
The current time in samples.
Defines output interface at the bottom of an AudioGraph.
TTObjectBasePtr mAudioEngine
The audio engine that signals are output to.
TTAudioSignalPtr placeHolder
An unused audio signal that we pass.
A simple container for an array of TTAudioSignal pointers.
TTUInt64 mSampleStamp
The current time in samples, as determined from the pulling of this object.
virtual TTErr process(TTAudioSignalPtr &returnedSignal, TTUInt64 sampleStamp, TTUInt16 forOutletNumber=0)
This method is required to be implemented by all objects except for those existing solely as a destin...
TTErr setVectorSize(const TTValue &newValue)
Set vector size.
TTErr start()
Start audio processing.
TTErr getSampleRate(TTValue &returnedValue)
Get current sample rate.
TTErr audioEngineWillProcess()
This method is called by the audio engine every time a new vector of output is required.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
The TTAudioGraphObjectBase wraps a TTDSP object such that it is possible to build a dynamic graph of ...
#define addMessage(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:19
32-bit unsigned integer, range is 0 through 4,294,967,295.
Definition: TTBase.h:278
TTErr getVectorSize(TTValue &returnedValue)
Get current vector size.
No Error.
Definition: TTBase.h:343
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
TTChannelCount numAudioSignals
The number of audio signal pointers which are actually valid.
#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
#define addMessageProperty(messageName, propertyName, initialValue)
A convenience macro to be used for registering properties of messages.
Definition: TTMessage.h:37