AmbisonicUtilities.h

Go to the documentation of this file.
00001 //
00002 //  AmbisonicUtilities.h -- Higher Order Ambisonic utility classes
00003 //  See the copyright notice and acknowledgment of authors in the file COPYRIGHT
00004 //  Higher Order Ambisonic classes written by Jorge Castellanos, Graham Wakefield, Florian Hollerweger, 2005
00005 //
00006 //  Utility classes used by HOA_Encoder, MOA_Encoder, AmbisonicRotator, MOA_Rotator, HOA_Decoder
00007 
00008 #ifndef AMBISONIC_UTILITIES_H
00009 #define AMBISONIC_UTILITIES_H
00010 
00011 #include "CSL_Core.h"
00012 #include "Ambisonic.h"
00013 
00014 #define AMBI_INVSQRT2 (1/1.414213562)
00015 
00016 namespace csl {
00017 
00019 
00020 void singularValueDecomposition(sample** a, int m, int n, sample* w, sample** v);
00021 
00023 
00024 void fumaEncodingWeights(SampleBuffer weights, const AmbisonicOrder &order, sample azimuth, sample elevation);
00025 
00027 
00028 void fumaIndexedEncodingWeights(SampleBuffer weights, const AmbisonicOrder &order, sample &azimuth, sample &elevation);
00029 
00030 
00031 //  AmbisonicMixer -- Higher Order Ambisonic mixing class
00032 //
00033 //  Higher Order Ambisonic class for mixing encoded ambisonic encoded audio streams.  All incoming streams should have
00034 //  the same order; the order used is derived from the first stream added.
00035 
00036 class AmbisonicMixer : public AmbisonicUnitGenerator {
00037 public:
00038     
00039     // Constructors & destructor:
00040     AmbisonicMixer(unsigned order = 1); // Default constructor
00041     AmbisonicMixer(unsigned hOrder, unsigned vOrder); // Default constructor
00042     
00044 //  AmbisonicMixer(UnitGenerator &input);
00045     
00046     ~AmbisonicMixer();  
00047 
00049     void initialize();
00050     
00052     void addInput(AmbisonicUnitGenerator &input);
00053     void addInput(UnitGenerator &input);
00054         
00055     unsigned numInputs() { return mInputs.size(); };    
00056 
00057     // nextBuffer(). Does the DSP processing for the Ambisonic Mixer.
00058     virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw(CException);
00059 
00060 protected:
00061     UGenVector mInputs;                     
00062     Buffer *mInBuffer;                      
00063     float mInvNumInputs;                    
00064     
00065 };
00066 
00067 typedef enum {
00068     kTILT = 0, 
00069     kTUMBLE, 
00070     kROTATE // to be used with the "setNthInput" method to add control sources
00071 } Axes;                                     // tilt -> x axis, tumble -> y axis, rotate -> z axis
00072 
00073 //  AmbisonicRotator.h -- Higher Order Ambisonic rotator class
00074 //  See the copyright notice and acknowledgment of authors in the file COPYRIGHT
00075 //  Higher Order Ambisonic classes written by Jorge Castellanos, Graham Wakefield, Florian Hollerweger, 2005
00076 //
00077 //  Higher Order Ambisonic class for rotating an Ambisonic encoded sound field (e.g. the output of the HOA_Encoder)
00078 //  around any combination of x, y and z axes. Rotation is applied by using the method "setNthInput" with the flags
00079 //  HOA_TILT, HOA_TUMBLE, HOA_ROTATE as desired. The order of the incoming Ambisonic framestream can be degraded to
00080 //  match the maximum order of the available decoding system (number of available speakers). It is possible to specify
00081 //  either one uniform Ambisonic order or to define the horizontal and vertical order separately (hybrid order rotating).
00082 //  If no order(s) is/are specified, the order(s) of the Ambisonic encoded input framestream will be used.
00083 
00084 class AmbisonicRotator : public AmbisonicUnitGenerator {
00085 public:
00086                 // Constructors & destructor:
00088     AmbisonicRotator(AmbisonicUnitGenerator &input);
00090     AmbisonicRotator(UnitGenerator &input, unsigned order);
00092     AmbisonicRotator(UnitGenerator &input, unsigned vorder, unsigned horder);
00093 
00094     ~AmbisonicRotator(); // destructor
00095     
00096     
00097     // set control input sources according axis flag
00098     void setNthInput(float amount, Axes axis);
00099     void setTilt(float amount);
00100     void setTumble(float amount);
00101     void setRotate(float amount);
00102     
00103     // Overriding Framestream::next_buffer(). Does the DSP processing for the Ambisonic Rotator.
00104     virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw(CException);
00105                 
00106 protected:
00107     unsigned mNumFrames;
00108     unsigned mGreaterOrder;
00109     unsigned mNumChannelsGreaterOrder;
00110     unsigned *mChannelIndex;        // index to the output buffer in the encoding functions.
00111     unsigned *mInputChannelIndex;   // index to the input buffer in the encoding functions (in case input order != output order)
00112     bool mShouldRotate, mShouldTurn, mShouldTilt;   // flags to note whether rotation in each axis is being used
00113 
00114 private:
00115     Port *mInputPort;
00116 
00117     sample mRotate, mTumble, mTilt;                 // the current amount of rotation in each axis (in radians)
00118     SampleBuffer mSinAngle, mCosAngle;              // Used to hold sines/cosines of tilt, tumble, rotate angles during audio processing
00119     SampleBufferVector mOutPtr, mInPtr;             // pointers to Ambisonic encoded input and Ambisonic encoded & rotated output buffers
00120     
00121     void initialize(UnitGenerator &input);  
00122     
00123     // methods for tilt, tumble & rotate at each order
00124     void tiltFirstOrder();
00125     void tiltSecondOrder();
00126     void tiltThirdOrder();
00127     
00128     void tumbleFirstOrder();
00129     void tumbleSecondOrder();
00130     void tumbleThirdOrder();
00131     
00132     // methods for rotation at each order
00133     // separated by horizontal & vertical for hybrid order systems (which can be rotated, but not tilted or tumbled)
00134     void rotateZerothOrder();
00135     void rotateFirstOrderHorizontal();  
00136     void rotateSecondOrderHorizontal();
00137     void rotateThirdOrderHorizontal();
00138     void rotateFirstOrderVertical();    
00139     void rotateSecondOrderVertical();
00140     void rotateThirdOrderVertical();
00141 };
00142 
00143 }
00144 
00145 #endif

Generated on Thu Sep 17 23:14:16 2009 for CSL by  doxygen 1.5.8