BsAudioDecoder.h 2.1 KB

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