BsOAFLACReader.h 1.3 KB

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