Ambisonic.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef CSL_AMBISONIC_H
00043 #define CSL_AMBISONIC_H
00044
00045 #include "CSL_Core.h"
00046 #include "CPoint.h"
00047 #include "SpatialSource.h"
00048 #include "SpeakerLayout.h"
00049
00050 #define HOA_MAX_ORDER 2 // maximum order that the CSL HOA will handle
00051
00052 namespace csl {
00053
00056
00057 class AmbisonicOrder {
00058 public:
00059 AmbisonicOrder(unsigned hOrder = 0, unsigned vOrder = 0) : horizontalOrder(hOrder), verticalOrder(vOrder) { };
00060 ~AmbisonicOrder() { };
00061
00062 unsigned horizontalOrder;
00063 unsigned verticalOrder;
00064 bool isUniform;
00065 };
00066
00068
00069 class AmbisonicUnitGenerator : public UnitGenerator {
00070 public:
00071
00072
00073 AmbisonicUnitGenerator(unsigned order = 0);
00074 AmbisonicUnitGenerator(unsigned horder, unsigned vorder);
00075 AmbisonicUnitGenerator(AmbisonicOrder order);
00076 virtual ~AmbisonicUnitGenerator();
00077
00078 AmbisonicOrder order() { return mOrder; };
00079
00080 protected:
00081 void setOrder(AmbisonicOrder order);
00082
00083 AmbisonicOrder mOrder;
00084
00085
00086
00087 unsigned channelsToUniformOrder(const unsigned channels);
00088
00090 unsigned greaterOrder(const AmbisonicOrder order);
00091
00093 unsigned orderToChannels(const AmbisonicOrder order);
00094
00096 unsigned orderToChannels(unsigned order);
00097
00099 unsigned orderToHorizontalChannels(const AmbisonicOrder order);
00100
00102 unsigned orderToVerticalChannels(const AmbisonicOrder order);
00103
00105 void channelIndexer(unsigned *indexArray);
00106
00108 void invChannelIndexer(unsigned *indexArray);
00109
00110 private:
00111
00112 void initOrder();
00113
00114 };
00115
00116
00117
00118
00119
00120
00121
00122
00123 class AmbisonicEncoder : public AmbisonicUnitGenerator {
00124 public:
00125
00126 AmbisonicEncoder();
00127 AmbisonicEncoder(SpatialSource &input, unsigned order = 1);
00128 AmbisonicEncoder(SpatialSource &input, unsigned horder, unsigned vorder);
00129
00130 virtual ~AmbisonicEncoder();
00131
00132 void setInput(SpatialSource &input);
00133 SpatialSource *input() { return (SpatialSource *)mInputPort->mUGen; };
00134
00136 virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException);
00137
00138 protected:
00139 SampleBuffer mWeights;
00140 Port *mInputPort;
00141 void initialize();
00142 };
00143
00145
00146 typedef enum {
00147 kPSEUDOINVERSE = 0,
00148 kPROJECTION
00149 } AmbisonicDecoderMethod;
00150
00152
00153 typedef enum {
00154 kBASIC = 0,
00155 kINPHASE,
00156 kMAXRE
00157 } AmbisonicDecoderFlavour;
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 class AmbisonicDecoder : public AmbisonicUnitGenerator {
00173 public:
00174
00176 AmbisonicDecoder(AmbisonicUnitGenerator &input, SpeakerLayout *layout = SpeakerLayout::defaultSpeakerLayout(), AmbisonicDecoderMethod method = kPROJECTION, AmbisonicDecoderFlavour flavour = kBASIC);
00178 AmbisonicDecoder(UnitGenerator &input, unsigned order, SpeakerLayout *layout = SpeakerLayout::defaultSpeakerLayout(), AmbisonicDecoderMethod method = kPROJECTION, AmbisonicDecoderFlavour flavour = kBASIC);
00180 AmbisonicDecoder(UnitGenerator &input, unsigned hOrder, unsigned vOrder, SpeakerLayout *layout = SpeakerLayout::defaultSpeakerLayout(), AmbisonicDecoderMethod method = kPROJECTION, AmbisonicDecoderFlavour flavour = kBASIC);
00181
00182 ~AmbisonicDecoder();
00183
00185 virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException);
00186
00187 protected:
00188
00189 Port *mInputPort;
00190 float mNumChannelsInv;
00191 int *mIOChannelMap;
00192 SampleBufferVector mDecodingMatrix;
00193 SpeakerLayout *mSpeakerLayout;
00194 AmbisonicDecoderMethod mDecodingMethod;
00195 AmbisonicDecoderFlavour mDecoderFlavour;
00196
00197
00199 void initialize(UnitGenerator &input, AmbisonicDecoderMethod method, AmbisonicDecoderFlavour flavour);
00200
00201 void asProjection();
00202 void asPseudoInverse();
00203
00204 void makeInPhase(unsigned greaterOrder);
00205 void makeMaxRE(unsigned greaterOrder);
00206
00207 void makeTransposedReEncodingMatrix(float **transposeMatrix);
00208
00209 };
00210
00211 }
00212
00213 #endif