1 /** 2 * Simple Compressor 3 * 4 * Copyright (C) 2006-2018 Teru Kamogashira 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 */ 20 21 #include "freeverb/scomp.hpp" 22 #include "freeverb/fv3_type_float.h" 23 #include "freeverb/fv3_ns_start.h" 24 FV3_(scomp)25FV3_(scomp)::FV3_(scomp)() 26 { 27 setRMS(0); setAttack(0); setRelease(0); 28 Threshold = -10; SoftKnee = 0; // for first init 29 setThreshold(-10); setSoftKnee(0); setRatio(1); 30 env = 0; 31 } 32 FV3_(scomp)33fv3_float_t FV3_(scomp)::getEnv() 34 { 35 return env; 36 } 37 FV3_(scomp)38void FV3_(scomp)::mute() 39 { 40 Rms.mute(); 41 env = 0; 42 } 43 FV3_(scomp)44long FV3_(scomp)::getRMS() 45 { 46 return Rms.getsize(); 47 } 48 FV3_(scomp)49void FV3_(scomp)::setRMS(long value) 50 { 51 Rms.setsize(value); 52 } 53 FV3_(scomp)54fv3_float_t FV3_(scomp)::getAttack() 55 { 56 return Attack; 57 } 58 FV3_(scomp)59void FV3_(scomp)::setAttack(fv3_float_t value) 60 { 61 Attack = value; 62 if(Attack > 0) 63 attackDelta = std::exp(-1.0/Attack); 64 else 65 attackDelta = 0; 66 } 67 FV3_(scomp)68fv3_float_t FV3_(scomp)::getRelease() 69 { 70 return Release; 71 } 72 FV3_(scomp)73void FV3_(scomp)::setRelease(fv3_float_t value) 74 { 75 Release = value; 76 if(Release > 0) 77 releaseDelta = std::exp(-1.0/Release); 78 else 79 releaseDelta = 0.0; 80 } 81 FV3_(scomp)82fv3_float_t FV3_(scomp)::getThreshold() 83 { 84 return Threshold; 85 } 86 FV3_(scomp)87fv3_float_t FV3_(scomp)::getSoftKnee() 88 { 89 return SoftKnee; 90 } 91 FV3_(scomp)92void FV3_(scomp)::setThreshold(fv3_float_t value) 93 { 94 Threshold = value; 95 threshold_log = std::log(Threshold); 96 update(); 97 } 98 FV3_(scomp)99void FV3_(scomp)::setSoftKnee(fv3_float_t dB) 100 { 101 SoftKnee = dB; 102 log_soft = std::log(FV3_(utils)::dB2R(SoftKnee)); 103 update(); 104 } 105 FV3_(scomp)106void FV3_(scomp)::update() 107 { 108 lowClip = Threshold*FV3_(utils)::dB2R(-SoftKnee); 109 highClip = Threshold*FV3_(utils)::dB2R(SoftKnee); 110 } 111 FV3_(scomp)112fv3_float_t FV3_(scomp)::getRatio() 113 { 114 return Ratio; 115 } 116 FV3_(scomp)117void FV3_(scomp)::setRatio(fv3_float_t value) 118 { 119 Ratio = value; 120 r = -(1-1/Ratio); 121 } 122 123 #include "freeverb/fv3_ns_end.h" 124