| 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
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38
39*/
40
41#ifndef INCLUDED_DISTI_SOUND_H
42#define INCLUDED_DISTI_SOUND_H
43
44#include "gls_cpp_lang_support.h"
45#include "scoped_ptr.h"
46
47 namespace disti
48{
49/// \details The SoundSystem class. Plays WAV files on Desktop Windows.
50 class SoundSystem
51{
52 public:
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
131 private:
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
143 SoundSystem( const SoundSystem& ) DISTI_SPECIAL_MEM_FUN_DELETE;
144 void operator=( const SoundSystem& ) DISTI_SPECIAL_MEM_FUN_DELETE;
145};
146} // namespace disti
147
148#endif
disti::SoundSystem
Definition: sound.h:51
disti::SoundSystem::~SoundSystem
~SoundSystem()
disti::SoundSystem::SoundSystem
SoundSystem(int maxSounds)
disti::SoundSystem::GetMasterVolume
float GetMasterVolume() const
disti::SoundSystem::LoadSounds
void LoadSounds(const char *firstArg,...)
disti::SoundSystem::SetMasterVolume
void SetMasterVolume(float volume)
disti::SoundSystem::Play
void Play(int which)
disti::SoundSystem::ClearSound
void ClearSound(int index)
disti::SoundSystem::IsValid
bool IsValid() const
disti::SoundSystem::LoadSound
void LoadSound(const char *fn, int index)
gls_cpp_lang_support.h
Macros and helper code to determine what subset of C++11/14/17 is available.
DISTI_SPECIAL_MEM_FUN_DELETE
#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:246
disti
Definition: bmpimage.h:47
scoped_ptr.h
A smart pointer with unique ownership – poor man's std::unique_ptr.