Jamoma API  0.6.0.a19
TTSpatDBAP.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup dspSpatLib
4  *
5  * @brief Jamoma DSP SpatLib unit based on Distance-based amplitude panning (DBAP)
6  *
7  * @details DBAP permits sinks (speakers) to be positioned any way you want.
8  * Speaker configurations are not limited to circles/spheres surrounding a sweet spot, but can be used e.g. to locate speakers in several adjecent spaces.
9  * DBAP is matrix-based and ensures equal intensity while adjusting gains to each of the sinks in such a way that relative gain diminish with increasing distance from source to sink.
10  * The exact rolloff rate (in dB) can be controlled with the rolloff attribute of the #TTSpatDBAPRenderer class.
11  *
12  * @todo: Extend with a solution for interpolating to new matrix coefficients
13  *
14  * @authors Trond Lossius, Nils Peters, Timothy Place
15  *
16  * @copyright Copyright © 2011 by Trond Lossius, Nils Peters, and Timothy Place @n
17  * This code is licensed under the terms of the "New BSD License" @n
18  * http://creativecommons.org/licenses/BSD/
19  */
20 
21 #include "TTSpatDBAP.h"
22 
23 #define thisTTClass TTSpatDBAP
24 #define thisTTClassName "spat.dbap"
25 #define thisTTClassTags "audio, spatialization, processing, dbap"
26 
27 
28 TTObjectBasePtr TTSpatDBAP::instantiate(TTSymbol name, TTValue arguments)
29 {
30  return (TTObjectBasePtr) new thisTTClass(arguments);
31 }
32 
33 
34 extern "C" void thisTTClass :: registerClass ()
35 {
36  TTClassRegister( thisTTClassName, thisTTClassTags, thisTTClass :: instantiate );
37 }
38 
39 
40 TTSpatDBAP::TTSpatDBAP(const TTValue& arguments) : TTSpatBase(arguments)
41 {
42  mRenderer = new TTSpatDBAPRenderer;
43 
45 
46  addMessageWithArguments(getSourceWidth);
47  addMessageWithArguments(setSourceWidth);
48 }
49 
50 
51 TTSpatDBAP::~TTSpatDBAP()
52 {
53  delete mRenderer;
54 }
55 
56 
58 {
59  aValue = getRenderer()->getRolloff();
60  return kTTErrNone;
61 }
62 
63 
65 {
66  TTFloat64 rolloff = aValue;
67 
68  getRenderer()->setRolloff(rolloff);
69  getRenderer()->recalculateMatrixCoefficients(mSources, mSinks);
70  return kTTErrNone;
71 }
72 
73 
74 // TODO: Problem -- when initializing the matrix will be calculated many many times
75 
76 
77 TTErr TTSpatDBAP::setSourceWidth(const TTValue& aWidth, TTValue& anUnused)
78 {
79  TTInt32 sourceNumber;
80  TTFloat64 width;
81 
82  // TODO: We need to think of what to do if there are not two arguments...
83 
84  sourceNumber = aWidth[0];
85  width = aWidth[1];
86 
87  sourceNumber = sourceNumber - 1;
88  sourceNumber = TTClip<TTInt32>(sourceNumber, 0, mSources.size()-1);
89  getSource(sourceNumber)->setWidth(width);
90  mRenderer->recalculateMatrixCoefficients(mSources, mSinks);
91 
92  return kTTErrNone; // Return something else if we don't have four arguments
93 }
94 
95 
96 TTErr TTSpatDBAP::getSourceWidth(const TTValue& aRequestedChannel, TTValue& aWidth)
97 {
98  TTInt16 sourceNumber;
99  TTFloat64 width;
100 
101  // TODO: We need to think of what to do if there are no arguments...
102  // or if sinkNumber is out of range of the available sources
103 
104  sourceNumber = aRequestedChannel[0];
105 
106  sourceNumber = sourceNumber - 1;
107  sourceNumber = TTClip<TTInt32>(sourceNumber, 0, mSources.size()-1);
108  getSource(sourceNumber)->getWidth(width);
109 
110  aWidth.resize(2);
111  aWidth[0] = sourceNumber;
112  aWidth[1] = width;
113 
114  return kTTErrNone;
115 }
116 
117 
TTSpatDBAPRenderer contains attributes and methods that are specific to this particular spatialisatio...
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
std::int16_t TTInt16
16 bit signed integer
Definition: TTBase.h:175
64-bit floating point
Definition: TTBase.h:272
void recalculateMatrixCoefficients(TTSpatSourceVector &aSources, TTSpatSinkVector &aSinks)
This method is called whenever matrix coefficients need to be updated.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:27
TTErr setRolloff(const TTValue &aValue)
TODO: document.
Definition: TTSpatDBAP.cpp:64
std::int32_t TTInt32
32 bit signed integer
Definition: TTBase.h:177
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
This class is eventually intended to provide a generalised interface for spatial renderers.
Definition: TTSpatBase.h:31
No Error.
Definition: TTBase.h:343
TTErr getRolloff(TTValue &aValue)
TODO: document.
Definition: TTSpatDBAP.cpp:57
void resize(size_type n)
Change the number of elements.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
Jamoma DSP SpatLib unit based on Distance-based amplitude panning (DBAP)
#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