nomlib
Loading...
Searching...
No Matches
ALAudioDeviceCaps.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014, 2015, 2016 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_AUDIO_AL_DEVICE_CAPS_HPP
30#define NOMLIB_AUDIO_AL_DEVICE_CAPS_HPP
31
32#include "nomlib/config.hpp"
33#include "nomlib/math/Point3.hpp"
34#include "nomlib/audio/IOAudioEngine.hpp"
35
36// FIXME(jeff): enums
37#include "nomlib/audio/AL/SoundSource.hpp"
38
39// Forward declarations
40struct ALCdevice_struct;
41struct ALCcontext_struct;
42
43namespace nom {
44namespace audio {
45
46// Forward declarations
47struct SoundBuffer;
48// struct AudioSpec;
49struct ALAudioDevice;
50
51// Function declarations
52
53void free_buffer(uint32 buffer_id);
54void free_source(uint32 buffer_id);
55
56uint32 buffer_id(const SoundBuffer* target);
57uint32 source_id(const SoundBuffer* target);
58
65uint32 next_buffer_id();
66
75uint32* next_buffer_id(uint32 num_buffers);
76
83uint32 next_source_id();
84
93uint32* next_source_id(uint32 num_sources);
94
95// TODO(jeff): Add const to getters!
96class ALAudioEngine: public IOAudioEngine
97{
98 public:
99 ALAudioEngine();
100 virtual ~ALAudioEngine();
101
102 ALAudioEngine(ALAudioDevice* driver);
103 virtual void init(void* driver) override;
104
105 virtual bool valid() const override;
106
107 virtual uint32 caps() const override;
108 virtual void set_cap(uint32 format) override;
109
110 virtual bool connected() const override;
111
113 virtual
114 uint32 channel_format(uint32 num_channels, uint32 channel_format) override;
115
116 virtual bool valid_buffer(SoundBuffer* target) override;
117 virtual bool valid_source(SoundBuffer* target) override;
118
119 virtual uint32 state(SoundBuffer* target) override;
120 virtual real32 pitch(SoundBuffer* target) override;
121
122 virtual real32 volume() const override;
123 virtual Point3f position() const override;
124
125 virtual real32 volume(SoundBuffer* target) const override;
126 virtual real32 min_volume(SoundBuffer* target) override;
127 virtual real32 max_volume(SoundBuffer* target) override;
128
129 virtual Point3f velocity(SoundBuffer* target) override;
130 virtual Point3f position(SoundBuffer* target) override;
131 virtual real32 playback_position(SoundBuffer* target) override;
132 virtual real32 playback_samples(SoundBuffer* target) override;
133
134 // virtual void set_state(SoundBuffer* target, uint32 state) override;
135
136 virtual void set_volume(real32 gain) override;
137 virtual void set_position(const Point3f& p) override;
138
139 virtual void set_min_volume(SoundBuffer* target, real32 gain) override;
140 virtual void set_max_volume(SoundBuffer* target, real32 gain) override;
141 virtual void set_volume(SoundBuffer* target, real32 gain) override;
142
143 virtual void set_velocity(SoundBuffer* target, const Point3f& v) override;
144 virtual void set_position(SoundBuffer* target, const Point3f& p) override;
145 virtual void set_pitch(SoundBuffer* target, real32 pitch) override;
146 virtual void set_playback_position(SoundBuffer* target, real32 offset_seconds) override;
147 virtual void play(SoundBuffer* target) override;
148 virtual void stop(SoundBuffer* target) override;
149 virtual void pause(SoundBuffer* target) override;
150 virtual void resume(SoundBuffer* target) override;
151
152 virtual bool push_buffer(SoundBuffer* target) override;
153 virtual bool queue_buffer(SoundBuffer* target) override;
154
155 // IMPORTANT(jeff): The audio hardware capabilities, maximum sources,
156 // limitations and so on are subject to change anytime that we touch the
157 // audio context state!
158 virtual void suspend() override;
159 virtual void resume() override;
160 virtual void close() override;
161
162 virtual void free_buffer(SoundBuffer* target) override;
163
164 private:
165 bool fill_buffer(SoundBuffer* target);
166
167 virtual void close_context();
168 virtual void close_device();
169
170 ALAudioDevice* impl_ = nullptr;
171};
172
173} // namespace audio
174} // namespace nom
175
176#endif // include guard defined
virtual uint32 channel_format(uint32 num_channels, uint32 channel_format) override
Find a suitable data format for OpenAL.