SAL
A C++ library for spatial audio.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
microphone.h
Go to the documentation of this file.
1 /*
2  microphone.h
3  Spatial Audio Library (SAL)
4  Copyright (c) 2011, Enzo De Sena
5  All rights reserved.
6 
7  Authors: Enzo De Sena, enzodesena@gmail.com
8 
9  */
10 
11 
12 #ifndef SAL_MICROPHONE_H
13 #define SAL_MICROPHONE_H
14 
15 #include "point.h"
16 #include "source.h"
17 #include "quaternion.h"
18 #include <assert.h>
19 #include <map>
20 #include "salconstants.h"
21 #include "audiobuffer.h"
22 
23 namespace sal {
24 
25 class Microphone {
26 public:
49  Microphone(mcl::Point position,
50  mcl::Quaternion orientation = mcl::Quaternion::Identity());
51 
53  mcl::Point position() const noexcept;
54 
56  virtual void SetPosition(const mcl::Point& position) noexcept;
57 
59  mcl::Quaternion orientation() const noexcept;
60 
62  virtual void SetOrientation(const mcl::Quaternion& orientation) noexcept;
63 
65  void SetHandedness(const mcl::Handedness handedness) noexcept;
66 
74  void AddPlaneWave(const MonoBuffer& signal,
75  const mcl::Point& point,
76  Buffer& output_buffer) noexcept;
77 
78  void AddPlaneWave(const Sample* input_data,
79  const Int num_samples,
80  const mcl::Point& point,
81  Buffer& output_buffer) noexcept;
82 
83  void AddPlaneWave(const Sample input_sample,
84  const mcl::Point& point,
85  Buffer& output_buffer) noexcept;
86 
87 
97  void AddPlaneWave(const MonoBuffer& input_buffer,
98  const mcl::Point& point,
99  const Int wave_id,
100  Buffer& output_buffer) noexcept;
101 
102  void AddPlaneWave(const Sample input_sample,
103  const mcl::Point& point,
104  const Int wave_id,
105  Buffer& output_buffer) noexcept;
106 
107  virtual void AddPlaneWave(const Sample* input_data,
108  const Int num_samples,
109  const mcl::Point& point,
110  const Int wave_id,
111  Buffer& output_buffer) noexcept;
112 
113  virtual bool IsCoincident() const noexcept = 0;
114 
115  virtual Int num_channels() const noexcept = 0;
116 
117  virtual bool IsOmni() const noexcept { return false; }
118 
120  mcl::Point GetRelativePoint(const mcl::Point& point) const noexcept;
121 
123  virtual void Reset() noexcept {}
124 
125  static bool Test();
126 
127  virtual ~Microphone() {}
128 
129 
130  virtual void AddPlaneWaveRelative(const MonoBuffer& signal,
131  const mcl::Point& point,
132  const Int wave_id,
133  Buffer& output_buffer) noexcept;
134 
148  virtual void AddPlaneWaveRelative(const Sample* input_data,
149  const Int num_samples,
150  const mcl::Point& point,
151  const Int wave_id,
152  Buffer& output_buffer) noexcept = 0;
153 
154 private:
155  mcl::Triplet position_;
156  mcl::Quaternion orientation_;
157 
158  friend class MicrophoneArray;
159 protected:
160  mcl::Handedness handedness_;
161 };
162 
163 class StereoMicrophone : public Microphone {
164 public:
165  StereoMicrophone(mcl::Point position, mcl::Quaternion orientation) :
166  Microphone(position, orientation) {}
167 
168  virtual ~StereoMicrophone() {}
169 };
170 
171 } // namespace sal
172 
173 #endif