IReader.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*******************************************************************************
  2. * Copyright 2009-2016 Jörg Müller
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. ******************************************************************************/
  16. #pragma once
  17. /**
  18. * @file IReader.h
  19. * @ingroup general
  20. * The IReader interface.
  21. */
  22. #include "respec/Specification.h"
  23. AUD_NAMESPACE_BEGIN
  24. /**
  25. * @interface IReader
  26. * This class represents a sound source as stream or as buffer which can be read
  27. * for example by another reader, a device or whatever.
  28. */
  29. class AUD_API IReader
  30. {
  31. public:
  32. /**
  33. * Destroys the reader.
  34. */
  35. virtual ~IReader() {}
  36. /**
  37. * Tells whether the source provides seeking functionality or not.
  38. * \warning This doesn't mean that the seeking always has to succeed.
  39. * \return Always returns true for readers of buffering types.
  40. */
  41. virtual bool isSeekable() const=0;
  42. /**
  43. * Seeks to a specific position in the source.
  44. * \param position The position to seek for measured in samples. To get
  45. * from a given time to the samples you simply have to multiply the
  46. * time value in seconds with the sample rate of the reader.
  47. * \warning This may work or not, depending on the actual reader.
  48. */
  49. virtual void seek(int position)=0;
  50. /**
  51. * Returns an approximated length of the source in samples.
  52. * \return The length as sample count. May be negative if unknown.
  53. */
  54. virtual int getLength() const=0;
  55. /**
  56. * Returns the position of the source as a sample count value.
  57. * \return The current position in the source. A negative value indicates
  58. * that the position is unknown.
  59. * \warning The value returned doesn't always have to be correct for readers,
  60. * especially after seeking.
  61. */
  62. virtual int getPosition() const=0;
  63. /**
  64. * Returns the specification of the reader.
  65. * \return The Specs structure.
  66. */
  67. virtual Specs getSpecs() const=0;
  68. /**
  69. * Request to read the next length samples out of the source.
  70. * The buffer supplied has the needed size.
  71. * \param[in,out] length The count of samples that should be read. Shall
  72. * contain the real count of samples after reading, in case
  73. * there were only fewer samples available.
  74. * A smaller value also indicates the end of the reader.
  75. * \param[out] eos End of stream, whether the end is reached or not.
  76. * \param[in] buffer The pointer to the buffer to read into.
  77. */
  78. virtual void read(int& length, bool& eos, sample_t* buffer)=0;
  79. };
  80. AUD_NAMESPACE_END