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 overflowBytesPerSample = 0;
  20. UINT32 samplesToRead = 0;
  21. bool error = false;
  22. };
  23. /** Used for reading FLAC audio files. */
  24. class OAFLACReader : public OAFileReader
  25. {
  26. public:
  27. OAFLACReader();
  28. ~OAFLACReader();
  29. /** @copydoc OAFileReader::open */
  30. bool open(const SPtr<DataStream>& stream, AudioFileInfo& info) override;
  31. /** @copydoc OAFileReader::seek */
  32. void seek(UINT32 offset) override;
  33. /** @copydoc OAFileReader::read */
  34. UINT32 read(UINT8* samples, UINT32 numSamples) override;
  35. /** @copydoc OAFileReader::isValid */
  36. bool isValid(const SPtr<DataStream>& stream) override;
  37. private:
  38. void close();
  39. FLAC__StreamDecoder* mDecoder;
  40. FLACDecoderData mData;
  41. };
  42. /** @} */
  43. }