nomlib
Loading...
Searching...
No Matches
ALAudioRenderer.hpp
1#pragma once
2
3#include "export.hpp"
4#include "nomlib/types.hpp"
5#include "nomlib/audio/SoundFile.hpp"
6#include "nomlib/math/Matrix.hpp"
7#include "nomlib/audio/IAudioDevice.hpp"
8#include "nomlib/audio/ALAudioContext.hpp"
9#include "nomlib/audio/ISoundSource.hpp"
10#include "nomlib/audio/AL/OpenAL.hpp"
11
12#include <vector>
13
14class Matrix4;
15
16namespace nom {
17namespace audio {
18
19// Forward declarations
20class ISoundSource;
21class Sound;
22struct OALSource;
23//class RenderWindow;
24
25using SoundSourceIterator = std::vector<ISoundSource*>::iterator;
26
27// SoundSystem impl
28class NOM_EXPORT ALAudioRenderer: public IAudioDevice
29{
30 public:
31 // Default constructor
32 ALAudioRenderer();
33 ALAudioRenderer(nom::uint32 channels);
34
35 virtual ~ALAudioRenderer();
36 virtual void release() override;
37
38 // used by ALAudioSource::update
39 // audio sources attached by this method are part of the emitters
40 // container (managed by this class)
41 // (see ALAudioRenderer::update).
42 virtual void add_source(ISoundSource* node) override;
43
44 // audio sources attached by this method are part of the temporary
45 // emitters container (managed by this class).
46 virtual void play_sound(Sound* s) override;
47
48 // audio sources attached by this method are part of the temporary
49 // emitters container (managed by this class).
50 virtual void play_sound(Sound* s, const nom::Point3f& pos) override;
51
52 // audio sources attached by this method are part of the temporary
53 // emitters container (managed by this class).
54 virtual void play_sound(Sound* s, SoundPriority p) override;
55
56 // audio sources attached by this method are part of the temporary
57 // emitters container (managed by this class).
58 virtual void play_sound(Sound* s, nom::real32 gain) override;
59
60 //virtual void set_listener(const Matrix4& node) override;
61
62 // responsible for updating emitters && temporary emitters and must be
63 // called inside the main game loop
64 virtual void update(nom::real32 delta) override;
65
66 // Return a free source (from the number of channels specified at init)
67 OALSource* source();
68
69 virtual void set_master_volume(nom::real32 gain) override;
70 private:
71 //void init_audio(int32 channels);
72 void initialize(nom::uint32 channels);
73 void update_listener();
74 //void update_temps(real32 delta);
75 //void update_internal(real32 delta);
76 void cull_nodes();
77 void detach_sources(SoundSourceIterator from, SoundSourceIterator to);
78 void attach_sources(SoundSourceIterator from, SoundSourceIterator to);
79
80 // Relocate to ALAudioContext or IAudioContext?
81 Matrix4 listener_;
82 // OpenAL audio sources that are in use -- this can be greater than the
83 // number of channels specified at init time
84 std::vector<OALSource*> sources_;
85 // container for audio source emitters that are expected to be around for
86 // some time, i.e.: streaming sources.
87 std::vector<ISoundSource*> emitters_;
88 // container for audio source emitters that are not expected to be around
89 // but for a brief time.
90 std::vector<ISoundSource*> temporary_emitters_;
91
92 ALCdevice* impl_;
93 ALAudioContext* ctx_;
94};
95
96NOM_EXPORT bool extension_available(const char* key);
97NOM_EXPORT int /*ALenum*/ enum_available(const char* key);
98NOM_EXPORT void* device_function(const ALCchar* fn);
99
100// Convert from nomlib's native AudioFormat enumeration to
101// the equivalent OpenAL format.
102//
103// AudioFormat -> AL_FORMAT_XXX
104// num_channels == 1 == AL_FORMAT_MONO
105// num_channels == 2 == AUDIO_FORMAT_AL_FORMAT_STEREO
106// ...
107// ?? Rename to openal_format
108NOM_EXPORT ALenum channel_format(nom::uint32 num_channels, nom::audio::AudioFormat channel_format);
109
110// Convert from nomlib's native AudioCaps enumeration to
111// the equivalent OpenAL format.
112//
113// CAPS_FORMAT_MONO_S8 -> AL_FORMAT_MONO8
114//
115//ALenum channel_format(uint32 num_channels, AudioCaps channel_format);
116
117} // namespace audio
118} // namespace nom