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