SoundEngine.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. //TODO: replace openal with opensl es
  79. /*
  80. #ifndef SOUND_ENGINE_H
  81. #define SOUND_ENGINE_H
  82. extern"C"
  83. {
  84. namespace SoundEngine {
  85. #include <CoreAudio/CoreAudioTypes.h>
  86. #include <AudioToolbox/AudioToolbox.h>
  87. #include <OpenAL/al.h>
  88. //============================================================================= =====================
  89. //Sound Engine
  90. //============================================================================= =====================
  91. // @enum SoundEngine error codes
  92. // @abstract These are the error codes returned from the SoundEngine API.
  93. // @constant kSoundEngineErrUnitialized The SoundEngine has not been initialized. Use SoundEngine_Initialize().
  94. // @constant kSoundEngineErrInvalidID The specified EffectID was not found. This can occur if the effect has not been loaded, or
  95. // if an unloaded is trying to be accessed.
  96. // @constant kSoundEngineErrFileNotFound The specified file was not found.
  97. // @constant kSoundEngineErrInvalidFileFormat The format of the file is invalid. Effect data must be little-endian 8 or 16 bit LPCM.
  98. // @constant kSoundEngineErrDeviceNotFound The output device was not found.
  99. enum {
  100. kSoundEngineErrUnitialized = 1,
  101. kSoundEngineErrInvalidID = 2,
  102. kSoundEngineErrFileNotFound = 3,
  103. kSoundEngineErrInvalidFileFormat = 4,
  104. kSoundEngineErrDeviceNotFound = 5
  105. };
  106. // @function SoundEngine_Initialize
  107. // @abstract Initializes and sets up the sound engine. Calling after a previous initialize will
  108. // reset the state of the SoundEngine, with all previous effects and music tracks
  109. // erased. Note: This is not required, loading an effect or background track will
  110. // initialize as necessary.
  111. // @param inMixerOutputRate
  112. // & nbsp; A Float32 that represents the output sample rate of the mixer unit. Setting this to
  113. // 0 will use the default rate (the sample rate of the device)
  114. // @result A OSStatus indicating success or failure.
  115. OSStatus SoundEngine_Initialize(Float32 inMixerOutputRate);
  116. // @function SoundEngine_Teardown
  117. // @abstract Tearsdown the sound engine.
  118. // @result A OSStatus indicating success or failure.
  119. OSStatus SoundEngine_Teardown();
  120. // @function SoundEngine_SetMasterVolume
  121. // @abstract Sets the overall volume of all sounds coming from the process
  122. // @param inValue
  123. // & nbsp; A Float32 that represents the level. The range is between 0.0 and 1.0 (inclusive).
  124. // @result A OSStatus indicating success or failure.
  125. OSStatus SoundEngine_SetMasterVolume(Float32 inValue);
  126. // @function SoundEngine_SetListenerPosition
  127. // @abstract Sets the position of the listener in the 3D space
  128. // @param inX
  129. // & nbsp; A Float32 that represents the listener's position along the X axis.
  130. // @param inY
  131. // & nbsp; A Float32 that represents the listener's position along the Y axis.
  132. // @param inZ
  133. // & nbsp; A Float32 that represents the listener's position along the Z axis.
  134. // @result A OSStatus indicating success or failure.
  135. OSStatus SoundEngine_SetListenerPosition(Float32 inX, Float32 inY, Float32 inZ);
  136. // @function SoundEngine_SetListenerGain
  137. // @abstract Sets the gain of the listener. Must be >= 0.0
  138. // @param inValue
  139. // & nbsp; A Float32 that represents the listener's gain
  140. // @result A OSStatus indicating success or failure.
  141. OSStatus SoundEngine_SetListenerGain(Float32 inValue);
  142. // @function SoundEngine_LoadBackgroundMusicTrack
  143. // @abstract Tells the background music player which file to play
  144. // @param inPath
  145. // & nbsp; The absolute path to the file to play.
  146. // @param inAddToQueue
  147. // & nbsp; If true, file will be added to the current background music queue. If
  148. // false, queue will be cleared and only loop the specified file.
  149. // @param inLoadAtOnce
  150. // & nbsp; If true, file will be loaded completely into memory. If false, data will be
  151. // streamed from the file as needed. For games without large memory pressure and/or
  152. // small background music files, this can save memory access and improve power efficiency
  153. // @result A OSStatus indicating success or failure.
  154. OSStatus SoundEngine_LoadBackgroundMusicTrack(const char* inPath, Boolean inAddToQueue, Boolean inLoadAtOnce);
  155. // @function SoundEngine_UnloadBackgroundMusicTrack
  156. // @abstract Tells the background music player to release all resources and stop playing.
  157. // @result A OSStatus indicating success or failure.
  158. OSStatus SoundEngine_UnloadBackgroundMusicTrack();
  159. // @function SoundEngine_StartBackgroundMusic
  160. // @abstract Tells the background music player to start playing.
  161. // @result A OSStatus indicating success or failure.
  162. OSStatus SoundEngine_StartBackgroundMusic();
  163. // @function SoundEngine_StopBackgroundMusic
  164. // @abstract Tells the background music player to stop playing.
  165. // @param inAddToQueue
  166. // & nbsp; If true, playback will stop when all tracks have completed. If false, playback
  167. // will stop immediately.
  168. // @result A OSStatus indicating success or failure.
  169. OSStatus SoundEngine_StopBackgroundMusic(Boolean inStopAtEnd);
  170. // @function SoundEngine_SetBackgroundMusicVolume
  171. // @abstract Sets the volume for the background music player
  172. // @param inValue
  173. // & nbsp; A Float32 that represents the level. The range is between 0.0 and 1.0 (inclusive).
  174. // @result A OSStatus indicating success or failure.
  175. OSStatus SoundEngine_SetBackgroundMusicVolume(Float32 inValue);
  176. //-Mat for loading caf files, this creates a soundeffect and sets outEffectID to it's alGenBuffer ID
  177. bool LoadSoundFile(const char *inFilePath, UInt32 *outEffectID);
  178. }
  179. }
  180. #endif //SOUND_ENGINE_H
  181. */