CUGL 1.2
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
CUSound.h
1 //
2 // CUSound.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides a sound asset. Historically, these would just be
6 // prerecorded sound files encoded a WAV, MP3, or OGG files. However, our
7 // long term roadmap is to support arbitrary audio graphs created by programs
8 // like PureData, Max DSP or Abelton. For that reason, the sound asset is
9 // an abstract class that is the base for several asset types.
10 //
11 // To get a specific sound asset type, either use a specific class (like
12 // AudioSample or AudioWaveform) or use the factory allocator in this class.
13 //
14 // This class uses our standard shared-pointer architecture.
15 //
16 // 1. The constructor does not perform any initialization; it just sets all
17 // attributes to their defaults.
18 //
19 // 2. All initialization takes place via init methods, which can fail if an
20 // object is initialized more than once.
21 //
22 // 3. All allocation takes place via static constructors which return a shared
23 // pointer.
24 //
25 //
26 // CUGL MIT License:
27 // This software is provided 'as-is', without any express or implied
28 // warranty. In no event will the authors be held liable for any damages
29 // arising from the use of this software.
30 //
31 // Permission is granted to anyone to use this software for any purpose,
32 // including commercial applications, and to alter it and redistribute it
33 // freely, subject to the following restrictions:
34 //
35 // 1. The origin of this software must not be misrepresented; you must not
36 // claim that you wrote the original software. If you use this software
37 // in a product, an acknowledgment in the product documentation would be
38 // appreciated but is not required.
39 //
40 // 2. Altered source versions must be plainly marked as such, and must not
41 // be misrepresented as being the original software.
42 //
43 // 3. This notice may not be removed or altered from any source distribution.
44 //
45 // Author: Walker White
46 // Version: 11/20/18
47 //
48 #ifndef __CU_SOUND_H__
49 #define __CU_SOUND_H__
50 #include <cugl/audio/graph/CUAudioNode.h>
51 #include <cugl/audio/graph/CUAudioNode.h>
52 #include <cugl/math/CUMathBase.h>
53 
54 namespace cugl {
69 class Sound : public std::enable_shared_from_this<Sound> {
70 private:
72  CU_DISALLOW_COPY_AND_ASSIGN(Sound);
73 
74 protected:
76  Uint8 _channels;
77 
79  Uint32 _rate;
80 
82  std::string _file;
83 
85  float _volume;
86 
87 public:
88 #pragma mark Constructors
89 
95  Sound();
96 
100  ~Sound() { dispose(); }
101 
108  virtual void dispose();
109 
110 #pragma mark Attributes
111 
116  Uint32 getRate() const { return _rate; }
117 
130  Uint32 getChannels() const { return _channels; }
131 
141  virtual Sint64 getLength() const { return -1; }
142 
152  virtual double getDuration() const { return -1; }
153 
161  std::string getFile() const { return _file; }
162 
171  std::string getSuffix() const;
172 
184  float getVolume() const { return _volume; }
185 
197  void setVolume(float volume);
198 
208  virtual std::shared_ptr<audio::AudioNode> createNode() { return nullptr; };
209 };
210 
211 }
212 
213 #endif /* __CU_SOUND_H__ */
Definition: CUSound.h:69
std::string _file
Definition: CUSound.h:82
std::string getFile() const
Definition: CUSound.h:161
std::string getSuffix() const
Uint32 getRate() const
Definition: CUSound.h:116
void setVolume(float volume)
virtual double getDuration() const
Definition: CUSound.h:152
~Sound()
Definition: CUSound.h:100
virtual std::shared_ptr< audio::AudioNode > createNode()
Definition: CUSound.h:208
virtual void dispose()
virtual Sint64 getLength() const
Definition: CUSound.h:141
Uint8 _channels
Definition: CUSound.h:76
Uint32 getChannels() const
Definition: CUSound.h:130
Uint32 _rate
Definition: CUSound.h:79
float getVolume() const
Definition: CUSound.h:184
Definition: CUAction.h:51
float _volume
Definition: CUSound.h:85