Gosu
Audio.hpp
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <Gosu/Fwd.hpp>
7 #include <Gosu/IO.hpp>
8 #include <Gosu/Platform.hpp>
9 #include <memory>
10 #include <string>
11 
12 namespace Gosu
13 {
17  class Channel
18  {
19  mutable int channel, token;
20 
21  public:
23  Channel();
25  Channel(int channel, int token);
26 
28  int current_channel() const;
29 
30  bool playing() const;
31  bool paused() const;
35  void pause();
36  void resume();
39  void stop();
40 
42  void set_volume(double volume);
44  void set_pan(double pan);
46  void set_speed(double speed);
47  };
48 
52  class Sample
53  {
54  struct Impl;
55  std::shared_ptr<Impl> pimpl;
56 
57  public:
59  Sample();
60 
63  explicit Sample(const std::string& filename);
64 
67  explicit Sample(Reader reader);
68 
75  Channel play(double volume = 1, double speed = 1, bool looping = false) const;
76 
86  Channel play_pan(double pan, double volume = 1, double speed = 1,
87  bool looping = false) const;
88  };
89 
92  class Song
93  {
94  struct Impl;
95  std::unique_ptr<Impl> pimpl;
96 
97  // Non-movable to avoid dangling internal references.
98  Song(Song&&) = delete;
99  // Non-movable to avoid dangling internal references.
100  Song& operator=(Song&&) = delete;
101 
102  public:
106  explicit Song(const std::string& filename);
107 
110  explicit Song(Reader reader);
111 
112  ~Song();
113 
117  static Song* current_song();
118 
121  void play(bool looping = false);
124  void pause();
127  bool paused() const;
130  void stop();
132  bool playing() const;
134  double volume() const;
136  void set_volume(double volume);
137 
139  static void update();
140  };
141 }
Definition: Audio.hpp:12
void set_pan(double pan)
Channel()
This creates an "empty" Channel which is expired and cannot be resumed.
void pause()
Pauses this instance to be resumed afterwards.
Utility class that points to a specific position in a resource and offers an interface for sequential...
Definition: IO.hpp:26
bool paused() const
void set_speed(double speed)
Sample::play returns a Channel that represents the sound being played.
Definition: Audio.hpp:17
Songs are less flexible than samples.
Definition: Audio.hpp:92
A sample is a short sound that is completely loaded in memory, can be played multiple times at once a...
Definition: Audio.hpp:52
bool playing() const
int current_channel() const
For internal use only.
void stop()
Stops this channel if the sample is still being played.
Macros and utility functions to facilitate programming on all of Gosu&#39;s supported platforms...
void set_volume(double volume)
Contains everything related to input and output.