Wayverb
full_run.h
1 #pragma once
2 
3 #include "combined/capsule_base.h"
4 #include "combined/engine.h"
5 #include "combined/forwarding_call.h"
6 
7 #include <experimental/optional>
8 
9 namespace wayverb {
10 namespace combined {
11 
13 
14 class postprocessing_engine final {
15 public:
16  postprocessing_engine(const core::compute_context& compute_context,
17  const core::gpu_scene_data& scene_data,
18  const glm::vec3& source,
19  const glm::vec3& receiver,
20  const core::environment& environment,
22  std::unique_ptr<waveguide_base> waveguide);
23 
25  postprocessing_engine(postprocessing_engine&&) noexcept = delete;
26 
27  postprocessing_engine& operator=(const postprocessing_engine&) = delete;
28  postprocessing_engine& operator=(postprocessing_engine&&) noexcept = delete;
29 
30  template <typename It>
31  std::experimental::optional<
32  util::aligned::vector<util::aligned::vector<float>>>
33  run(It b_capsules,
34  It e_capsules,
35  double sample_rate,
36  const std::atomic_bool& keep_going) {
37  // Only add engine listeners if things are listening to this object.
38 
39  engine_state_changed::scoped_connection state;
40  if (!engine_state_changed_.empty()) {
41  state = engine_state_changed::scoped_connection{
42  engine_.connect_engine_state_changed(
43  make_forwarding_call(engine_state_changed_))};
44  }
45 
46  waveguide_node_pressures_changed::scoped_connection pressures;
47  if (!waveguide_node_pressures_changed_.empty()) {
48  pressures = waveguide_node_pressures_changed::scoped_connection{
49  engine_.connect_waveguide_node_pressures_changed(
50  make_forwarding_call(
51  waveguide_node_pressures_changed_))};
52  }
53 
55  if (!raytracer_reflections_generated_.empty()) {
57  engine_.connect_raytracer_reflections_generated(
58  make_forwarding_call(
59  raytracer_reflections_generated_))};
60  }
61 
62  // Start running.
63 
64  const auto intermediate = engine_.run(keep_going);
65 
66  if (intermediate == nullptr) {
67  return std::experimental::nullopt;
68  }
69 
70  engine_state_changed_(state::postprocessing, 1.0);
71 
72  util::aligned::vector<util::aligned::vector<float>> channels;
73  for (auto it = b_capsules; it != e_capsules && keep_going; ++it) {
74  channels.emplace_back(
75  (*it)->postprocess(*intermediate, sample_rate));
76  }
77 
78  if (!keep_going) {
79  return std::experimental::nullopt;
80  }
81 
82  return channels;
83  }
84 
85  // notifications
86 
92 
93  engine_state_changed::connection connect_engine_state_changed(
94  engine_state_changed::callback_type callback);
95 
96  waveguide_node_pressures_changed::connection
97  connect_waveguide_node_pressures_changed(
98  waveguide_node_pressures_changed::callback_type callback);
99 
101  connect_raytracer_reflections_generated(
102  raytracer_reflections_generated::callback_type callback);
103 
104  // get contents
105 
106  const waveguide::voxels_and_mesh& get_voxels_and_mesh() const;
107 
108 private:
109  engine engine_;
110 
111  engine_state_changed engine_state_changed_;
112  waveguide_node_pressures_changed waveguide_node_pressures_changed_;
113  raytracer_reflections_generated raytracer_reflections_generated_;
114 };
115 
116 } // namespace combined
117 } // namespace wayverb
Definition: scene_data.h:13
util::event< state, double > engine_state_changed
Args: Current engine state, progress within state.
Definition: engine.h:108
This is badly designed. Really, the capsules should be polymorphic.
Definition: engine.h:67
Definition: engine.h:91
Definition: pressure.h:22
Definition: environment.h:6
Definition: capsule_base.h:9
util::event< util::aligned::vector< util::aligned::vector< raytracer::reflection >>, glm::vec3 > raytracer_reflections_generated
Args: Current reflections, source position.
Definition: engine.h:117
util::event< util::aligned::vector< float >, double > waveguide_node_pressures_changed
Args: Current node pressures, total distanced travelled by sound wave.
Definition: engine.h:112
Definition: event.h:76
invariant: device is a valid device for the context
Definition: common.h:13
Definition: event.h:28
Similar to engine but immediately runs the postprocessing step.
Definition: full_run.h:14
Definition: simulation_parameters.h:9