CSL 5.2

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

- File List
- File Members

SpatialSource.h
Go to the documentation of this file.
1 //
2 // SpeakerSource.h -- Spatial Sound Source
3 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 // Created by Jorge Castellanos on 6/16/06. Hacked 8/09 by STP.
5 //
6 /// @todo Make a position object (possibly inherits from CPoint) that keeps both polar and cartesian values.
7
8 #ifndef SOUND_SOURCE_H
9 #define SOUND_SOURCE_H
10
11 #include "CSL_Core.h"
12 #include "CPoint.h"
13
14 namespace csl {
15
16 //class SpatialProperties {
17 //public:
18 // SpatialProperties() : mPosition(0.f), mRoot(NULL), mPositionChanged(true) { };
19 // ~SpatialProperties() { };
20 //
21 // float mPosition;
22 // UnitGenerator *mRoot;
23 // bool mPositionChanged; //< true if this source's position has changed
24 //
25 //};
26
27 /// Temp Spatial Sound Source
28
29 class SpatialSource : public UnitGenerator, public virtual Scalable {
30 public:
31 SpatialSource(); ///< constructors
32 SpatialSource(UnitGenerator &input, float azi = 0.0, float ele = 0.0, float dist = 1.0);
33 virtual ~SpatialSource();
34 /// Set the sound source position in cartesian coordinates.
35 virtual void setPosition(CPoint pos);
36 virtual void setPosition(float x = 0., float y = 0., float z = 0.);
37 virtual void setPosition(double x = 0., double y = 0., double z = 0.);
38
39 /// Set the sound source position in spherical coordinates (degrees).
40 virtual void setPosition(char s, float azi = 0, float ele = 0, float dist = 1.0) ;
41 virtual void setPosition(char s, double azi = 0, double ele = 0, double dist = 1.0) ;
42 CPoint & getPosition() { return (* mPosition); };
43
44 #ifdef DIRECTIONAL_SOURCES
45 /// Specify what direction is the object facing
46 void setOrientation(float horizontalAngle, float verticalAngle);
47 /// This is the actual sound radiation pattern of the sound object.
48 void setDirectivity(float innerConeAngle, float outerConeAngle);
49 /// kType of radiation.
50 #endif
51
52 void setAzimuth(float val) { mPosition->setAzimuth(val); }; ///< Sets the horizontal angle.
53 void setElevation(float val) { mPosition->setElevation(val); }; ///< Sets the angle of elevation.
54 void setDistance(float val) { mPosition->setMagnitude(val); }; ///< Sets the distance from the center.
55
56 float azimuth() { return mPosition->theta(); }; ///< Returns the horizontal angle.
57 float elevation() { return mPosition->ele(); }; ///< Returns the angle of elevation.
58 float distance() { return mPosition->r(); }; ///< Returns the distance from the center.
59
60 CPoint *position(unsigned channelNum = 0);
61
62 /// Returns whether the sound source position changed since last block call.
63 virtual bool positionChanged() { return mPositionChanged; };
64
65 virtual void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException);
66 virtual void nextBuffer(Buffer & outputBuffer) throw (CException);
67
68 void dump();
69
70 protected:
71 CPoint * mPosition; ///< source position
72 bool mPositionChanged; ///< true if this source's position has changed recently
73
74 #ifdef DIRECTIONAL_SOURCES
75 float mInnerCone;
76 float mOuterCone;
77 float mHorizontalOrientation;
78 float mVerticalOrientation;
79 #endif
80
81 };
82
83 /*
84 DESIGN THOUGHTS:
85 Possibly Source could be called PositionableSource and be the base class of other Spatial Sources.
86 For example, a subclass could include directivity and radiation pattern, wich is less common than position
87 Also, different ways of sound radiation could be implemented by subclasses.
88
89 A second option is to specify sound radiation directly to the object that does the actual computation.
90 This way the different processors could accept their very particular way of doing things.
91 This approach would break with the concept of having the sound source KNOW its own characteristics.
92 Cons: not only the processors of directivity, but also procesors of room acoustics would make use of
93 such info, so user would have to specify it twice (this could be a feature, as it would allow different
94 types, one simpler for reflections, and a possibly complex one for the direct sound.
95
96 Maybe the answer is that sound radiation is not just a record class, but it responds with an actual value
97 (or filter?) when asked for the value at x angle. That way the different types of pattern would know how to
98 do their shit, but mantaining a common interface and return type, so it can be processed.
99
100 Or.. should I just decide for one method and stick to it? That would defeat the purpose of an extensible
101 framework made to be used for research, as well as for making content.
102
103 */
104 }
105
106 #endif