sfml_impl 0.1.0
Vendor SFML 3.0.2 : IGraphic2Module / IAudioModule
Loading...
Searching...
No Matches
SfmlSoundBuffer.hpp
Go to the documentation of this file.
1
11#ifndef SFMLSOUNDBUFFER_HPP_
12#define SFMLSOUNDBUFFER_HPP_
13
14//Sfml
15#include <SFML/Audio.hpp>
16
17//Interface
18#include "ISoundBuffer.hpp"
19
20#include <iostream>
21#include <optional>
22
28class SfmlSoundBuffer : public audio::ISoundBuffer {
29
30 public:
31 SfmlSoundBuffer(std::string path) {
32 try {
33 _buffer.emplace(path);
34 } catch (const sf::Exception &e) {
35 std::cerr << "Failed to load sound buffer: " << e.what() << std::endl;
36 }
37 }
38
39 ~SfmlSoundBuffer() = default;
40
41 bool isReady() const override {
42 return _buffer.has_value();
43 }
44
45 float getLength() const override {
46 return _buffer.has_value() ? _buffer->getDuration().asSeconds() : 0.f;
47 }
48
49 const sf::SoundBuffer &handle() const {
50 return _buffer.value();
51 }
52
53 private:
54 std::optional<sf::SoundBuffer> _buffer;
55};
56
59#endif /* !SFMLSOUNDBUFFER_HPP_ */
Sfml SoundBuffer class - owns the loaded samples. SfmlSound only references it (sf::Sound itself alre...
Definition SfmlSoundBuffer.hpp:28
bool isReady() const override
Definition SfmlSoundBuffer.hpp:41
SfmlSoundBuffer(std::string path)
Definition SfmlSoundBuffer.hpp:31
float getLength() const override
Definition SfmlSoundBuffer.hpp:45
~SfmlSoundBuffer()=default
const sf::SoundBuffer & handle() const
Definition SfmlSoundBuffer.hpp:49