#include <Sound.hpp>
Represent a sound being played.
More...
Represent a sound being played.
- See also
- SoundBuffer
Example
sound.Play()
A sound file loaded in memory.
Represent a sound being played.
Please make sure to init OpenAL in main() by creating a smk::Audio.
- Examples
- sound.cpp.
Definition at line 31 of file Sound.hpp.
◆ Sound() [1/3]
◆ Sound() [2/3]
◆ ~Sound()
Definition at line 41 of file Sound.cpp.
41 {
43 if (source_) {
44 alDeleteSources(1, &source_);
45 }
46}
void Stop()
Stop playing the sound.
◆ Sound() [3/3]
smk::Sound::Sound |
( |
Sound && |
o | ) |
|
|
noexcept |
Definition at line 89 of file Sound.cpp.
89 {
90 operator=(std::move(o));
91}
◆ IsPlaying()
bool smk::Sound::IsPlaying |
( |
| ) |
const |
- Returns
- return whether the sound is currently playing something or not.
Definition at line 80 of file Sound.cpp.
80 {
81 if (!source_) {
82 return false;
83 }
84 ALint state = {};
85 alGetSourcei(source_, AL_SOURCE_STATE, &state);
86 return (state == AL_PLAYING);
87}
◆ operator=()
Definition at line 93 of file Sound.cpp.
93 {
94 std::swap(buffer_, o.buffer_);
95 std::swap(source_, o.source_);
96 std::swap(is_playing_, o.is_playing_);
97 return *this;
98}
◆ Play()
void smk::Sound::Play |
( |
| ) |
|
Start playing the sound.
Definition at line 49 of file Sound.cpp.
49 {
50 if (!buffer_ || !buffer_->buffer()) {
51 return;
52 }
53 if (is_playing_) {
55 }
56 EnsureSourceIsCreated();
57 alSourcei(source_, AL_BUFFER, ALint(buffer_->buffer()));
58 alSourcePlay(source_);
59 is_playing_ = true;
60}
◆ SetLoop()
void smk::Sound::SetLoop |
( |
bool |
looping | ) |
|
Specify whether the sound must restart when it has reached the end.
- Parameters
-
looping | whether the sound must restart when it has reached the end. |
Definition at line 74 of file Sound.cpp.
74 {
75 EnsureSourceIsCreated();
76 alSourcei(source_, AL_LOOPING, looping);
77}
◆ SetVolume()
void smk::Sound::SetVolume |
( |
float |
volume | ) |
|
Definition at line 100 of file Sound.cpp.
100 {
101 if (!source_) {
102 return;
103 }
104 EnsureSourceIsCreated();
105 alSourcef(source_, AL_GAIN, volume);
106}
◆ Stop()
void smk::Sound::Stop |
( |
| ) |
|
Stop playing the sound.
Definition at line 63 of file Sound.cpp.
63 {
64 if (!source_ || !buffer_ || !is_playing_) {
65 return;
66 }
67 alSourceStop(source_);
68 alSourcei(source_, AL_BUFFER, 0);
69 is_playing_ = false;
70}
The documentation for this class was generated from the following files:
- /home/arthursonzogni/programmation/real/smk/include/smk/Sound.hpp
- /home/arthursonzogni/programmation/real/smk/src/smk/Sound.cpp