ADSR.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 ADSR.h
  19. * @ingroup fx
  20. * The ADSR class.
  21. */
  22. #include "fx/Effect.h"
  23. AUD_NAMESPACE_BEGIN
  24. /**
  25. * The ADSR effect implements the Attack-Delay-Sustain-Release behaviour of a sound.
  26. */
  27. class AUD_API ADSR : public Effect
  28. {
  29. private:
  30. /**
  31. * Attack time.
  32. */
  33. float m_attack;
  34. /**
  35. * Decay time.
  36. */
  37. float m_decay;
  38. /**
  39. * Sustain level.
  40. */
  41. float m_sustain;
  42. /**
  43. * Release time.
  44. */
  45. float m_release;
  46. // delete copy constructor and operator=
  47. ADSR(const ADSR&) = delete;
  48. ADSR& operator=(const ADSR&) = delete;
  49. public:
  50. /**
  51. * Creates a new ADSR object.
  52. * @param sound The sound to apply this effect to.
  53. * @param attack The attack time in seconds.
  54. * @param decay The decay time in seconds.
  55. * @param sustain The sustain level as linear volume.
  56. * @param release The release time in seconds.
  57. */
  58. ADSR(std::shared_ptr<ISound> sound, float attack, float decay, float sustain, float release);
  59. /**
  60. * Returns the attack time.
  61. * @return The attack time in seconds.
  62. */
  63. float getAttack() const;
  64. /**
  65. * Sets the attack time.
  66. * @param attack The attack time in seconds.
  67. */
  68. void setAttack(float attack);
  69. /**
  70. * Returns the decay time.
  71. * @return The decay time in seconds.
  72. */
  73. float getDecay() const;
  74. /**
  75. * Sets the decay time.
  76. * @param decay The decay time in seconds.
  77. */
  78. void setDecay(float decay);
  79. /**
  80. * Returns the sustain level.
  81. * @return The sustain level in linear volume.
  82. */
  83. float getSustain() const;
  84. /**
  85. * Sets the sustain level.
  86. * @param sustain The sustain level in linear volume.
  87. */
  88. void setSustain(float sustain);
  89. /**
  90. * Returns the release time.
  91. * @return The release time in seconds.
  92. */
  93. float getRelease() const;
  94. /**
  95. * Sets the release time.
  96. * @param release The release time in seconds.
  97. */
  98. void setRelease(float release);
  99. virtual std::shared_ptr<IReader> createReader();
  100. };
  101. AUD_NAMESPACE_END