BsFLACDecoder.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 "BsAudioDecoder.h"
  6. #include "FLAC/stream_decoder.h"
  7. namespace bs
  8. {
  9. /** @addtogroup OpenAudio
  10. * @{
  11. */
  12. /** Data used by the FLAC decoder. */
  13. struct FLACDecoderData
  14. {
  15. SPtr<DataStream> stream;
  16. UINT32 streamOffset = 0;
  17. AudioDataInfo info;
  18. UINT8* output = nullptr;
  19. Vector<UINT8> overflow;
  20. UINT32 samplesToRead = 0;
  21. bool error = false;
  22. };
  23. /** Decodes FLAC audio data into raw PCM samples. */
  24. class FLACDecoder : public AudioDecoder
  25. {
  26. public:
  27. FLACDecoder();
  28. ~FLACDecoder();
  29. /** @copydoc AudioDecoder::open */
  30. bool open(const SPtr<DataStream>& stream, AudioDataInfo& info, UINT32 offset = 0) override;
  31. /** @copydoc AudioDecoder::seek */
  32. void seek(UINT32 offset) override;
  33. /** @copydoc AudioDecoder::read */
  34. UINT32 read(UINT8* samples, UINT32 numSamples) override;
  35. /** @copydoc AudioDecoder::isValid */
  36. bool isValid(const SPtr<DataStream>& stream, UINT32 offset = 0) override;
  37. private:
  38. /** Cleans up the FLAC decoder. */
  39. void close();
  40. FLAC__StreamDecoder* mDecoder;
  41. FLACDecoderData mData;
  42. };
  43. /** @} */
  44. }