SAL
A C++ library for spatial audio.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tdbem.h
Go to the documentation of this file.
1 /*
2  Spatial Audio Library (SAL)
3  Copyright (c) 2013-2018, Enzo De Sena
4  All rights reserved.
5 
6  Authors: Enzo De Sena, enzodesena@gmail.com
7  */
8 
9 #ifndef SAL_TDBEM_H
10 #define SAL_TDBEM_H
11 
12 
13 #include "cuboidroom.h"
14 #include "source.h"
15 #include "microphone.h"
16 #include "delayfilter.h"
17 
18 namespace sal {
19 
20 class TdBem {
21 private:
22  Room* const room_;
23  sal::Source* const source_;
24  sal::Microphone* const microphone_;
25 
26  sal::Time sampling_frequency_;
27  sal::Length spatial_sampling_period_;
28  sal::Sample specific_acoustic_impedance_;
29 
30  std::vector<sal::Sample> rir_;
31 
32 
33  std::vector<mcl::Point> points_; // Stores points on the bounduary
34  sal::Int num_elements_;
35  std::vector<mcl::Point> normal_vectors_;
36  std::vector<std::vector<sal::Length> > distances_;
37  std::vector<std::vector<sal::Sample> > weights_current_;
38  std::vector<std::vector<sal::Sample> > weights_previous_;
39 
40  std::vector<sal::Length> distances_mic_;
41  std::vector<sal::Sample> weights_mic_current_;
42  std::vector<sal::Sample> weights_mic_previous_;
43  std::vector<sal::Sample> weights_source_;
44 
45  std::vector<sal::Length> distances_source_;
46  sal::Length distance_los_;
47 
48  std::vector<sal::DelayFilter> pressures_;
49 
50  sal::DelayFilter source_delay_line_;
51 
52  bool log_;
53  std::string log_file_name_;
54 
55  void CalculatePoints();
56 
57  static sal::Sample
58  CalculateWeightCurrent(sal::Sample dr_dn,
59  sal::Length distance,
60  sal::Length sound_speed,
61  sal::Time sampling_frequency,
62  sal::Length spatial_sampling_period,
63  sal::Sample specific_acoustic_impedance);
64 
65 
66  static sal::Sample
67  CalculateWeightPrevious(sal::Sample dr_dn,
68  sal::Length distance,
69  sal::Length sound_speed,
70  sal::Time sampling_frequency,
71  sal::Length spatial_sampling_period,
72  sal::Sample specific_acoustic_impedance);
73 
74  static sal::Sample CalculateDrDn(mcl::Point point_x,
75  mcl::Point point_y,
76  mcl::Point normal_y);
77 
78 public:
79  TdBem(Room* const room,
80  sal::Source* const source,
81  sal::Microphone* const microphone,
82  const sal::Time sampling_frequency,
83  const sal::Length spatial_sampling_period,
84  const sal::Sample specific_acoustic_impedance);
85 
86  void WriteOutPoints(const std::string file_name);
87 
88  void Run(const MonoBuffer& input_buffer, Buffer& output_buffer);
89 
90  sal::Signal rir() const { return rir_; }
91 
92  void Log(std::string file_name) {
93  log_ = true;
94  log_file_name_ = file_name;
95  }
96 
97  static bool SimulationTime();
98 };
99 
100 } // namespace sal
101 
102 
103 #endif