GL Studio C++ Runtime API
sound.h
Go to the documentation of this file.
1/*! \file
2 \brief The SoundSystem class for playback of audio files.
3
4 \par Copyright Information
5
6 Copyright (c) 2017 by The DiSTI Corporation.<br>
7 11301 Corporate Blvd; Suite 100<br>
8 Orlando, Florida 32817<br>
9 USA<br>
10 <br>
11 All rights reserved.<br>
12
13 This Software contains proprietary trade secrets of DiSTI and may not be
14reproduced, in whole or part, in any form, or by any means of electronic,
15mechanical, or otherwise, without the written permission of DiSTI. Said
16permission may be derived through the purchase of applicable DiSTI product
17licenses which detail the distribution rights of this content and any
18Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37State of Florida and the United States of America.
38
39*/
40
41#ifndef INCLUDED_DISTI_SOUND_H
42#define INCLUDED_DISTI_SOUND_H
43
45#include "scoped_ptr.h"
46
47namespace disti
48{
49/// \details The SoundSystem class. Plays WAV files on Desktop Windows.
51{
52public:
53 /** Constructor
54 * \param maxSounds Maximum number of soundfiles in the sound system
55 * \throw std::bad_alloc if unable to allocate memory.
56 */
57 DISTI_EXPORT explicit SoundSystem( int maxSounds );
58
59 /** Destructor */
60 DISTI_EXPORT ~SoundSystem();
61
62 /// \return Whether the sound device was initialized sucessfully.
63 DISTI_EXPORT bool IsValid() const;
64
65 /** Plays the sound at the given index
66 * \param which The zero based index of the sound to play
67 */
68 DISTI_EXPORT void Play( int which );
69
70 /** Plays the sound at the given index, attenuated for distancec
71 * \param which The zero based index of the sound to play
72 * \param volumeOrDistance The volume of the sound, from 0.0 (min) to FLT_MAX (max) or the
73 * distance in meters of the sound, depending on the platform.
74 */
75 DISTI_EXPORT void Play( int which, float volumeOrDistance );
76
77 /** Loads the sound from a file into a slot in the sound system
78 * \param fn The name of the file to load from
79 * \param index The zero based index to load the file into
80 * \throw std::bad_alloc if unable to allocate memory
81 */
82 DISTI_EXPORT void LoadSound( const char* fn, int index );
83
84 /** Loads a number of sounds from files into the sound system
85 * The sounds are loaded sequentially starting at slot zero
86 * \param firstArg Filenames to load, followed by a NULL
87 * \throw std::bad_alloc if unable to allocate memory
88 */
89 DISTI_EXPORT void LoadSounds( const char* firstArg, ... );
90
91 /** Deletes the sound from the given index
92 * \param index Zero based index to clear
93 */
94 DISTI_EXPORT void ClearSound( int index );
95
96 /** Sets the master volume of the sound system, from 0.0 (min) to FLT_MAX (max)
97 * \param volume The master volume of the sound system, from 0.0 (min) to FLT_MAX (max)
98 */
99 DISTI_EXPORT void SetMasterVolume( float volume );
100
101 /** Gets the master volume of the sound system, from 0.0 (min) to FLT_MAX (max)
102 * \return The master volume of the sound system, from 0.0 (min) to FLT_MAX (max)
103 */
104 DISTI_EXPORT float GetMasterVolume() const;
105
106 /// \cond INTERNAL
107 // Base class for all platform-specific implementations of the sound system
108 class ISoundSystemImpl
109 {
110 public:
111 DISTI_EXPORT virtual bool IsValid() const = 0;
112 DISTI_EXPORT virtual void LoadSound( const char* fileName, int index ) = 0;
113 DISTI_EXPORT virtual void ClearSound( int index ) = 0;
114 DISTI_EXPORT virtual void SetMasterVolume( float volume ) = 0;
115 DISTI_EXPORT virtual float GetMasterVolume() const = 0;
116 DISTI_EXPORT virtual void Play( int index ) = 0;
117 DISTI_EXPORT virtual void Play( int index, float volume ) = 0;
118
119 DISTI_EXPORT virtual ~ISoundSystemImpl() {}
120
121 protected:
122 DISTI_EXPORT ISoundSystemImpl() {}
123
124 private:
125 // Disabled
126 ISoundSystemImpl( const ISoundSystemImpl& ) DISTI_SPECIAL_MEM_FUN_DELETE;
127 void operator=( const ISoundSystemImpl& ) DISTI_SPECIAL_MEM_FUN_DELETE;
128 };
129 /// \endcond
130
131private:
132 // Pimpl idiom for platform-specific overrides
133 // Note: The abstract base class + pimpl is an unusual construction, but it allows us to keep
134 // backwards compatibility with our existing code while swapping out the internals.
135 ScopedPtr<ISoundSystemImpl> _impl;
136
137 // The following are to be defined by the platform implementation.
138 // Only one should be present in any build of the GL Studio runtime.
139 static ISoundSystemImpl* CreateSoundSystemImpl( int maxSounds );
140 static const char* const s_errorMsg;
141
142 // Copying/moving is disabled
144 void operator=( const SoundSystem& ) DISTI_SPECIAL_MEM_FUN_DELETE;
145};
146} // namespace disti
147
148#endif
Definition: sound.h:51
SoundSystem(int maxSounds)
float GetMasterVolume() const
void LoadSounds(const char *firstArg,...)
void SetMasterVolume(float volume)
void Play(int which)
void ClearSound(int index)
bool IsValid() const
void LoadSound(const char *fn, int index)
Macros and helper code to determine what subset of C++11/14/17 is available.
#define DISTI_SPECIAL_MEM_FUN_DELETE
Macro to wrap function deletion, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:235
Force inclusion of the DirectShow library.
Definition: bmpimage.h:47
A smart pointer with unique ownership – poor man's std::unique_ptr.