Jamoma API  0.6.0.a19
TTOutputAudio.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup modularLibrary
4  *
5  * @brief An audio output component for Jamoma models.
6  *
7  * @details
8  *
9  * @authors Timothy Place
10  *
11  * @copyright © 2013, 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 #include "TTOutputAudio.h"
17 
18 #define thisTTClass TTOutputAudio
19 #define thisTTClassName "Output.audio"
20 #define thisTTClassTags "output"
21 
22 TTObjectBasePtr TTOutputAudio::instantiate (TTSymbol name, TTValue arguments)
23 {
24  return new TTOutputAudio(arguments);
25 }
26 
27 
28 extern "C" void TTOutputAudio::registerClass()
29 {
30  TTClassRegister(TTSymbol("Output.audio"), thisTTClassTags, TTOutputAudio::instantiate);
31 }
32 
33 
34 TTOutputAudio::TTOutputAudio(const TTValue& arguments) :
35 TTOutput(arguments)
36 {
37  TTValue args;
38 
39  mType = "audio";
40 
41  // the only argument is the owner, which is used as a baton to hand to the callback
42  if (arguments.size() > 0)
43  mReturnSignalCallback = arguments[0];
44 
45  mSignalIn = TTObject(kTTSym_audiosignal, 1);
46  mSignalOut = TTObject(kTTSym_audiosignal, 1);
47  mSignalTemp = TTObject(kTTSym_audiosignal, 1);
48  mSignalZero = TTObject(kTTSym_audiosignal, 1);
49 
50  // note : crossfade instantiation can failed if JamomaDSP is not loaded.
51  // maybe this means we should move TTOutputAudio into JamomaDSP ?
52  if (!ttEnvironment->isClassRegistered("crossfade")) {
53  mMixUnit = TTObject("crossfade", 1);
54  mMixUnit.set("position", 1.0);
55  }
56 
57  // note : gain instantiation can failed if JamomaDSP is not loaded.
58  // maybe this means we should move TTOutputAudio into JamomaDSP ?
59  if (!ttEnvironment->isClassRegistered("gain")) {
60  mGainUnit = TTObject("gain", 1);
61  mGainUnit.set("linearGain", 1.0);
62  }
63 
64  // note : ramp instantiation can failed if JamomaDSP is not loaded.
65  // maybe this means we should move TTOutputAudio into JamomaDSP ?
66  if (!ttEnvironment->isClassRegistered("ramp")) {
67  mRampMixUnit = TTObject(TTSymbol("ramp"), 1);
68  mRampGainUnit = TTObject(TTSymbol("ramp"), 1);
69  }
70 }
71 
72 
73 TTOutputAudio::~TTOutputAudio()
74 {
75  ;
76 }
77 
78 
79 void TTOutputAudio::process(TTSampleValue* anInputSampleVector, TTSampleValue* anOutputSampleVector, TTUInt16 aVectorSize)
80 {
81  // Store the audio vector as a proper audio signal
82  TTAudioSignalPtr(mSignalIn.instance())->setVector64Copy(0, aVectorSize, anInputSampleVector);
83 
84  // if the output signal is muted
85  if (mMute)
86  TTAudioSignal::copy(*TTAudioSignalPtr(mSignalZero.instance()), *TTAudioSignalPtr(mSignalOut.instance()));
87 
88  // if input signal exists
89  else if (mInputObject.instance()) {
90 
91  // if input signal is bypassed : copy input (in Temp)
92  if (TTInputPtr(mInputObject.instance())->mBypass)
93  TTAudioSignal::copy(*TTAudioSignalPtr(TTInputPtr(mInputObject.instance())->mSignalIn.instance()), *TTAudioSignalPtr(mSignalTemp.instance()));
94 
95  // otherwise mix input and output signals (in Temp)
96  else
97  TTAudioObjectBasePtr(mMixUnit.instance())->process(TTAudioSignalPtr(TTInputPtr(mInputObject.instance())->mSignalOut.instance()), TTAudioSignalPtr(mSignalIn.instance()), TTAudioSignalPtr(mSignalTemp.instance()));
98 
99  // then perform gain control (from Temp)
100  TTAudioObjectBasePtr(mGainUnit.instance())->process(TTAudioSignalPtr(mSignalTemp.instance()), TTAudioSignalPtr(mSignalOut.instance()));
101  }
102  // otherwise just perform gain control
103  else
104  TTAudioObjectBasePtr(mGainUnit.instance())->process(TTAudioSignalPtr(mSignalIn.instance()), TTAudioSignalPtr(mSignalOut.instance()));
105 
106  // Send the input on to the outlets for the algorithm
107  TTAudioSignalPtr(mSignalOut.instance())->getVectorCopy(0, aVectorSize, anOutputSampleVector);
108 }
109 
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
TTFOUNDATION_EXPORT TTEnvironment * ttEnvironment
The environment object has one instance, which is global in scope.
Create and use Jamoma object instances.
Definition: TTObject.h:29
size_type size() const noexcept
Return the number of elements.
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
TTAudioObjectBase * TTAudioObjectBasePtr
Pointer to a TTAudioObjectBase.
An audio output component for Jamoma models.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
The TTAudioSignal class represents N vectors of audio samples for M channels.
Definition: TTAudioSignal.h:57
TTErr isClassRegistered(const TTSymbol &className)
Check if a class is registered.
static TTErr copy(const TTAudioSignal &source, TTAudioSignal &dest, TTChannelCount channelOffset=0)
Copy the audio from one signal into another.
An audio output component for Jamoma models.
Definition: TTOutputAudio.h:23
TTFloat64 TTSampleValue
A value representing a single audio sample.
Definition: TTBase.h:230
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34