MOS
renderer.hpp
1 #pragma once
2 
3 #include <memory>
4 #include <thread>
5 #include <unordered_map>
6 
7 #include <mos/al/buffer.hpp>
8 #include <mos/al/filter.hpp>
9 #include <mos/al/source.hpp>
10 
11 #include <AL/al.h>
12 #include <AL/alc.h>
13 #include <AL/alext.h>
14 #include <AL/efx-presets.h>
15 
16 #include <mos/apu/scene.hpp>
17 #include <mos/apu/sound.hpp>
18 #include <mos/aud/sound_streams.hpp>
19 #include <mos/aud/sounds.hpp>
20 
21 namespace mos::aud {
22 class Sound_stream;
23 class Sound;
24 class Listener;
25 class Scene;
26 } // namespace mos::aud
27 
28 namespace mos::apu {
29 class Scene;
30 }
31 
32 namespace mos::al {
33 
35 class Renderer final {
36 public:
37  Renderer();
38  ~Renderer();
39 
40  Renderer(const Renderer &renderer) = delete;
41  Renderer(const Renderer &&renderer) = delete;
42 
43  Renderer &operator=(const Renderer &renderer) = delete;
44  Renderer &operator=(const Renderer &&renderer) = delete;
45 
47  static auto listener() -> aud::Listener;
48 
49  auto load(const aud::Sounds &sounds) -> std::vector<mos::apu::Sound>;
50 
51  auto load(const aud::Sound_streams &sound_streams)
52  -> std::vector<mos::apu::Sound_stream>;
53 
55  auto render(const apu::Scene &scene, const float dt) -> void;
56 
58  auto clear() -> void;
59 
60 private:
62  static auto listener(const aud::Listener &listener) -> void;
63 
65  auto render_sound_stream(const apu::Sound_stream &sound_stream,
66  const float dt) -> void;
67 
69  auto render_sound(const apu::Sound &sound, const float dt) -> void;
70 
71  ALCdevice *device_;
72  ALCcontext *context_;
73 
74  EFXEAXREVERBPROPERTIES reverb_properties;
75  ALuint reverb_effect{0};
76  ALuint reverb_slot{0};
77  ALuint lowpass_filter1{0};
78  ALuint lowpass_filter2{0};
79 
80  using SourcePair = std::pair<unsigned int, ALuint>;
81  using BufferPair = std::pair<unsigned int, ALuint>;
82  using Sources = std::unordered_map<unsigned int, Source>;
83  using Buffers = std::unordered_map<unsigned int, Buffer>;
84  using Filters = std::unordered_map<unsigned int, Filter>;
85 
86  Sources sources_;
87  Buffers buffers_;
88  Filters filters_;
89 };
90 } // namespace mos::al
Definition: buffer.hpp:13
Definition: sound.hpp:14
Where the audio system listens from.
Definition: listener.hpp:8
OpenAL audio renderer.
Definition: renderer.hpp:35
Audio scene with listener and audio sources.
Definition: scene.hpp:11
Definition: renderer.hpp:28
Streamed audio from file, combined with a source living on the APU.
Definition: sound_stream.hpp:10
Definition: filter.hpp:13