SineReader.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 SineReader.h
  19. * @ingroup generator
  20. * The SineReader class.
  21. */
  22. #include "IReader.h"
  23. AUD_NAMESPACE_BEGIN
  24. /**
  25. * This class is used for sine tone playback.
  26. * The sample rate can be specified, the signal is mono.
  27. */
  28. class AUD_API SineReader : public IReader
  29. {
  30. private:
  31. /**
  32. * The frequency of the sine wave.
  33. */
  34. float m_frequency;
  35. /**
  36. * The current position in samples.
  37. */
  38. int m_position;
  39. /**
  40. * The sample rate for the output.
  41. */
  42. const SampleRate m_sampleRate;
  43. // delete copy constructor and operator=
  44. SineReader(const SineReader&) = delete;
  45. SineReader& operator=(const SineReader&) = delete;
  46. public:
  47. /**
  48. * Creates a new reader.
  49. * \param frequency The frequency of the sine wave.
  50. * \param sampleRate The output sample rate.
  51. */
  52. SineReader(float frequency, SampleRate sampleRate);
  53. /**
  54. * Sets the frequency of the wave.
  55. * @param frequency The new frequency in Hertz.
  56. */
  57. void setFrequency(float frequency);
  58. virtual bool isSeekable() const;
  59. virtual void seek(int position);
  60. virtual int getLength() const;
  61. virtual int getPosition() const;
  62. virtual Specs getSpecs() const;
  63. virtual void read(int& length, bool& eos, sample_t* buffer);
  64. };
  65. AUD_NAMESPACE_END