JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
SoundFile.hpp
Go to the documentation of this file.
1// Copyright 2019-2024 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include <future>
8#include <memory>
9#include <string>
10#include <vector>
11#if defined(__has_include) && __has_include(<optional>)
12#include <optional>
13using std::optional;
14#else
15#include <experimental/optional>
17#endif
18
19namespace jngl {
20
21class Channel;
22class Sound;
23struct SoundParams;
24
29class SoundFile {
30public:
39 explicit SoundFile(const std::string& filename, std::launch policy = std::launch::async);
40 ~SoundFile();
41 SoundFile(const SoundFile&) = delete;
42 SoundFile& operator=(const SoundFile&) = delete;
43 SoundFile(SoundFile&&) noexcept;
44 SoundFile& operator=(SoundFile&&) noexcept;
45
47 void play();
48 void play(Channel&);
49
51 void stop();
52 void stop(Channel&);
53
55 bool isPlaying();
56
58 void loop();
59 void loop(Channel&);
60
62 void setVolume(float v);
63
67 void load();
68
69private:
70 std::shared_ptr<Sound> sound_;
71 std::vector<float> buffer_;
72 long frequency = -1;
73};
74
75} // namespace jngl
An audio channel, different channels could be for example: "Music", "Speech" and "Sound Effects".
Definition: Channel.hpp:16
Sound loaded from an OGG file.
Definition: SoundFile.hpp:29
void play()
Play the sound once. If called twice the sound would also play twice.
SoundFile(const std::string &filename, std::launch policy=std::launch::async)
Load an OGG file called filename.
void load()
Block until the sound file has been fully decompressed and loaded.
bool isPlaying()
Whether the sound is still playing at least once.
void stop()
Stop the last started sound.
void setVolume(float v)
Set volume in [0, ∞]. Default is 1.0f.
void loop()
Play the sound in a loop. Can also be stopped using stop()
JNGL's main namespace.
Definition: Achievement.hpp:10