SoundEngine.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. /*
  23. ===== IMPORTANT =====
  24. This is sample code demonstrating API, technology or techniques in development.
  25. Although this sample code has been reviewed for technical accuracy, it is not
  26. final. Apple is supplying this information to help you plan for the adoption of
  27. the technologies and programming interfaces described herein. This information
  28. is subject to change, and software implemented based on this sample code should
  29. be tested with final operating system software and final documentation. Newer
  30. versions of this sample code may be provided with future seeds of the API or
  31. technology. For information about updates to this and other developer
  32. documentation, view the New & Updated sidebars in subsequent documentation
  33. seeds.
  34. =====================
  35. File: SoundEngine.h
  36. Abstract: This C API is a sound engine intended for games and applications that
  37. want to do more than casual UI sounds playback e.g. background music track,
  38. multiple sound effects, stereo panning... while ensuring low-latency response at
  39. the same time.
  40. Version: 1.1
  41. Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
  42. ("Apple") in consideration of your agreement to the following terms, and your
  43. use, installation, modification or redistribution of this Apple software
  44. constitutes acceptance of these terms. If you do not agree with these terms,
  45. please do not use, install, modify or redistribute this Apple software.
  46. In consideration of your agreement to abide by the following terms, and subject
  47. to these terms, Apple grants you a personal, non-exclusive license, under
  48. Apple's copyrights in this original Apple software (the "Apple Software"), to
  49. use, reproduce, modify and redistribute the Apple Software, with or without
  50. modifications, in source and/or binary forms; provided that if you redistribute
  51. the Apple Software in its entirety and without modifications, you must retain
  52. this notice and the following text and disclaimers in all such redistributions
  53. of the Apple Software.
  54. Neither the name, trademarks, service marks or logos of Apple Inc. may be used
  55. to endorse or promote products derived from the Apple Software without specific
  56. prior written permission from Apple. Except as expressly stated in this notice,
  57. no other rights or licenses, express or implied, are granted by Apple herein,
  58. including but not limited to any patent rights that may be infringed by your
  59. derivative works or by other works in which the Apple Software may be
  60. incorporated.
  61. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
  62. WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  63. WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  64. PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  65. COMBINATION WITH YOUR PRODUCTS.
  66. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  67. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  68. GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  69. ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
  70. DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
  71. CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
  72. APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  73. Copyright (C) 2008 Apple Inc. All Rights Reserved.
  74. */
  75. /*============================================================================= =====================
  76. SoundEngine.h
  77. =============================================================================== ===================*/
  78. #ifndef SOUND_ENGINE_H
  79. #define SOUND_ENGINE_H
  80. extern"C"
  81. {
  82. namespace SoundEngine {
  83. #include <CoreAudio/CoreAudioTypes.h>
  84. #include <AudioToolbox/AudioToolbox.h>
  85. #include <OpenAL/al.h>
  86. //============================================================================= =====================
  87. //Sound Engine
  88. //============================================================================= =====================
  89. /*!
  90. @enum SoundEngine error codes
  91. @abstract These are the error codes returned from the SoundEngine API.
  92. @constant kSoundEngineErrUnitialized The SoundEngine has not been initialized. Use SoundEngine_Initialize().
  93. @constant kSoundEngineErrInvalidID The specified EffectID was not found. This can occur if the effect has not been loaded, or
  94. if an unloaded is trying to be accessed.
  95. @constant kSoundEngineErrFileNotFound The specified file was not found.
  96. @constant kSoundEngineErrInvalidFileFormat The format of the file is invalid. Effect data must be little-endian 8 or 16 bit LPCM.
  97. @constant kSoundEngineErrDeviceNotFound The output device was not found.
  98. */
  99. enum {
  100. kSoundEngineErrUnitialized = 1,
  101. kSoundEngineErrInvalidID = 2,
  102. kSoundEngineErrFileNotFound = 3,
  103. kSoundEngineErrInvalidFileFormat = 4,
  104. kSoundEngineErrDeviceNotFound = 5
  105. };
  106. /*!
  107. @function SoundEngine_Initialize
  108. @abstract Initializes and sets up the sound engine. Calling after a previous initialize will
  109. reset the state of the SoundEngine, with all previous effects and music tracks
  110. erased. Note: This is not required, loading an effect or background track will
  111. initialize as necessary.
  112. @param inMixerOutputRate
  113. & nbsp; A Float32 that represents the output sample rate of the mixer unit. Setting this to
  114. 0 will use the default rate (the sample rate of the device)
  115. @result A OSStatus indicating success or failure.
  116. */
  117. OSStatus SoundEngine_Initialize(Float32 inMixerOutputRate);
  118. /*!
  119. @function SoundEngine_Teardown
  120. @abstract Tearsdown the sound engine.
  121. @result A OSStatus indicating success or failure.
  122. */
  123. OSStatus SoundEngine_Teardown();
  124. /*!
  125. @function SoundEngine_SetMasterVolume
  126. @abstract Sets the overall volume of all sounds coming from the process
  127. @param inValue
  128. & nbsp; A Float32 that represents the level. The range is between 0.0 and 1.0 (inclusive).
  129. @result A OSStatus indicating success or failure.
  130. */
  131. OSStatus SoundEngine_SetMasterVolume(Float32 inValue);
  132. /*!
  133. @function SoundEngine_SetListenerPosition
  134. @abstract Sets the position of the listener in the 3D space
  135. @param inX
  136. & nbsp; A Float32 that represents the listener's position along the X axis.
  137. @param inY
  138. & nbsp; A Float32 that represents the listener's position along the Y axis.
  139. @param inZ
  140. & nbsp; A Float32 that represents the listener's position along the Z axis.
  141. @result A OSStatus indicating success or failure.
  142. */
  143. OSStatus SoundEngine_SetListenerPosition(Float32 inX, Float32 inY, Float32 inZ);
  144. /*!
  145. @function SoundEngine_SetListenerGain
  146. @abstract Sets the gain of the listener. Must be >= 0.0
  147. @param inValue
  148. & nbsp; A Float32 that represents the listener's gain
  149. @result A OSStatus indicating success or failure.
  150. */
  151. OSStatus SoundEngine_SetListenerGain(Float32 inValue);
  152. /*!
  153. @function SoundEngine_LoadBackgroundMusicTrack
  154. @abstract Tells the background music player which file to play
  155. @param inPath
  156. & nbsp; The absolute path to the file to play.
  157. @param inAddToQueue
  158. & nbsp; If true, file will be added to the current background music queue. If
  159. false, queue will be cleared and only loop the specified file.
  160. @param inLoadAtOnce
  161. & nbsp; If true, file will be loaded completely into memory. If false, data will be
  162. streamed from the file as needed. For games without large memory pressure and/or
  163. small background music files, this can save memory access and improve power efficiency
  164. @result A OSStatus indicating success or failure.
  165. */
  166. OSStatus SoundEngine_LoadBackgroundMusicTrack(const char* inPath, Boolean inAddToQueue, Boolean inLoadAtOnce);
  167. /*!
  168. @function SoundEngine_UnloadBackgroundMusicTrack
  169. @abstract Tells the background music player to release all resources and stop playing.
  170. @result A OSStatus indicating success or failure.
  171. */
  172. OSStatus SoundEngine_UnloadBackgroundMusicTrack();
  173. /*!
  174. @function SoundEngine_StartBackgroundMusic
  175. @abstract Tells the background music player to start playing.
  176. @result A OSStatus indicating success or failure.
  177. */
  178. OSStatus SoundEngine_StartBackgroundMusic();
  179. /*!
  180. @function SoundEngine_StopBackgroundMusic
  181. @abstract Tells the background music player to stop playing.
  182. @param inAddToQueue
  183. & nbsp; If true, playback will stop when all tracks have completed. If false, playback
  184. will stop immediately.
  185. @result A OSStatus indicating success or failure.
  186. */
  187. OSStatus SoundEngine_StopBackgroundMusic(Boolean inStopAtEnd);
  188. /*!
  189. @function SoundEngine_SetBackgroundMusicVolume
  190. @abstract Sets the volume for the background music player
  191. @param inValue
  192. & nbsp; A Float32 that represents the level. The range is between 0.0 and 1.0 (inclusive).
  193. @result A OSStatus indicating success or failure.
  194. */
  195. OSStatus SoundEngine_SetBackgroundMusicVolume(Float32 inValue);
  196. //-Mat for loading caf files, this creates a soundeffect and sets outEffectID to it's alGenBuffer ID
  197. bool LoadSoundFile(const char *inFilePath, UInt32 *outEffectID);
  198. }
  199. }
  200. #endif //SOUND_ENGINE_H