CSL  6.0
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 
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,
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 
85 public:
86  // Constructors & destructor:
87  /// initializes with no rotation
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;
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:
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();
138  void rotateFirstOrderVertical();
141 };
142 
143 }
144 
145 #endif
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
Definition: CSL_Types.h:194
SampleBufferVector mOutPtr
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
void setNthInput(float amount, Axes axis)
void fumaEncodingWeights(SampleBuffer weights, const AmbisonicOrder &order, sample azimuth, sample elevation)
Utility function that calculates fuma encoding weights for a given order, azimuth and elevation...
AmbisonicMixer(unsigned order=1)
UGenVector mInputs
vector of pointers to the loudspeakers
void setRotate(float amount)
float sample
(could be changed to int, or double)
Definition: CSL_Types.h:191
void addInput(AmbisonicUnitGenerator &input)
methods for adding/removing inputs to the mixer.
virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
Number of active inputs.
std::vector< UnitGenerator * > UGenVector
Definition: CSL_Types.h:241
AmbisonicRotator(AmbisonicUnitGenerator &input)
initializes with no rotation
virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
void initialize()
Initializing method called by constructors.
~AmbisonicMixer()
Destructor.
void setTumble(float amount)
void setTilt(float amount)
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Definition: CSL_Core.h:106
Ambisonic Abstract Base Class.
Definition: Ambisonic.h:69
SampleBuffer * SampleBufferVector
Multi-channel buffer data type, vector of (SampleBuffer)
Definition: CSL_Types.h:195
Port – used to represent constant, control-rate or signal inputs and outputs in named maps; holds a ...
Definition: CSL_Core.h:312
forward declaration
Definition: CSL_Core.h:241
SampleBufferVector mInPtr
float mInvNumInputs
the inverse of the number of inputs (used for normalization)
Buffer * mInBuffer
buffer for the input framestream
void fumaIndexedEncodingWeights(SampleBuffer weights, const AmbisonicOrder &order, sample &azimuth, sample &elevation)
Utility function that calculates fuma encoding weights for a given order, azimuth and elevation...
void initialize(UnitGenerator &input)
Base class of CSL exceptions (written upper-case). Has a string message.
void singularValueDecomposition(sample **a, int m, int n, sample *w, sample **v)
Utility function used in calculating the inverse of a matrix, used in AmbisonicDecoder for the pseudo...