SAL
A C++ library for spatial audio.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
freefieldsimulation.h
Go to the documentation of this file.
1 /*
2  simulation.h
3  Spatial Audio Library (SAL)
4  Copyright (c) 2012, Enzo De Sena
5  All rights reserved.
6 
7  This class calculates the signals recorded by N microphones due to M acoustic
8  sources in free-field.
9 
10  Authors: Enzo De Sena, enzodesena@gmail.com
11 
12  */
13 
14 #ifndef SAL_SIMULATION_H
15 #define SAL_SIMULATION_H
16 
17 #define DEFAULT_MAX_BUFFER 10
18 
19 #include "source.h"
20 #include "saltypes.h"
21 #include "point.h"
22 #include "microphone.h"
23 #include "propagationline.h"
24 #include <vector>
25 #include "salconstants.h"
26 
27 namespace sal {
28 
29 class FreeFieldSim {
30 public:
31  FreeFieldSim(std::vector<Microphone*> microphones,
32  std::vector<Source*> sources,
33  const Time sampling_frequency,
34  const Length sound_speed);
35 
36  FreeFieldSim(Microphone* microphones,
37  std::vector<Source*> sources,
38  const Time sampling_frequency,
39  const Length sound_speed);
40 
41  FreeFieldSim(std::vector<Microphone*> microphones,
42  Source* sources,
43  const Time sampling_frequency,
44  const Length sound_speed);
45 
46  FreeFieldSim(Microphone* microphones,
47  Source* sources,
48  const Time sampling_frequency,
49  const Length sound_speed);
50 
51  void Init(std::vector<Microphone*> microphones,
52  std::vector<Source*> sources,
53  const Time sampling_frequency,
54  const Length sound_speed);
55 
56  void Run(std::vector<MonoBuffer*> input_buffers,
57  const Int num_output_samples,
58  std::vector<Buffer*> output_buffers);
59 
60  void AllocateTempBuffers(const Int num_samples);
61  void DeallocateTempBuffers();
62 
63  ~FreeFieldSim();
64 
65  static bool Test();
66 private:
67 
68 
69  void Tick();
70 
72  static Length MinimumDistance(const std::vector<Microphone*>& microphones,
73  const std::vector<Source*>& sources);
74 
76  static Length MaximumDistance(const std::vector<Microphone*>& microphones,
77  const std::vector<Source*>& sources);
78 
79  static std::vector<Length>
80  AllDistances(const std::vector<Microphone*>& microphones,
81  const std::vector<Source*>& sources);
82 
83 
84 
85  std::vector<std::vector<PropagationLine*> > propagation_lines_;
86  std::vector<std::vector<MonoBuffer*> > temp_buffers_;
87 
88  std::vector<Microphone*> microphones_;
89  std::vector<Source*> sources_;
90  Time sampling_frequency_;
91  Speed sound_speed_;
92 };
93 
94 } // namespace sal
95 
96 #endif