CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

SpatialAudio.h
Go to the documentation of this file.
1 //
2 // SpatialAudio.h -- Spatializer
3 //
4 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
5 // Created by Jorge Castellanos on 7/23/06. Hacked 8/09 by STP.
6 //
7
8 #ifndef CSL_SPATIAL_AUDIO_H
9 #define CSL_SPATIAL_AUDIO_H
10
11 #include "SpatialPanner.h"
12 #include "DistanceSimulator.h"
13
14 namespace csl {
15
16 /// Panner types
17
18 typedef enum {
19 kAutomatic = 0,
20 kBinaural, ///< HRTF 2-channel panning
21 kVBAP, ///< Vector Base Amplitude Panning
22 kAmbisonic, ///< Full 3D Ambisonics
23 kSimple, ///< Simple panning/filtering spatializer
24 kWFS ///< Wave Field Synthesis
25 } PannerType;
26
27 /// Container class that simplifies the spatial audio interface.
28 /// This layer hides most of the inner-working of audio spatialization,
29 /// providing a simple interface for sound placement in a space.
30
31 class Spatializer : public UnitGenerator, public Observer {
32 public:
33 Spatializer(PannerType panMode = kAutomatic, SpeakerLayout *speakerLayout = SpeakerLayout::defaultSpeakerLayout());
34 ~Spatializer();
35
36 void addSource(SpatialSource &s); ///< Add a sound souce to the list of inputs to be processed.
37 void removeSource(SpatialSource &s); ///< Remove a Sound Source.
38
39 unsigned numSources() { return mPanner->numSources(); }; ///< number of active inputs.
40
41 void setPanningMode(PannerType panType);
42
43 virtual void update(void *arg); ///< called when the speaker layout changes, so panners update precalculated data.
44
45 virtual void nextBuffer(Buffer &outputBuffer /*, unsigned outBufNum */) throw (CException); ///< fill the buffer with data :-)
46
47 private:
48 SpatialPanner *mPanner;
49 /// a map between a source passed/key and a the corresponding distance
50 /// simulator (used for removing sources)
51 map <SpatialSource *, DistanceSimulator *> mInputsHashMap;
52 /// If null, it will use the default layout by calling
53 /// SpeakerLayout::defaultSpeakerLayout();
54 SpeakerLayout *mSpeakerLayout;
55 PannerType mType;
56 };
57
58
59 class Auralizer : public Spatializer {
60 public:
61 Auralizer() { };
62 ~Auralizer() { };
63
64
65 private:
66
67 // SHOULD REVERB BE PART OF THE AURALIZER? OR THE SPATIALIZER?
68 // TO AN EXTENT, ADDING REVERB IS ALREADY A VERY COARSE ATTEMPT TO SIMULATE A SPACE, MAKING IT PART OF AURALIZER
69 // BUT A SPATIALIZER IS ALSO SUPPOSED TO PLACE A SOUND IN A SPACE, THUS THE NAME.
70 // ADDING ROOM SIZE TO A SPAIZALIZER TO CONTROL REVERB AMOUNT WOULD GET INTO THE INTERFAXE OF AURALIZER
71 // UNLESS NOT SPECIFIED? NAHH!
72
73 /*
74 For now use Freeverb as the reverberator. In the future, a base reverb class should exist,
75 allowing to specify the type of reverb. Although this would call for a subclass of Auralizer,
76 rather than using setter functions, where by default it gets constructed to use Freverb, but
77 A subclass could just place any other reverb.
78 */
79
80 // Freeverb *mGlobalReverb
81
82 /*
83 The reverb settings would be set depending on the room specified.
84 The "Room" Class should have a method for returning volume, as well as average absorption
85 (in order to set the tail properties, as well as calculating reflections.
86
87 The calculation of early reflections should also share a common base class, so that subclasses
88 can initialize the "geometer" to any desired one."
89 */
90
91
92 };
93
94 ///*
95 //I GUESS I'VE FOUND A SOLUTION TO THE SPATIALIZER "CONTAINER".
96 //FIRST, IT WONT BE A SPATIALIZER, BUT THE AURALIZER WILL COME A LEVEL DOWN, AND BE ITSELF THE SPATIALIZER.
97 //THE DIFFERENCE IS THAT BY DEFAULT IT WON'T DEAL WITH ROOM MODELS. (IT COULD POSSIBLY BE A SUBCLASS OF SPATIALIZER IF THE "ECHO" INFO
98 //BECOMES TO COMPLICATED TO HAVE FOR EVERY SPATIALIZER.
99 //
100 //HERE IT GOES:
101 //WHEN ADDING A SOURCE TO THE SPATIALIZER, THIS WILL MAKE A DISTANCE_SIMULATOR AND PASS IT THE ADDED SOURCE. THEN, IT'LL CALL "ADD SOURCE" OF THE
102 //PANNER AND WILL PASS IT THE NEW CREATED DISTANCE SIMULATOR.
103 //IN THE NEXT BUFFER OF THE SPATIALIZER, THIS WILL CALL NEXT BUFFER OF THE PANNER, WHICH IN TURN WILL CALL NEXT BUFFER OF EACH SOURCE, MEANING EACH DISTANCE SIMULATOR
104 //WHICH IN TURN IT'LL CAL THE NEXT BUFFER OF EACH PASSED SOURCE.
105 //
106 //
107 //
108 //
109 //*/
110
111 class SpeakerLayoutExpert {
112 public:
113 SpeakerLayoutExpert() { };
114 ~SpeakerLayoutExpert() { };
115
116 static PannerType findPannerFromLayout(SpeakerLayout *layout = SpeakerLayout::defaultSpeakerLayout());
117
118 };
119
120 } // end of nameespace
121
122 #endif