BsOAAudioClip.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsOAPrerequisites.h"
  5. #include "BsAudioClip.h"
  6. #include "BsOggVorbisDecoder.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup OpenAudio
  10. * @{
  11. */
  12. /** OpenAudio implementation of an AudioClip. */
  13. class OAAudioClip : public AudioClip
  14. {
  15. public:
  16. OAAudioClip(const SPtr<DataStream>& samples, UINT32 streamSize, UINT32 numSamples, const AUDIO_CLIP_DESC& desc);
  17. virtual ~OAAudioClip();
  18. /**
  19. * Returns audio samples in PCM format, channel data interleaved. Only available if the audio data has been created
  20. * with AudioReadMode::Stream, AudioReadMode::LoadCompressed (and the format is compressed), or if @p keepSourceData
  21. * was enabled on creation.
  22. *
  23. * @param[in] samples Previously allocated buffer to contain the samples.
  24. * @param[in] offset Offset in number of samples at which to start reading (should be a multiple of number
  25. * of channels).
  26. * @param[in] count Number of samples to read (should be a multiple of number of channels).
  27. *
  28. * @note Implementation must be thread safe as this will get called from audio streaming thread.
  29. */
  30. void getSamples(UINT8* samples, UINT32 offset, UINT32 count) const;
  31. /** @name Internal
  32. * @{
  33. */
  34. /** Returns the internal OpenAL buffer. Only valid if the audio clip was created without AudioReadMode::Stream. */
  35. UINT32 _getOpenALBuffer() const { return mBufferId; }
  36. /** @} */
  37. protected:
  38. /** @copydoc Resource::initialize */
  39. void initialize() override;
  40. /** @copydoc AudioClip::getSourceStream */
  41. SPtr<DataStream> getSourceStream(UINT32& size) override;
  42. private:
  43. mutable Mutex mMutex;
  44. mutable OggVorbisDecoder mVorbisReader;
  45. bool mNeedsDecompression;
  46. UINT32 mBufferId;
  47. // These streams exist to save original audio data in case it's needed later (usually for saving with the editor, or
  48. // manual data manipulation). In normal usage (in-game) these will be null so no memory is wasted.
  49. SPtr<DataStream> mSourceStreamData;
  50. UINT32 mSourceStreamSize;
  51. };
  52. /** @} */
  53. }