|
JNGL
Easy to use cross-platform 2D game library
|
Sound loaded from an OGG or MP3 file. More...
#include <jngl/SoundFile.hpp>
Public Member Functions | |
| SoundFile (const std::string &filename, std::launch policy=std::launch::async) | |
| Load an OGG or MP3 file called filename. | |
| SoundFile (const SoundFile &)=delete | |
| SoundFile & | operator= (const SoundFile &)=delete |
| SoundFile (SoundFile &&) noexcept | |
| SoundFile & | operator= (SoundFile &&) noexcept |
| void | play () |
| Play the sound once. If called twice the sound would also play twice. | |
| void | play (Channel &) |
| Play the sound once on the Channel. | |
| void | stop () |
| Stop the last started sound. | |
| void | stop (Channel &) |
| Stop the last started sound of this SoundFile started on the Channel. | |
| bool | isPlaying () |
| Whether the sound is still playing at least once. | |
| void | loop () |
| Play the sound in a loop. Can also be stopped using stop() | |
| void | loop (Channel &) |
| SoundPanning | playWithPanning () |
| Like play(), but the sound can be positioned in the stereo field. | |
| SoundPanning | playWithPanning (Channel &) |
| SoundPanning | loopWithPanning () |
| Like loop(), but the sound can be positioned in the stereo field. | |
| SoundPanning | loopWithPanning (Channel &) |
| void | setVolume (float v) |
| Set volume in [0, ∞]. Default is 1.0f. | |
| void | load () |
| Block until the sound file has been fully decompressed and loaded. | |
| std::chrono::milliseconds | length () const |
| Returns the duration in ms. | |
| float | progress () const |
| Returns playing progress in [0, 1], can be used with length() to determine how much time has passed. | |
| std::span< float > | getSamples () |
| Returns the raw audio samples of this SoundFile. | |
Static Public Member Functions | |
| static std::shared_ptr< SoundFile > | get (std::string_view filename) |
| Returns a shared pointer to a SoundFile from JNGL's internal cache, creates it with async loading if necessary. | |
Sound loaded from an OGG or MP3 file.
JNGL keeps a list of loaded sound files, so there's no need for you to use this class directly - you can just use jngl::play or Channel::play. If you want to access the internally SoundFile from JNGL's cache before playing, use SoundFile::get.
Definition at line 34 of file SoundFile.hpp.
|
explicit |
Load an OGG or MP3 file called filename.
Loading can either happen on its own thread (std::launch::async) or the first time you try to play the file (std::launch::deferred).
|
static |
Returns a shared pointer to a SoundFile from JNGL's internal cache, creates it with async loading if necessary.
Example:
| void stop | ( | Channel & | ) |
Stop the last started sound of this SoundFile started on the Channel.
|
nodiscard |
Like play(), but the sound can be positioned in the stereo field.
The sound only starts playing once SoundPanning::setPanning has been called for the first time and stops when the returned object gets destroyed. Use the returned object to control the sound, as stop(), isPlaying(), setVolume() and progress() of this SoundFile won't affect it.
|
nodiscard |
Like loop(), but the sound can be positioned in the stereo field.
Unlike loop() this will always start a new sound, even if this SoundFile is already looping. See playWithPanning() for details.
| void load | ( | ) |
Block until the sound file has been fully decompressed and loaded.
| std::runtime_error | File not found or decoding errors |
| float progress | ( | ) | const |
Returns playing progress in [0, 1], can be used with length() to determine how much time has passed.
If the sound hasn't been started yet, returns 0.0f.