CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

AmbisonicUtilities.h
Go to the documentation of this file.
1 //
2 // AmbisonicUtilities.h -- Higher Order Ambisonic utility classes
3 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 // Higher Order Ambisonic classes written by Jorge Castellanos, Graham Wakefield, Florian Hollerweger, 2005
5 //
6 // Utility classes used by HOA_Encoder, MOA_Encoder, AmbisonicRotator, MOA_Rotator, HOA_Decoder
7
8 #ifndef AMBISONIC_UTILITIES_H
9 #define AMBISONIC_UTILITIES_H
10
11 #include "CSL_Core.h"
12 #include "Ambisonic.h"
13
14 #define AMBI_INVSQRT2 (1/1.414213562)
15
16 namespace csl {
17
18 /// Utility function used in calculating the inverse of a matrix, used in AmbisonicDecoder for the pseudoinverse method
19
20 void singularValueDecomposition(sample** a, int m, int n, sample* w, sample** v);
21
22 /// Utility function that calculates fuma encoding weights for a given order, azimuth and elevation.
23
24 void fumaEncodingWeights(SampleBuffer weights, const AmbisonicOrder &order, sample azimuth, sample elevation);
25
26 /// Utility function that calculates fuma encoding weights for a given order, azimuth and elevation.
27
28 void fumaIndexedEncodingWeights(SampleBuffer weights, const AmbisonicOrder &order, sample &azimuth, sample &elevation);
29
30
31 // AmbisonicMixer -- Higher Order Ambisonic mixing class
32 //
33 // Higher Order Ambisonic class for mixing encoded ambisonic encoded audio streams. All incoming streams should have
34 // the same order; the order used is derived from the first stream added.
35
36 class AmbisonicMixer : public AmbisonicUnitGenerator {
37 public:
38
39 // Constructors & destructor:
40 AmbisonicMixer(unsigned order = 1); // Default constructor
41 AmbisonicMixer(unsigned hOrder, unsigned vOrder); // Default constructor
42
43 //// Initialize with one input, derive the Mixer ambisonic order from this input.
44 // AmbisonicMixer(UnitGenerator &input);
45
46 ~AmbisonicMixer(); ///< Destructor
47
48 /// Initializing method called by constructors
49 void initialize();
50
51 /// methods for adding/removing inputs to the mixer.
52 void addInput(AmbisonicUnitGenerator &input);
53 void addInput(UnitGenerator &input);
54
55 unsigned numInputs() { return mInputs.size(); }; ///< Number of active inputs
56
57 // nextBuffer(). Does the DSP processing for the Ambisonic Mixer.
58 virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw(CException);
59
60 protected:
61 UGenVector mInputs; ///< vector of pointers to the loudspeakers
62 Buffer *mInBuffer; ///< buffer for the input framestream
63 float mInvNumInputs; ///< the inverse of the number of inputs (used for normalization)
64
65 };
66
67 typedef enum {
68 kTILT = 0,
69 kTUMBLE,
70 kROTATE // to be used with the "setNthInput" method to add control sources
71 } Axes; // tilt -> x axis, tumble -> y axis, rotate -> z axis
72
73 // AmbisonicRotator.h -- Higher Order Ambisonic rotator class
74 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
75 // Higher Order Ambisonic classes written by Jorge Castellanos, Graham Wakefield, Florian Hollerweger, 2005
76 //
77 // Higher Order Ambisonic class for rotating an Ambisonic encoded sound field (e.g. the output of the HOA_Encoder)
78 // around any combination of x, y and z axes. Rotation is applied by using the method "setNthInput" with the flags
79 // HOA_TILT, HOA_TUMBLE, HOA_ROTATE as desired. The order of the incoming Ambisonic framestream can be degraded to
80 // match the maximum order of the available decoding system (number of available speakers). It is possible to specify
81 // either one uniform Ambisonic order or to define the horizontal and vertical order separately (hybrid order rotating).
82 // If no order(s) is/are specified, the order(s) of the Ambisonic encoded input framestream will be used.
83
84 class AmbisonicRotator : public AmbisonicUnitGenerator {
85 public:
86 // Constructors & destructor:
87 /// initializes with no rotation
88 AmbisonicRotator(AmbisonicUnitGenerator &input);
89 /// initializes with uniform Ambisonic order and no rotation
90 AmbisonicRotator(UnitGenerator &input, unsigned order);
91 /// initializes with hybrid Ambisonic order and no rotation
92 AmbisonicRotator(UnitGenerator &input, unsigned vorder, unsigned horder);
93
94 ~AmbisonicRotator(); // destructor
95
96
97 // set control input sources according axis flag
98 void setNthInput(float amount, Axes axis);
99 void setTilt(float amount);
100 void setTumble(float amount);
101 void setRotate(float amount);
102
103 // Overriding Framestream::next_buffer(). Does the DSP processing for the Ambisonic Rotator.
104 virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw(CException);
105
106 protected:
107 unsigned mNumFrames;
108 unsigned mGreaterOrder;
109 unsigned mNumChannelsGreaterOrder;
110 unsigned *mChannelIndex; // index to the output buffer in the encoding functions.
111 unsigned *mInputChannelIndex; // index to the input buffer in the encoding functions (in case input order != output order)
112 bool mShouldRotate, mShouldTurn, mShouldTilt; // flags to note whether rotation in each axis is being used
113
114 private:
115 Port *mInputPort;
116
117 sample mRotate, mTumble, mTilt; // the current amount of rotation in each axis (in radians)
118 SampleBuffer mSinAngle, mCosAngle; // Used to hold sines/cosines of tilt, tumble, rotate angles during audio processing
119 SampleBufferVector mOutPtr, mInPtr; // pointers to Ambisonic encoded input and Ambisonic encoded & rotated output buffers
120
121 void initialize(UnitGenerator &input);
122
123 // methods for tilt, tumble & rotate at each order
124 void tiltFirstOrder();
125 void tiltSecondOrder();
126 void tiltThirdOrder();
127
128 void tumbleFirstOrder();
129 void tumbleSecondOrder();
130 void tumbleThirdOrder();
131
132 // methods for rotation at each order
133 // separated by horizontal & vertical for hybrid order systems (which can be rotated, but not tilted or tumbled)
134 void rotateZerothOrder();
135 void rotateFirstOrderHorizontal();
136 void rotateSecondOrderHorizontal();
137 void rotateThirdOrderHorizontal();
138 void rotateFirstOrderVertical();
139 void rotateSecondOrderVertical();
140 void rotateThirdOrderVertical();
141 };
142
143 }
144
145 #endif