SoundWorld.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "Types.h"
  25. #define MAX_SOUND_INSTANCES 64
  26. namespace crown
  27. {
  28. /// Global audio-related functions
  29. namespace audio_system
  30. {
  31. /// Initializes the audio system.
  32. /// This is the place where to create and initialize per-application objects.
  33. void init();
  34. /// It should reverse the actions performed by audio_system::init().
  35. void shutdown();
  36. } // namespace audio_system
  37. class Allocator;
  38. struct Vector3;
  39. struct Matrix4x4;
  40. struct SoundResource;
  41. typedef Id SoundInstanceId;
  42. class SoundWorld
  43. {
  44. public:
  45. virtual ~SoundWorld() {};
  46. /// Plays the sound @a name at the given @a volume [0 .. 1].
  47. /// If loop is true the sound will be played looping.
  48. virtual SoundInstanceId play(const char* name, bool loop, float volume, const Vector3& pos) = 0;
  49. /// Stops the sound with the given @a id.
  50. /// After this call, the instance will be destroyed.
  51. virtual void stop(SoundInstanceId id) = 0;
  52. /// Returns wheter the sound @a id is playing.
  53. virtual bool is_playing(SoundInstanceId id) = 0;
  54. /// Stops all the sounds in the world.
  55. virtual void stop_all() = 0;
  56. /// Pauses all the sounds in the world
  57. virtual void pause_all() = 0;
  58. /// Resumes all previously paused sounds in the world.
  59. virtual void resume_all() = 0;
  60. /// Sets the @a positions (in world space) of @a count sound instances @a ids.
  61. virtual void set_sound_positions(uint32_t count, const SoundInstanceId* ids, const Vector3* positions) = 0;
  62. /// Sets the @a ranges (in meters) of @a count sound instances @a ids.
  63. virtual void set_sound_ranges(uint32_t count, const SoundInstanceId* ids, const float* ranges) = 0;
  64. /// Sets the @a volumes of @a count sound instances @a ids.
  65. virtual void set_sound_volumes(uint32_t count, const SoundInstanceId* ids, const float* volumes) = 0;
  66. virtual void reload_sounds(SoundResource* old_sr, SoundResource* new_sr) = 0;
  67. /// Sets the @a pose of the listener in world space.
  68. virtual void set_listener_pose(const Matrix4x4& pose) = 0;
  69. virtual void update() = 0;
  70. static SoundWorld* create(Allocator& a);
  71. static void destroy(Allocator& a, SoundWorld* sw);
  72. };
  73. } // namespace crown