VBAP.h

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

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