nomlib
Loading...
Searching...
No Matches
SoundSource.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_AL_SOUNDSOURCE_HEADERS
30#define NOMLIB_AL_SOUNDSOURCE_HEADERS
31
32#include <memory>
33#include <algorithm>
34
35#include "nomlib/config.hpp"
36#include "nomlib/math/Point3.hpp"
37
38namespace nom {
39namespace audio {
40
41// Forward declarations
42class IOAudioEngine;
43struct SoundBuffer;
45struct SoundInfo;
46
48enum AudioState
49{
50 AUDIO_STATE_INITIAL = 0,
51 AUDIO_STATE_STOPPED,
52 AUDIO_STATE_PAUSED,
53 AUDIO_STATE_PLAYING,
54 AUDIO_STATE_STREAMING,
55
56 // TODO: Bit mask..?
57 AUDIO_STATE_LOOPING
58};
59
60enum AudioSourceType
61{
62 AUDIO_TYPE_UNKNOWN = 0,
63 AUDIO_TYPE_STATIC,
64 AUDIO_TYPE_STREAMING,
65};
66
67// buffer creation
68
69uint32 channel_format(uint32 num_channels, uint32 channel_format,
70 IOAudioEngine* target);
71
72bool write_info(SoundBuffer* buffer, const SoundInfo& metadata);
73
74void* create_samples(nom::size_type alloc_bytes, uint32 num_channels,
75 uint32 channel_format);
76
77void free_samples(uint32 channel_format, void* data);
78
79SoundBuffer* create_buffer_memory();
80
82create_buffer_memory(nom::size_type total_sample_bytes, uint32 num_channels,
83 uint32 channel_format);
84
86create_buffer(void* samples, const SoundInfo& metadata, IOAudioEngine* target);
87
88// TODO(jeff): Restructure this function..? Perhaps split it up.
90create_buffer(const std::string& filename, ISoundFileReader* fp,
91 IOAudioEngine* target);
92
94create_buffer(const std::string& filename, IOAudioEngine* target);
95
96bool valid_buffer(SoundBuffer* buffer, IOAudioEngine* target);
97bool valid_source(SoundBuffer* buffer, IOAudioEngine* target);
98
99SoundInfo info(SoundBuffer* buffer);
100
101void free_buffer(SoundBuffer* buffer, IOAudioEngine* target);
102
103// audio control
104
105// void queue(SoundBuffer* buffer, IOAudioEngine* target);
106
107void play(SoundBuffer* buffer, IOAudioEngine* target);
108
109void stop(SoundBuffer* buffer, IOAudioEngine* target);
110
111void pause(SoundBuffer* buffer, IOAudioEngine* target);
112
113void resume(SoundBuffer* buffer, IOAudioEngine* target);
114
115uint32 state(SoundBuffer* buffer, IOAudioEngine* target);
116
117real32 pitch(SoundBuffer* buffer, IOAudioEngine* target);
118
119Point3f
120position(SoundBuffer* buffer, IOAudioEngine* target);
121
122Point3f
123velocity(SoundBuffer* buffer, IOAudioEngine* target);
124
128real32
129volume(IOAudioEngine* target);
130
131Point3f
132position(IOAudioEngine* target);
133
137real32
138volume(SoundBuffer* buffer, IOAudioEngine* target);
139
143real32
144min_volume(SoundBuffer* buffer, IOAudioEngine* target);
145
149real32
150max_volume(SoundBuffer* buffer, IOAudioEngine* target);
151
152real32
153playback_position(SoundBuffer* buffer, IOAudioEngine* target);
154
155real32
156playback_samples(SoundBuffer* buffer, IOAudioEngine* target);
157
158// TODO(jeff): Update me
159SoundBuffer* clone_buffer(const SoundBuffer* rhs);
160
161// void
162// set_state(SoundBuffer* buffer, IOAudioEngine* target, uint32 state);
163
170void set_volume(real32 gain, IOAudioEngine* target);
171
172void
173set_volume(SoundBuffer* buffer, IOAudioEngine* target, real32 gain);
174
178void set_min_volume(SoundBuffer* buffer, IOAudioEngine* target, real32 gain);
179
183void set_max_volume(SoundBuffer* buffer, IOAudioEngine* target, real32 gain);
184
185void set_pitch(SoundBuffer* buffer, IOAudioEngine* target, real32 pitch);
186
187void
188set_velocity(SoundBuffer* buffer, IOAudioEngine* target, const Point3f& v);
189
190void
191set_position(SoundBuffer* buffer, IOAudioEngine* target, const Point3f& pos);
192
193void
194set_playback_position(SoundBuffer* buffer, IOAudioEngine* target,
195 real32 offset_seconds);
196
197void suspend(IOAudioEngine* target);
198void resume(IOAudioEngine* target);
199
200} // namespace audio
201} // namespace nom
202
203#endif // NOMLIB_AL_SOUNDSOURCE_HEADERS defined
204
Abstract base class for an instance of the audio hardware interface.