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 ///////////////////////////////////////////////////////////////////////////////////////////////////
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  /** Returns 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  ///////////////////////////////////////////////////////////////////////////////////////////
107  /// Base class for all platform-specific implementations of the sound system
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 
130 private:
131  // Pimpl idiom for platform-specific overrides
132  // Note: The abstract base class + pimpl is an unusual construction, but it allows us to keep
133  // backwards compatibility with our existing code while swapping out the internals.
135 
136  // The following are to be defined by the platform implementation.
137  // Only one should be present in any build of the GL Studio runtime.
138  static ISoundSystemImpl* CreateSoundSystemImpl( int maxSounds );
139  static const char* const s_errorMsg;
140 
141  // Copying/moving is disabled
142  SoundSystem( const SoundSystem& ) DISTI_SPECIAL_MEM_FUN_DELETE;
143  void operator=( const SoundSystem& ) DISTI_SPECIAL_MEM_FUN_DELETE;
144 };
145 } // namespace disti
146 
147 #endif
Base class for all platform-specific implementations of the sound system.
Definition: sound.h:108
SoundSystem(int maxSounds)
void LoadSounds(const char *firstArg,...)
Definition: scoped_ptr.h:53
void LoadSound(const char *fn, int index)
void SetMasterVolume(float volume)
float GetMasterVolume() const
void Play(int which)
bool IsValid() const
Definition: sound.h:50
A smart pointer with unique ownership – poor man's std::unique_ptr.
Macros and helper code to determine what subset of C++11/14/17 is available.
void ClearSound(int index)
Definition: bmpimage.h:46