AudioAsset.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #ifndef _AUDIO_ASSET_H_
  23. #define _AUDIO_ASSET_H_
  24. #ifndef _PLATFORMAUDIO_H_
  25. #include "platform/platformAudio.h"
  26. #endif
  27. #ifndef _AUDIOBUFFER_H_
  28. #include "audio/audioBuffer.h"
  29. #endif
  30. #ifndef _BITSTREAM_H_
  31. #include "io/bitStream.h"
  32. #endif
  33. #ifndef _SIMBASE_H_
  34. #include "sim/simBase.h"
  35. #endif
  36. #ifndef _ASSET_BASE_H_
  37. #include "assets/assetBase.h"
  38. #endif
  39. #ifndef _UTILITY_H_
  40. #include "2d/core/Utility.h"
  41. #endif
  42. //----------------------------------------------------------------------------
  43. DefineConsoleType( TypeAudioAssetPtr )
  44. //----------------------------------------------------------------------------
  45. class AudioAsset: public AssetBase
  46. {
  47. private:
  48. typedef AssetBase Parent;
  49. StringTableEntry mAudioFile;
  50. Audio::Description mDescription;
  51. public:
  52. AudioAsset();
  53. static void initPersistFields();
  54. virtual void copyTo(SimObject* object);
  55. void setAudioFile( const char* pAudioFile );
  56. inline StringTableEntry getAudioFile( void ) const { return mAudioFile; }
  57. void setVolume( const F32 volume );
  58. inline F32 getVolume( void ) const { return mDescription.mVolume; }
  59. void setVolumeChannel( const S32 volumeChannel );
  60. inline S32 getVolumeChannel( void ) const { return mDescription.mVolumeChannel; }
  61. void setLooping( const bool looping );
  62. inline bool getLooping( void ) const { return mDescription.mIsLooping; }
  63. void setStreaming( const bool streaming );
  64. inline bool getStreaming( void ) const { return mDescription.mIsStreaming; }
  65. void setDescription( const Audio::Description& audioDescription );
  66. inline const Audio::Description& getAudioDescription( void ) const { return mDescription; }
  67. DECLARE_CONOBJECT(AudioAsset);
  68. protected:
  69. virtual void initializeAsset( void );
  70. /// Taml callbacks.
  71. virtual void onTamlPreWrite( void );
  72. virtual void onTamlPostWrite( void );
  73. protected:
  74. static bool setAudioFile( void* obj, const char* data ) { static_cast<AudioAsset*>(obj)->setAudioFile(data); return false; }
  75. static const char* getAudioFile(void* obj, const char* data) { return static_cast<AudioAsset*>(obj)->getAudioFile(); }
  76. static bool setVolume( void* obj, const char* data ) { static_cast<AudioAsset*>(obj)->setVolume(dAtof(data)); return false; }
  77. static bool writeVolume( void* obj, StringTableEntry pFieldName ) { return mNotEqual(static_cast<AudioAsset*>(obj)->getVolume(), 1.0f); }
  78. static bool setVolumeChannel( void* obj, const char* data ) { static_cast<AudioAsset*>(obj)->setVolumeChannel(dAtoi(data)); return false; }
  79. static bool writeVolumeChannel( void* obj, StringTableEntry pFieldName ) { return static_cast<AudioAsset*>(obj)->getVolumeChannel() != 0; }
  80. static bool setLooping( void* obj, const char* data ) { static_cast<AudioAsset*>(obj)->setLooping(dAtob(data)); return false; }
  81. static bool writeLooping( void* obj, StringTableEntry pFieldName ) { return static_cast<AudioAsset*>(obj)->getLooping() == true; }
  82. static bool setStreaming( void* obj, const char* data ) { static_cast<AudioAsset*>(obj)->setStreaming(dAtob(data)); return false; }
  83. static bool writeStreaming( void* obj, StringTableEntry pFieldName ) { return static_cast<AudioAsset*>(obj)->getStreaming() == true; }
  84. };
  85. #endif // _AUDIO_ASSET_H_