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 | |
7 | namespace bs |
8 | { |
9 | /** @addtogroup OpenAudio |
10 | * @{ |
11 | */ |
12 | |
13 | /** Interface used for implementations that parse audio formats into a set of PCM samples. */ |
14 | class AudioDecoder |
15 | { |
16 | public: |
17 | virtual ~AudioDecoder() = default; |
18 | |
19 | /** |
20 | * Attempts to open audio data from the provided stream. Must be called before any reads or seeks. |
21 | * |
22 | * @param[in] stream Data stream audio data is stored in. |
23 | * @param[out] info Output information describing meta-data of the audio in the stream. |
24 | * @param[in] offset Offset at which audio data in the stream begins, in bytes. |
25 | * @return True if the data is valid, false otherwise. |
26 | */ |
27 | virtual bool open(const SPtr<DataStream>& stream, AudioDataInfo& info, UINT32 offset = 0) = 0; |
28 | |
29 | /** |
30 | * Moves the read pointer to the specified offset. Any further read() calls will read from this location. User must |
31 | * ensure not to seek past the end of the data. |
32 | * |
33 | * @param[in] offset Offset to move the pointer in. In number of samples. |
34 | */ |
35 | virtual void seek(UINT32 offset) = 0; |
36 | |
37 | /** |
38 | * Reads a set of samples from the audio data. |
39 | * |
40 | * @param[out] samples Pre-allocated buffer to store the samples in. |
41 | * @param[in] numSamples Number of samples to read. |
42 | * @return Number of samples that were actually read (can be less than requested if the more data |
43 | * in the stream). |
44 | * |
45 | * @note All values are returned as signed values. |
46 | */ |
47 | virtual UINT32 read(UINT8* samples, UINT32 numSamples) = 0; |
48 | |
49 | /** |
50 | * Checks if the data in the provided stream valid audio data for the current format. You should check this before |
51 | * calling open(). |
52 | * |
53 | * @param[in] stream Stream to check. |
54 | * @param[in] offset Offset at which audio data in the stream begins, in bytes. |
55 | * @return True if the data is valid, false otherwise. |
56 | */ |
57 | virtual bool isValid(const SPtr<DataStream>& stream, UINT32 offset = 0) = 0; |
58 | }; |
59 | |
60 | /** @} */ |
61 | } |