LinearResampleReader.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 LinearResampleReader.h
  19. * @ingroup respec
  20. * The LinearResampleReader class.
  21. */
  22. #include "respec/ResampleReader.h"
  23. #include "util/Buffer.h"
  24. AUD_NAMESPACE_BEGIN
  25. /**
  26. * This resampling reader does simple first-order hold resampling.
  27. */
  28. class AUD_API LinearResampleReader : public ResampleReader
  29. {
  30. private:
  31. /**
  32. * The reader channels.
  33. */
  34. Channels m_channels;
  35. /**
  36. * The position in the cache.
  37. */
  38. float m_cache_pos;
  39. /**
  40. * The sound output buffer.
  41. */
  42. Buffer m_buffer;
  43. /**
  44. * The input caching buffer.
  45. */
  46. Buffer m_cache;
  47. /**
  48. * Whether the cache contains valid data.
  49. */
  50. bool m_cache_ok;
  51. // delete copy constructor and operator=
  52. LinearResampleReader(const LinearResampleReader&) = delete;
  53. LinearResampleReader& operator=(const LinearResampleReader&) = delete;
  54. public:
  55. /**
  56. * Creates a resampling reader.
  57. * \param reader The reader to mix.
  58. * \param rate The target sampling rate.
  59. */
  60. LinearResampleReader(std::shared_ptr<IReader> reader, SampleRate rate);
  61. virtual void seek(int position);
  62. virtual int getLength() const;
  63. virtual int getPosition() const;
  64. virtual Specs getSpecs() const;
  65. virtual void read(int& length, bool& eos, sample_t* buffer);
  66. };
  67. AUD_NAMESPACE_END