soundbuffer.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 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
30 #pragma once
31
32 #include <memory>
33 #include "soundbuffer_session.h"
34 #include "../Core/Resources/resource.h"
35
36 namespace clan
37 {
40
41 class XMLResourceDocument;
42 class SoundOutput;
43 class SoundProvider;
44 class SoundBuffer_Session;
45 class SoundFilter;
46 class SoundBuffer_Impl;
47 class IODevice;
48 class FileSystem;
49 class ResourceManager;
50
56 class SoundBuffer
57 {
60
61 public:
63 SoundBuffer();
64
66
79 SoundBuffer(
80 SoundProvider *provider);
81
82 SoundBuffer(
83 const std::string &fullname,
84 bool streamed = false,
85 const std::string &format = "");
86
87 SoundBuffer(
88 const std::string &filename,
89 bool streamed,
90 const FileSystem &fs,
91 const std::string &type = "");
92
93 SoundBuffer(
94 IODevice &file,
95 bool streamed,
96 const std::string &type);
97
99
102 public:
103
104
110 static Resource<SoundBuffer> resource(const std::string &id, const ResourceManager &resources);
111
113 static SoundBuffer load(const std::string &id, const XMLResourceDocument &doc);
114
115 virtual ~SoundBuffer();
116
120
121 public:
123 SoundProvider *get_provider() const;
124
126 float get_volume() const;
127
129 float get_pan() const;
130
132 bool is_null() const { return !impl; }
133
135 void throw_if_null() const;
136
140
141 public:
142
144
147 void set_volume(float new_volume);
148
150
154 void set_pan(float new_pan);
155
159 void add_filter(SoundFilter &filter);
160
162 void remove_filter(SoundFilter &filter);
163
170 SoundBuffer_Session play(bool looping = false, SoundOutput *output = nullptr);
171
177 SoundBuffer_Session prepare(bool looping = false, SoundOutput *output = nullptr);
178
182
183 private:
184 std::shared_ptr<SoundBuffer_Impl> impl;
186 };
187
188 }
189
clan::SoundBuffer::prepare
SoundBuffer_Session prepare(bool looping=false, SoundOutput *output=nullptr)
Prepares the soundbuffer for playback on the specified soundcard.
clan
Definition: clanapp.h:35
clan::SoundBuffer::~SoundBuffer
virtual ~SoundBuffer()
clan::Resource
Resource proxy of a specific type.
Definition: resource.h:58
clan::SoundProvider
Sound provider.
Definition: soundprovider.h:45
clan::SoundBuffer::get_provider
SoundProvider * get_provider() const
Returns the sound provider to be used for playback.
clan::IODevice
I/O Device interface.
Definition: iodevice.h:50
clan::SoundBuffer_Session
SoundBuffer_Session provides control over a playing soundeffect.
Definition: soundbuffer_session.h:51
clan::SoundOutput
SoundOutput interface in ClanLib.
Definition: soundoutput.h:48
clan::SoundBuffer::is_null
bool is_null() const
Returns true if this object is invalid.
Definition: soundbuffer.h:132
clan::SoundBuffer::SoundBuffer
SoundBuffer()
Construct a null instance.
clan::SoundBuffer::set_volume
void set_volume(float new_volume)
Sets the volume of the sound buffer in a relative measure (0->1)
clan::SoundBuffer
Sample interface in ClanLib.
Definition: soundbuffer.h:56
clan::SoundBuffer::play
SoundBuffer_Session play(bool looping=false, SoundOutput *output=nullptr)
Plays the soundbuffer on the specified soundcard.
clan::StyleTokenType::string
@ keyword
clan::SoundBuffer::resource
static Resource< SoundBuffer > resource(const std::string &id, const ResourceManager &resources)
Retrieves a SoundBuffer resource from the resource manager.
clan::FileSystem
Virtual File System (VFS).
Definition: file_system.h:47
clan::SoundFilter
Sound Filter Class.
Definition: soundfilter.h:44
clan::SoundBuffer::throw_if_null
void throw_if_null() const
Throw an exception if this object is invalid.
clan::ResourceManager
Resource manager.
Definition: resource_manager.h:44
clan::SoundBuffer::set_pan
void set_pan(float new_pan)
Sets the panning of the sound buffer played in measures from -1 -> 1.
clan::SoundBuffer::load
static SoundBuffer load(const std::string &id, const XMLResourceDocument &doc)
Loads a SoundBuffer from a XML resource definition.
clan::SoundBuffer::get_volume
float get_volume() const
Returns the start/default volume used when the buffer is played.
clan::SoundBuffer::get_pan
float get_pan() const
Returns the default panning position when the buffer is played.
clan::XMLResourceDocument
XML Resource Document.
Definition: xml_resource_document.h:48
clan::SoundBuffer::remove_filter
void remove_filter(SoundFilter &filter)
Remove the sound filter from the sound buffer.
clan::SoundBuffer::add_filter
void add_filter(SoundFilter &filter)
Adds the sound filter to the sound buffer.