utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
audio_source.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22#pragma once
23
24#include <AL/al.h>
25#include <AL/alc.h>
26
27#include <memory>
28
29#include "utility/sound/audio_buffer.hpp"
30
31namespace utility::sound
32{
33 class AudioManager;
34
55 {
56 public:
64 AudioSource(uint32_t sourceID, AudioManager &manager);
65
72
78 void play();
79
85 void pause();
86
93 void stop();
94
102 void setBuffer(std::shared_ptr<AudioBuffer> buffer);
103
109 void setLooping(bool loop);
110
119 void setPitch(float pitch);
120
126 void setGain(float gain);
127
133 [[nodiscard]] uint32_t sourceID() const;
134
135 private:
139 std::shared_ptr<AudioBuffer> _buffer;
140
144 uint32_t _sourceID;
145
149 AudioManager &_manager;
150
154 bool _isPlaying = false;
155
159 float _pitch = 1.0f;
160
164 float _gain = 1.0f;
165
169 bool _looping = false;
170 };
171} // namespace utility::sound
Central manager responsible for OpenAL initialization and audio resource management.
Represents a playable audio source managed by AudioManager.
void setPitch(float pitch)
Sets the playback pitch.
void stop()
Stops audio playback.
void setGain(float gain)
Sets the playback gain.
void setBuffer(std::shared_ptr< AudioBuffer > buffer)
Assigns an audio buffer to this source.
void play()
Starts or resumes audio playback.
void pause()
Pauses audio playback.
uint32_t sourceID() const
Returns the unique identifier of this audio source.
~AudioSource()
Destroys the audio source.
void setLooping(bool loop)
Enables or disables looping playback.