soundbuffer.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2016 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
29 #pragma once
30 
31 #include <memory>
32 #include "soundbuffer_session.h"
33 #include "../Core/Resources/resource.h"
34 
35 namespace clan
36 {
39 
40  class XMLResourceDocument;
41  class SoundOutput;
42  class SoundProvider;
43  class SoundBuffer_Session;
44  class SoundFilter;
45  class SoundBuffer_Impl;
46  class IODevice;
47  class FileSystem;
48  class ResourceManager;
49 
56  {
57  public:
59  SoundBuffer();
60 
62 
76  SoundProvider *provider);
77 
79  const std::string &fullname,
80  bool streamed = false,
81  const std::string &format = "");
82 
84  const std::string &filename,
85  bool streamed,
86  const FileSystem &fs,
87  const std::string &type = "");
88 
90  IODevice &file,
91  bool streamed,
92  const std::string &type);
93 
99  static Resource<SoundBuffer> resource(const std::string &id, const ResourceManager &resources);
100 
102  static SoundBuffer load(const std::string &id, const XMLResourceDocument &doc);
103 
104  virtual ~SoundBuffer();
105 
107  SoundProvider *get_provider() const;
108 
110  float get_volume() const;
111 
113  float get_pan() const;
114 
116  bool is_null() const { return !impl; }
117 
119  void throw_if_null() const;
120 
122 
125  void set_volume(float new_volume);
126 
128 
132  void set_pan(float new_pan);
133 
137  void add_filter(SoundFilter &filter);
138 
140  void remove_filter(SoundFilter &filter);
141 
148  SoundBuffer_Session play(bool looping = false, SoundOutput *output = nullptr);
149 
155  SoundBuffer_Session prepare(bool looping = false, SoundOutput *output = nullptr);
156 
157  private:
158  std::shared_ptr<SoundBuffer_Impl> impl;
159  };
160 
162 }
SoundBuffer_Session play(bool looping=false, SoundOutput *output=nullptr)
Plays the soundbuffer on the specified soundcard.
Definition: clanapp.h:35
SoundProvider * get_provider() const
Returns the sound provider to be used for playback.
float get_volume() const
Returns the start/default volume used when the buffer is played.
void set_pan(float new_pan)
Sets the panning of the sound buffer played in measures from -1 -> 1.
Resource proxy of a specific type.
Definition: resource.h:57
Sound provider.
Definition: soundprovider.h:45
static Resource< SoundBuffer > resource(const std::string &id, const ResourceManager &resources)
Retrieves a SoundBuffer resource from the resource manager.
I/O Device interface.
Definition: iodevice.h:49
SoundBuffer_Session provides control over a playing soundeffect.
Definition: soundbuffer_session.h:50
SoundOutput interface in ClanLib.
Definition: soundoutput.h:47
void throw_if_null() const
Throw an exception if this object is invalid.
static SoundBuffer load(const std::string &id, const XMLResourceDocument &doc)
Loads a SoundBuffer from a XML resource definition.
void add_filter(SoundFilter &filter)
Adds the sound filter to the sound buffer.
Sample interface in ClanLib.
Definition: soundbuffer.h:55
void set_volume(float new_volume)
Sets the volume of the sound buffer in a relative measure (0->1)
SoundBuffer_Session prepare(bool looping=false, SoundOutput *output=nullptr)
Prepares the soundbuffer for playback on the specified soundcard.
Virtual File System (VFS).
Definition: file_system.h:46
void remove_filter(SoundFilter &filter)
Remove the sound filter from the sound buffer.
Sound Filter Class.
Definition: soundfilter.h:43
Resource manager.
Definition: resource_manager.h:43
bool is_null() const
Returns true if this object is invalid.
Definition: soundbuffer.h:116
float get_pan() const
Returns the default panning position when the buffer is played.
virtual ~SoundBuffer()
XML Resource Document.
Definition: xml_resource_document.h:47
SoundBuffer()
Construct a null instance.