SawtoothReader.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 SawtoothReader.h
  19. * @ingroup generator
  20. * The SawtoothReader class.
  21. */
  22. #include "IReader.h"
  23. AUD_NAMESPACE_BEGIN
  24. /**
  25. * This class is used for sawtooth tone playback.
  26. * The output format is in the 16 bit format and stereo, the sample rate can be
  27. * specified.
  28. * As the two channels both play the same the output could also be mono, but
  29. * in most cases this will result in having to resample for output, so stereo
  30. * sound is created directly.
  31. */
  32. class AUD_API SawtoothReader : public IReader
  33. {
  34. private:
  35. /**
  36. * The frequency of the sine wave.
  37. */
  38. float m_frequency;
  39. /**
  40. * The current position in samples.
  41. */
  42. int m_position;
  43. /**
  44. * The value of the current sample.
  45. */
  46. float m_sample;
  47. /**
  48. * The sample rate for the output.
  49. */
  50. const SampleRate m_sampleRate;
  51. // delete copy constructor and operator=
  52. SawtoothReader(const SawtoothReader&) = delete;
  53. SawtoothReader& operator=(const SawtoothReader&) = delete;
  54. public:
  55. /**
  56. * Creates a new reader.
  57. * \param frequency The frequency of the sine wave.
  58. * \param sampleRate The output sample rate.
  59. */
  60. SawtoothReader(float frequency, SampleRate sampleRate);
  61. /**
  62. * Sets the frequency of the wave.
  63. * @param frequency The new frequency in Hertz.
  64. */
  65. void setFrequency(float frequency);
  66. virtual bool isSeekable() const;
  67. virtual void seek(int position);
  68. virtual int getLength() const;
  69. virtual int getPosition() const;
  70. virtual Specs getSpecs() const;
  71. virtual void read(int & length, bool &eos, sample_t* buffer);
  72. };
  73. AUD_NAMESPACE_END