GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
SoundMix.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_AUDIO_SOUND_MIX_HPP
5#define GREM_AUDIO_SOUND_MIX_HPP
6
8
13#include <GREM/core/math.hpp>
15
16namespace grem::audio {
17
27 size_t channelCount = 2;
28
32 float volume = 1.0f;
33
41 bool enableStatistics = false;
42
50 [[nodiscard]] constexpr bool operator==(const SoundMixOptions& other) const = default;
51};
52
58class SoundMix : public Sound {
59public:
68
78 GREM_API(audio) explicit SoundMix(const SoundMixOptions& options, const SoundOptions& soundOptions = {});
79
83 GREM_API(audio) SoundInstanceID playSound(const Sound& sound, float volume = -1.0f);
84
88 GREM_API(audio) SoundInstanceID play3DSound(const Sound& sound, vec3 position, vec3 velocity, float volume = -1.0f);
89
93 GREM_API(audio) SoundInstanceID createPausedSound(const Sound& sound, float volume = -1.0f);
94
98 GREM_API(audio) SoundInstanceID createPaused3DSound(const Sound& sound, vec3 position, vec3 velocity, float volume = -1.0f);
99
103 GREM_API(audio) SoundInstanceID playSoundClocked(Duration time, const Sound& sound, float volume = -1.0f);
104
108 GREM_API(audio) SoundInstanceID play3DSoundClocked(Duration time, const Sound& sound, vec3 position, vec3 velocity, float volume = -1.0f);
109
115 GREM_API(audio) void setVolume(float volume);
116
126 GREM_API(audio) void setStatisticsEnabled(bool newEnableStatistics);
127
143
156 [[nodiscard]] GREM_API(audio) Array<float, 256> getOutputWaveStatistics() const;
157
174 [[nodiscard]] GREM_API(audio) float getOutputChannelVolumeStatistics(uint32_t channelIndex) const;
175};
176
177} // namespace grem::audio
178
179#endif
SoundMix()
Construct a stereo sound mix with the default options.
Definition SoundMix.hpp:66
Array< float, 256 > calculateOutputFastFourierTransformStatistics() const
Calculate the fast Fourier transform of the audio currently playing through the sound mix.
SoundMix(const SoundMixOptions &options, const SoundOptions &soundOptions={})
Construct a sound mix.
float getOutputChannelVolumeStatistics(uint32_t channelIndex) const
Get an approximation of the volume of the audio currently playing through a specific channel of the s...
SoundInstanceID createPausedSound(const Sound &sound, float volume=-1.0f)
Create a new relative sound instance, but don't start playing it yet.
Array< float, 256 > getOutputWaveStatistics() const
Get the sound wave currently playing through the sound mix.
void setStatisticsEnabled(bool newEnableStatistics)
Set whether to enable statistics gathering or not.
SoundInstanceID playSoundClocked(Duration time, const Sound &sound, float volume=-1.0f)
Create a new 3D sound instance and start playing it at a specific time relative to other sounds that ...
SoundInstanceID playSound(const Sound &sound, float volume=-1.0f)
Create a new relative sound instance and start playing it.
SoundInstanceID createPaused3DSound(const Sound &sound, vec3 position, vec3 velocity, float volume=-1.0f)
Create a new 3D sound instance, but don't start playing it yet.
SoundInstanceID play3DSoundClocked(Duration time, const Sound &sound, vec3 position, vec3 velocity, float volume=-1.0f)
Create a new 3D sound instance and start playing it at a specific time relative to other sounds that ...
SoundInstanceID play3DSound(const Sound &sound, vec3 position, vec3 velocity, float volume=-1.0f)
Create a new 3D sound instance and start playing it.
void setVolume(float volume)
Set the volume of the sound mix.
Sound() noexcept=default
Construct an invalid sound that must be reassigned before use.
Definition Error.hpp:12
Clock::duration Duration
Definition Clock.hpp:25
vec< 3, float > vec3
Definition math.hpp:439
Definition Array.hpp:20
Opaque handle to a specific instance of a sound or sound mix playing in a sound stage or sound mix.
Definition SoundInstanceID.hpp:23
Configuration options for a SoundMix.
Definition SoundMix.hpp:21
size_t channelCount
The number of channels to produce audio for.
Definition SoundMix.hpp:27
bool enableStatistics
Whether to enable statistics gathering or not.
Definition SoundMix.hpp:41
float volume
Default volume of the sound mix.
Definition SoundMix.hpp:32
constexpr bool operator==(const SoundMixOptions &other) const =default
Compare these options to another set of options for equality.
Configuration options for a Sound.
Definition Sound.hpp:95