// ------------------------------------------------------------------------ // audiofx_envelope-modulation.cpp: Effects which modify/modulate signal // envelope // Copyright (C) 2000 Rob Coker, rcs@birch.net // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // ------------------------------------------------------------------------ #include #include #include "samplebuffer_iterators.h" #include "audiofx_envelope-modulation.h" #include "eca-debug.h" #include "eca-error.h" EFFECT_PULSE_GATE::EFFECT_PULSE_GATE (parameter_type freq_Hz, parameter_type onTime_percent) { set_parameter(1, freq_Hz); set_parameter(2, onTime_percent); currentTime = 0.0; incrTime = 1.0/samples_per_second(); } void EFFECT_PULSE_GATE::set_parameter(int param, parameter_type value) { MESSAGE_ITEM otemp; switch (param) { case 1: if (value > 0) { period = 1.0/value; // seconds } else { otemp << "(audiofx_envelope-modulation) WARNING! Frequency must be greater than 0! "; } break; case 2: if ((value > 0) && (value < 100)) { stopTime = (value/100.0)*period; // seconds } else { otemp << "(audiofx_envelope-modulation) WARNING! on time must be between 0 and 100 inclusive! "; } break; } ecadebug->msg(otemp.to_string()); } CHAIN_OPERATOR::parameter_type EFFECT_PULSE_GATE::get_parameter(int param) const { switch (param) { case 1: return(1.0/period); break; case 2: return (stopTime/period)*100.0; break; } return(0.0); } void EFFECT_PULSE_GATE::init(SAMPLE_BUFFER* sbuf) { i.init(sbuf); } void EFFECT_PULSE_GATE::process(void) { i.begin(); while(!i.end()) { currentTime += incrTime; if (currentTime > period) { currentTime = 0.0; } if (currentTime > stopTime) { *i.current() = 0.0; } i.next(); } }