AmbisonicUtilities.h

Go to the documentation of this file.
00001 /*
00002 
00003 HOA_Utilities.h -- Higher Order Ambisonic utility classes
00004 See the copyright notice and acknowledgment of authors in the file COPYRIGHT
00005 Higher Order Ambisonic classes written by Jorge Castellanos, Graham Wakefield, Florian Hollerweger, 2005
00006 
00007 Utility classes used by HOA_Encoder, MOA_Encoder, AmbisonicRotator, MOA_Rotator, HOA_Decoder
00008 
00009 */
00010 
00011 #ifndef AMBISONIC_UTILITIES_H
00012 #define AMBISONIC_UTILITIES_H
00013 
00014 #include "CSL_Core.h"
00015 #include "Ambisonic.h"
00016 
00017 #define AMBI_INVSQRT2 (1/1.414213562)
00018 
00019 namespace csl {
00020 
00021 
00023 void singularValueDecomposition(sample** a, int m, int n, sample* w, sample** v);
00024 
00026 void fumaEncodingWeights(sample *weights, const AmbisonicOrder &order, sample azimuth, sample elevation);
00027 
00029 void fumaIndexedEncodingWeights(sample *weights, const AmbisonicOrder &order, sample &azimuth, sample &elevation);
00030 
00031 
00038 class AmbisonicMixer : public AmbisonicUnitGenerator {
00039 public:
00040     
00041     // Constructors & destructor:
00042     AmbisonicMixer(unsigned order = 1); // Default constructor
00043     AmbisonicMixer(unsigned hOrder, unsigned vOrder); // Default constructor
00044     
00046 //  AmbisonicMixer(UnitGenerator &input);
00047     
00048     ~AmbisonicMixer();  
00049 
00051     void initialize();
00052     
00054     void addInput(AmbisonicUnitGenerator &input);
00055     void addInput(UnitGenerator &input);
00056         
00057     unsigned numInputs() { return mInputs.size(); };    
00058 
00059     // nextBuffer(). Does the DSP processing for the Ambisonic Mixer.
00060     virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw(CException);
00061 
00062 protected:
00063 
00064     vector<UnitGenerator *> mInputs;        
00065     Buffer *mInBuffer;                      // buffer for the input framestream
00066 
00067     float mInvNumInputs;                   // the inverse of the number of inputs (used for normalization)
00068     
00069 };
00070 
00071 typedef enum {
00072     kTILT = 0, 
00073     kTUMBLE, 
00074     kROTATE // to be used with the "setNthInput" method to add control sources
00075 } Axes;                                     // tilt -> x axis, tumble -> y axis, rotate -> z axis
00076 
00092 class AmbisonicRotator : public AmbisonicUnitGenerator {
00093 public:
00094     
00095     // Constructors & destructor:
00096         
00098     AmbisonicRotator(AmbisonicUnitGenerator &input);
00099     
00101     AmbisonicRotator(UnitGenerator &input, unsigned order);
00102     
00104     AmbisonicRotator(UnitGenerator &input, unsigned vorder, unsigned horder);
00105 
00106     ~AmbisonicRotator(); // destructor
00107     
00108     
00109     // set control input sources according axis flag
00110     void setNthInput(float amount, Axes axis);
00111     void setTilt(float amount);
00112     void setTumble(float amount);
00113     void setRotate(float amount);
00114     
00115     // Overriding Framestream::next_buffer(). Does the DSP processing for the Ambisonic Rotator.
00116     virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw(CException);
00117                 
00118 protected:
00119     unsigned mNumFrames;
00120     unsigned mGreaterOrder;
00121     unsigned mNumChannelsGreaterOrder;
00122     unsigned *mChannelIndex;        // index to the output buffer in the encoding functions.
00123     unsigned *mInputChannelIndex;   // index to the input buffer in the encoding functions (in case input order != output order)
00124     bool mShouldRotate, mShouldTurn, mShouldTilt;   // flags to note whether rotation in each axis is being used
00125 
00126 private:
00127     UGenPort *mInputPort;
00128 
00129     sample mRotate, mTumble, mTilt;             // the current amount of rotation in each axis (in radians)
00130     sample *mSinAngle, *mCosAngle;              // Used to hold sines/cosines of tilt, tumble, rotate angles during audio processing
00131     sample **mOutPtr, **mInPtr;                 // pointers to Ambisonic encoded input and Ambisonic encoded & rotated output buffers
00132     
00133     void initialize(UnitGenerator &input);  
00134     
00135     // methods for tilt, tumble & rotate at each order
00136     void tiltFirstOrder();
00137     void tiltSecondOrder();
00138     void tiltThirdOrder();
00139     
00140     void tumbleFirstOrder();
00141     void tumbleSecondOrder();
00142     void tumbleThirdOrder();
00143     
00144     // methods for rotation at each order
00145     // separated by horizontal & vertical for hybrid order systems (which can be rotated, but not tilted or tumbled)
00146     void rotateZerothOrder();
00147     void rotateFirstOrderHorizontal();  
00148     void rotateSecondOrderHorizontal();
00149     void rotateThirdOrderHorizontal();
00150     void rotateFirstOrderVertical();    
00151     void rotateSecondOrderVertical();
00152     void rotateThirdOrderVertical();
00153 
00154     
00155 };
00156 
00157 
00158 }
00159 
00160 #endif

Generated on Fri Apr 6 20:18:13 2007 for CSL by  doxygen 1.4.5-20051010