BsFMODAudioClip.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsFMODPrerequisites.h"
  5. #include "Audio/BsAudioClip.h"
  6. #include "BsOggVorbisDecoder.h"
  7. #include <fmod.hpp>
  8. namespace bs
  9. {
  10. /** @addtogroup FMOD
  11. * @{
  12. */
  13. /** Contains data used for decompressing an Ogg Vorbis stream. */
  14. struct FMODOggDecompressorData
  15. {
  16. UINT32 readPos = 0;
  17. OggVorbisDecoder vorbisReader;
  18. const FMODAudioClip* clip = nullptr;
  19. };
  20. /** FMOD implementation of an AudioClip. */
  21. class FMODAudioClip : public AudioClip
  22. {
  23. public:
  24. FMODAudioClip(const SPtr<DataStream>& samples, UINT32 streamSize, UINT32 numSamples, const AUDIO_CLIP_DESC& desc);
  25. virtual ~FMODAudioClip();
  26. /**
  27. * Creates a new streaming sound. Only valid if the clip was created with AudioReadMode::Stream. Caller is
  28. * responsible for releasing the sound. Make sure to call releaseStreamingSound() when done.
  29. */
  30. FMOD::Sound* createStreamingSound() const;
  31. /** Releases any resources with a streaming sound (created with createStreamingSound()). */
  32. static void releaseStreamingSound(FMOD::Sound* sound);
  33. /** Returns FMOD sound representing this clip. Only valid for non-streaming clips. */
  34. FMOD::Sound* getSound() const { return mSound; }
  35. /**
  36. * Checks whether the audio clip requires a streaming sound retrieved via createStreamingSound(), or can the
  37. * basic sound retrieved via getSound() be used.
  38. */
  39. bool requiresStreaming() const;
  40. protected:
  41. /** @copydoc Resource::initialize */
  42. void initialize() override;
  43. /** @copydoc AudioClip::getSourceStream */
  44. SPtr<DataStream> getSourceStream(UINT32& size) override;
  45. FMOD::Sound* mSound;
  46. // These streams exist to save original audio data in case it's needed later (usually for saving with the editor, or
  47. // manual data manipulation). In normal usage (in-game) these will be null so no memory is wasted.
  48. SPtr<DataStream> mSourceStreamData;
  49. UINT32 mSourceStreamSize;
  50. };
  51. /** @} */
  52. }