VBAP.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 #ifndef CSL_VBAP_H
00007 #define CSL_VBAP_H
00008 
00009 #include "CSL_Core.h"
00010 #include "Panner.h"
00011 
00012 //#define CSL_DEBUG
00013 
00014 #include <iostream>
00015 
00017 #define _NO_EXCEPTION
00018 
00019 #include "matrix.h"
00020 
00021 #ifndef _NO_NAMESPACE
00022   using namespace std;
00023   using namespace math;
00024 #  define STD std
00025 #else
00026 #  define STD
00027 #endif
00028 
00029 #  define TRYBEGIN()
00030 #  define CATCHERROR()
00031 
00032 typedef matrix<double> CSLMatrix;
00034 
00035 namespace csl {
00036 
00037 #define deg2rad(x)   ( ( (double)x ) * CSL_TWOPI) / 360.0
00038 
00040 typedef enum {
00041     kAuto = 0,
00042     kPantophonic = 2,       
00043     kPeriphonic = 3         
00044 } VBAPMode;
00045 
00046 class SpeakerSetLayout;  // Forward declaration. See below.
00047 
00048 
00050 
00055 class VBAP : public Panner {
00056 public:
00059     VBAP(VBAPMode mode = kAuto, SpeakerLayout *layout = SpeakerLayout::defaultSpeakerLayout()); 
00060 
00061     virtual ~VBAP();
00062     
00064     void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException);
00065 
00066     void dump() {}; 
00067 
00068 protected:
00069     VBAPMode mMode;     
00070     SpeakerSetLayout *mSpeakerSetLayout;  
00071  
00072     virtual void *cache();      
00073     virtual void speakerLayoutChanged();    
00074 
00075 };
00076 
00079 class StereoPanner : public VBAP {
00080 public:
00081     StereoPanner();
00082     virtual ~StereoPanner();
00083 
00084     void addInput(UnitGenerator &input, float panPosition);
00085     
00086 };
00087 
00090 class SurroundPanner : public VBAP {
00091 public:
00093     SurroundPanner(unsigned numSpeakers = 5, bool useSubwoofer = true);
00094     virtual ~SurroundPanner();
00095 
00096 };
00097 
00098 // Used for caching data from previous callbacks. Each SpatialSource has its own set of data to be remembered.
00099 // This is just for internal use of the VBAP object.
00100 class VBAPSourceCache {
00101 public:
00102     VBAPSourceCache() : tripletIndex(0) {};
00103     ~VBAPSourceCache() {};
00104     
00105     float gains[3];
00106     unsigned tripletIndex;
00107 };
00108  
00110 class SpeakerSet { 
00111 public:
00112     SpeakerSet(unsigned size = 3);
00113     ~SpeakerSet();
00114 
00115     unsigned *nodes;        
00116     CSLMatrix *invL;        
00117     void dump();        
00118 };
00119 
00120 /*// **** SPEAKER TRIPLET LAYOUT  ***** 
00121 TO AVOID BUILDING A TRIPLET LAYOUT PER VBAP INSTANCE, THE VBAP CLASS WILL HAVE A STATIC METHOD THAT 
00122 RETURS A MAP OF THE SPEAKER LAYOUT (KEY) AND THE TRIPLET SPEAKER LAYOUT (VALUE). THIS WAY, IF ANOTHER
00123 INSTANCE HAS ALREADY CREATED A TRIPLET LAYOUT (IN OTHER WORDS IF A NEW INSTANCE IS USING THE SAME LAYOUT
00124 THAN THE ALREADY CREATED INSTANCE) THEN A POINTER TO THE TRIPLET LAYOUT WILL BE RETURNED.
00125 AS AN ALTERNATIVE, INSTEAD OF A MAP, THE TRIPLET SPEAKER LAYOUT WILL HOLD A POINTER TO THE SPEAKER LAYOUT
00126 AND WILL BE ABLE TO COMPARE TO A PASSED POINTER. IN THES CASE, A STATIC VECTOR OF TRIPLET LAYOUTS WOULD HOLD
00127 THE ALREADY CREATED TRIPLET LAYOUTS AND WHEN CREATING A NEW VBAP INSTANCE, IT WOULD GO THRU EACH TRIPLET LAYOUT
00128 (IF ANY) COMPARING SPEAKER LAYOUT ADDRESSES. IF A MATCH IS FOUND, THE TRIPLET LAYOUT WOULD BE SET TO BE THE OBJECT
00129 HELD BY THE VBAP INSTANCE (EACH VBAP INSTANCE WILL KEEP ITS OWN POINTER TO ITS TRIPLET LAYOUT OBJECT. FOR THIS TO WORK
00130 SOME SORT OF COUNT WILL BE NEEDED SO WHEN NO OBJECT IS KEEPING A TRIPLET, THEN IT SHOULD GET DESTROYED.
00131 WHEN SETTING THE SPEAKER LAYOUT, THE OBJECT WILL HAVE TO SEARCH AGAIN FOR TRIPLET LAYOUTS ALREADY CREATED, AND RE COMPUTE 
00132 ONE IF NONE EXISTS.
00133 ADVANTAGES: 
00134     A) THE TRIPLET FINDING GOES TO THE LAYOUT AND AWAY FROM THE VBAP, SIMPLIFYING THE VABAP INTERFACE.
00135     B) SAVES MEMORY USAGE BY HAVING ONLY ONE INSTANCE OF TRIPLETS FOR EACH LAYOUT USED.
00136         IN MOST CASES, ONLY ONE LAYOUT IS USED, WHICH TRANSLATIES INTO ONLY ONE SET OF TRIPLETS IN MEMORY.
00137     C) SAVES COMPUTATION BY NOT RECALCULATING TRIPLETS FOR EACH VBAP INSTANCE. IT DOES IT ONLY ON ONE.
00138     
00139 COST:
00140     A) COMPUTATIONALLY THE COST IS MINIMAL. AT INSTANTIATION TIME, THE OBJECT HAS TO SEARCH THRU A VECTOR. 
00141         THIS BECOMES NULL IF NO OBJECTS ARE USED AND INSIGNIFICANT WHEN ONE OR MORE OBJECTS ARE INSTANTIATED.
00142     B) REGARDING MEMORY, IT'LL HAVE TO LOAD STATICALLY A VECTOR AT APP LOAD TIME...
00143 
00144 */
00145 class SpeakerSetLayout {
00146 friend class VBAP; // Grant VBAP the access to your private members.
00147 public:
00149     SpeakerSetLayout(SpeakerLayout *aLayout, VBAPMode mode = kAuto); 
00150     ~SpeakerSetLayout();                
00151 
00153     SpeakerLayout *speakerLayout() { return mSpeakerLayout; }; // Ussed to compare layouts in case it's already calculated.
00154     
00155     void dump();
00156 
00157 private:
00158     // THE TRIPLETS SHOULD BE SHARED AMONG ALL VBAP OBJECTS, UNLESS MULTIPLE LAYOUTS ARE USED SIMULTANEOUSLY.
00159     SpeakerSet **mTriplets; // list of output triples
00160     SpeakerLayout *mSpeakerLayout;
00161     unsigned mNumTriplets;
00162     unsigned mMode;
00163     
00164     void findSpeakerTriplets() throw(CException);
00165     void findSpeakerPairs() throw(CException);
00166     void invertTripleMatrix(SpeakerSet *lst);
00167     void addTriple( SpeakerSet *lst);
00168     void removeTriple(SpeakerSet *lst);
00169     bool evaluateCrossing( CPoint &li, CPoint &lj, CPoint &ln, CPoint &lm);
00170 };
00171 
00172 
00173 } // end namespace
00174 
00175 #endif
00176 

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