JNGL
SoundFile.hpp
Go to the documentation of this file.
1 // Copyright 2019-2021 Jan Niklas Hasse <[email protected]>
2 // For conditions of distribution and use, see copyright notice in LICENSE.txt
5 #pragma once
6 
7 #include <memory>
8 #include <string>
9 #include <vector>
10 
11 namespace jngl {
12 
13 class Sound;
14 struct SoundParams;
15 
17 class SoundFile {
18 public:
20  explicit SoundFile(const std::string& filename);
21  ~SoundFile();
22  SoundFile(const SoundFile&) = delete;
23  SoundFile& operator=(const SoundFile&) = delete;
24  SoundFile(SoundFile&&) noexcept;
25  SoundFile& operator=(SoundFile&&) noexcept;
26 
28  void play();
29 
31  void stop();
32 
34  bool isPlaying();
35 
37  void loop();
38 
40  void setPitch(float);
41 
43  void setVolume(float v);
44 
45 private:
46  std::shared_ptr<Sound> sound_;
47  std::unique_ptr<SoundParams> params;
48  std::vector<char> buffer_;
49 };
50 
51 } // namespace jngl
Sound loaded from an OGG file.
Definition: SoundFile.hpp:17
SoundFile(const std::string &filename)
Load an OGG file called filename.
void play()
Play the sound once. If called twice the sound would also play twice.
bool isPlaying()
Whether the sound is still playing at least once.
void stop()
Stop the last started sound.
void setPitch(float)
Set pitch in (0.0f, ∞]. Default is 1.0f.
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: App.hpp:10