Container for a particular sound wave that can be played in a SoundStage.
More...
#include <GREM/audio/Sound.hpp>
|
| | Sound () noexcept=default |
| | Construct an invalid sound that must be reassigned before use.
|
| | Sound (const Filesystem &filesystem, CStringView filepath, const SoundOptions &options={}) |
| | Load a sound from a virtual file.
|
| | Sound (Span< const byte > fileContents, const SoundOptions &options={}) |
| | Load a sound from an in-memory file.
|
| | Sound (Span< const uint8_t > samples, float sampleRate, size_t channelCount=1, const SoundOptions &options={}) |
| | Construct a sound wave from a raw array of samples.
|
| | Sound (Span< const int16_t > samples, float sampleRate, size_t channelCount=1, const SoundOptions &options={}) |
| | Construct a sound wave from a raw array of samples.
|
| | Sound (Span< const float32_t > samples, float sampleRate, size_t channelCount=1, const SoundOptions &options={}) |
| | Construct a sound wave from a raw array of samples.
|
| | operator bool () const noexcept |
| | Check if the sound has a value.
|
| template<filter F> |
| void | setFilter (size_t filterSlotIndex, const F &newFilter) |
| | Set the filter at a particular filter slot of the sound.
|
| void | removeFilter (size_t filterSlotIndex) noexcept |
| | Remove the filter at a particular filter slot of the sound.
|
| Duration | getDuration () const noexcept |
| | Get the duration of the sound.
|
| void * | get () noexcept |
| | Get an opaque handle to the internal representation of the sound.
|
| const void * | get () const noexcept |
| | Get an opaque handle to the internal representation of the sound.
|
|
| static constexpr size_t | MAX_FILTER_COUNT = 8 |
| | Maximum number of filters that can be applied simultaneously to a sound.
|
Container for a particular sound wave that can be played in a SoundStage.
A single loaded sound can be used to spawn multiple sound instances that play the same sound at different times or in parallel, and with potentially varying volumes, positions and velocities.
◆ Sound() [1/7]
| grem::audio::Sound::Sound |
( |
| ) |
|
|
defaultnoexcept |
Construct an invalid sound that must be reassigned before use.
◆ Sound() [2/7]
Load a sound from a virtual file.
The supported file formats are:
- Vorbis (.ogg)
- RIFF (.wav)
- FLAC (.flac)
- MP3 (.mp3)
- Parameters
-
| filesystem | filesystem to load the file from. |
| filepath | virtual filepath of the sound file to load. |
| options | sound options, see SoundOptions. |
- Exceptions
-
| File::Error | on failure to open the file. |
| audio::Error | on failure to load a sound from the file. |
| std::length_error | if the maximum sound file size was exceeded. |
| std::bad_alloc | on allocation failure. |
- Note
- The file format is determined entirely from the file contents; the filename extension is not taken into account.
◆ Sound() [3/7]
| grem::audio::Sound::Sound |
( |
Span< const byte > | fileContents, |
|
|
const SoundOptions & | options = {} ) |
|
explicit |
Load a sound from an in-memory file.
The supported file formats are:
- Vorbis (.ogg)
- RIFF (.wav)
- FLAC (.flac)
- MP3 (.mp3)
- Parameters
-
| fileContents | contents of the sound file to load. |
| options | sound options, see SoundOptions. |
- Exceptions
-
| audio::Error | on failure to load a sound from the file. |
| std::length_error | if the maximum sound file size was exceeded. |
| std::bad_alloc | on allocation failure. |
◆ Sound() [4/7]
| grem::audio::Sound::Sound |
( |
Span< const uint8_t > | samples, |
|
|
float | sampleRate, |
|
|
size_t | channelCount = 1, |
|
|
const SoundOptions & | options = {} ) |
Construct a sound wave from a raw array of samples.
- Parameters
-
| samples | array of unsigned 8-bit samples. |
| sampleRate | sample rate of the sound, in Hertz. For example: 44100.0f, 48000.0f or 96000.0f. |
| channelCount | number of sound channels. The number of samples must be divisible by this number. |
| options | sound options, see SoundOptions. |
- Exceptions
-
| audio::Error | on failure to create the sound. |
| std::length_error | if the maximum sound wave size was exceeded. |
| std::bad_alloc | on allocation failure. |
◆ Sound() [5/7]
| grem::audio::Sound::Sound |
( |
Span< const int16_t > | samples, |
|
|
float | sampleRate, |
|
|
size_t | channelCount = 1, |
|
|
const SoundOptions & | options = {} ) |
Construct a sound wave from a raw array of samples.
- Parameters
-
| samples | array of signed 16-bit samples. |
| sampleRate | sample rate of the sound, in Hertz. For example: 44100.0f, 48000.0f or 96000.0f. |
| channelCount | number of sound channels. The number of samples must be divisible by this number. |
| options | sound options, see SoundOptions. |
- Exceptions
-
| audio::Error | on failure to create the sound. |
| std::length_error | if the maximum sound wave size was exceeded. |
| std::bad_alloc | on allocation failure. |
◆ Sound() [6/7]
| grem::audio::Sound::Sound |
( |
Span< const float32_t > | samples, |
|
|
float | sampleRate, |
|
|
size_t | channelCount = 1, |
|
|
const SoundOptions & | options = {} ) |
Construct a sound wave from a raw array of samples.
- Parameters
-
| samples | array of floating-point 32-bit samples. |
| sampleRate | sample rate of the sound, in Hertz. For example: 44100.0f, 48000.0f or 96000.0f. |
| channelCount | number of sound channels. The number of samples must be divisible by this number. |
| options | sound options, see SoundOptions. |
- Exceptions
-
| audio::Error | on failure to create the sound. |
| std::length_error | if the maximum sound wave size was exceeded. |
| std::bad_alloc | on allocation failure. |
◆ Sound() [7/7]
| grem::audio::Sound::Sound |
( |
void * | handle, |
|
|
const SoundOptions & | options ) |
|
protected |
◆ operator bool()
| grem::audio::Sound::operator bool |
( |
| ) |
const |
|
inlineexplicitnoexcept |
Check if the sound has a value.
- Returns
- true if the sound has a value, false otherwise.
◆ setFilter()
template<filter F>
| void grem::audio::Sound::setFilter |
( |
size_t | filterSlotIndex, |
|
|
const F & | newFilter ) |
|
inline |
Set the filter at a particular filter slot of the sound.
This replaces any existing filter at the given slot.
- Parameters
-
| filterSlotIndex | filter slot index to set the filter of. Must be less than Sound::MAX_FILTER_COUNT. |
| newFilter | new filter to insert. |
- Exceptions
-
| audio::Error | on failure to create the filter. |
| std::length_error | if the maximum filter size was exceeded. |
| std::bad_alloc | on allocation failure. |
◆ removeFilter()
| void grem::audio::Sound::removeFilter |
( |
size_t | filterSlotIndex | ) |
|
|
noexcept |
Remove the filter at a particular filter slot of the sound.
- Parameters
-
◆ getDuration()
| Duration grem::audio::Sound::getDuration |
( |
| ) |
const |
|
nodiscardnoexcept |
Get the duration of the sound.
- Returns
- the time duration between the start and end of the sound when played at 1x speed.
◆ get() [1/2]
| void * grem::audio::Sound::get |
( |
| ) |
|
|
inlinenodiscardnoexcept |
Get an opaque handle to the internal representation of the sound.
- Returns
- an untyped non-owning pointer to the internal representation of the sound.
- Note
- This function is used internally by the SoundStage implementation and is not intended to be used outside of it. The returned handle has no meaning to application code.
◆ get() [2/2]
| const void * grem::audio::Sound::get |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
Get an opaque handle to the internal representation of the sound.
- Returns
- an untyped non-owning read-only pointer to the internal representation of the sound.
- Note
- This function is used internally by the SoundStage implementation and is not intended to be used outside of it. The returned handle has no meaning to application code.
◆ MAX_FILTER_COUNT
| size_t grem::audio::Sound::MAX_FILTER_COUNT = 8 |
|
staticconstexpr |
Maximum number of filters that can be applied simultaneously to a sound.
The documentation for this class was generated from the following file: