| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #pragma once |
| 4 | |
| 5 | #include "BsOAPrerequisites.h" |
| 6 | #include "BsAudioDecoder.h" |
| 7 | #include "FLAC/stream_decoder.h" |
| 8 | |
| 9 | namespace bs |
| 10 | { |
| 11 | /** @addtogroup OpenAudio |
| 12 | * @{ |
| 13 | */ |
| 14 | |
| 15 | /** Data used by the FLAC decoder. */ |
| 16 | struct FLACDecoderData |
| 17 | { |
| 18 | SPtr<DataStream> stream; |
| 19 | UINT32 streamOffset = 0; |
| 20 | AudioDataInfo info; |
| 21 | UINT8* output = nullptr; |
| 22 | Vector<UINT8> overflow; |
| 23 | UINT32 samplesToRead = 0; |
| 24 | bool error = false; |
| 25 | }; |
| 26 | |
| 27 | /** Decodes FLAC audio data into raw PCM samples. */ |
| 28 | class FLACDecoder : public AudioDecoder |
| 29 | { |
| 30 | public: |
| 31 | FLACDecoder() = default; |
| 32 | ~FLACDecoder(); |
| 33 | |
| 34 | /** @copydoc AudioDecoder::open */ |
| 35 | bool open(const SPtr<DataStream>& stream, AudioDataInfo& info, UINT32 offset = 0) override; |
| 36 | |
| 37 | /** @copydoc AudioDecoder::seek */ |
| 38 | void seek(UINT32 offset) override; |
| 39 | |
| 40 | /** @copydoc AudioDecoder::read */ |
| 41 | UINT32 read(UINT8* samples, UINT32 numSamples) override; |
| 42 | |
| 43 | /** @copydoc AudioDecoder::isValid */ |
| 44 | bool isValid(const SPtr<DataStream>& stream, UINT32 offset = 0) override; |
| 45 | private: |
| 46 | /** Cleans up the FLAC decoder. */ |
| 47 | void close(); |
| 48 | |
| 49 | FLAC__StreamDecoder* mDecoder = nullptr; |
| 50 | FLACDecoderData mData; |
| 51 | }; |
| 52 | |
| 53 | /** @} */ |
| 54 | } |
| 55 | |