1
// ------------------------------------------------------------------------
2
// audiofx_envelope-modulation.cpp: Effects which modify/modulate signal
4
// Copyright (C) 2000 Rob Coker
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.
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.
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
20
// ------------------------------------------------------------------------
24
// 2003-08-21 Kai Vehmanen
25
// - Fixed a timing resolution bug in the envelope modulation code.
26
// This involved changing from float to fixed point presentation for
27
// the position counters to avoid loss of precision (led to unexpected
28
// drift in pulse timing).
29
// 2000-11-01 Rob Coker
32
// ------------------------------------------------------------------------
36
#include <kvu_message_item.h>
38
#include "samplebuffer_iterators.h"
39
#include "audiofx_envelope_modulation.h"
41
#include "eca-logger.h"
42
#include "eca-error.h"
44
EFFECT_ENV_MOD::~EFFECT_ENV_MOD(void)
48
EFFECT_PULSE_GATE::EFFECT_PULSE_GATE (parameter_t freq_Hz,
49
parameter_t onTime_percent)
51
set_parameter(1, freq_Hz);
52
set_parameter(2, onTime_percent);
61
EFFECT_PULSE_GATE::~EFFECT_PULSE_GATE(void)
65
void EFFECT_PULSE_GATE::set_samples_per_second(SAMPLE_SPECS::sample_rate_t v)
67
/* NOP, see audiofx.cpp:set_samples_per_second(); */
68
EFFECT_ENV_MOD::set_samples_per_second(v);
71
void EFFECT_PULSE_GATE::set_parameter(int param, parameter_t value)
78
period_rep = static_cast<long int>(1.0f / freq_rep * samples_per_second() + 0.5f); // samples
83
otemp << "(audiofx_envelope_modulation) WARNING! Frequency must be greater than 0! ";
84
ECA_LOG_MSG(ECA_LOGGER::user_objects, otemp.to_string());
89
if ((value > 0) && (value < 100))
92
on_from_rep = static_cast<long int>((on_time_rep / 100.0) * period_rep + 0.5f);
97
otemp << "(audiofx_envelope_modulation) WARNING! on time must be between 0 and 100 inclusive! ";
98
ECA_LOG_MSG(ECA_LOGGER::user_objects, otemp.to_string());
104
CHAIN_OPERATOR::parameter_t EFFECT_PULSE_GATE::get_parameter(int param) const
111
return (on_time_rep);
116
void EFFECT_PULSE_GATE::init(SAMPLE_BUFFER* sbuf)
119
set_channels(sbuf->number_of_channels());
120
EFFECT_ENV_MOD::init(sbuf);
123
void EFFECT_PULSE_GATE::process(void)
125
i.begin(); // iterate through all samples, one sample-frame at a
126
// time (interleaved)
129
if (current_rep >= period_rep) {
132
if (current_rep > on_from_rep) {
133
for(int n = 0; n < channels(); n++) {
141
EFFECT_PULSE_GATE_BPM::EFFECT_PULSE_GATE_BPM (parameter_t bpm,
142
parameter_t ontime_percent)
144
set_parameter(1, bpm);
145
set_parameter(2, ontime_percent);
148
EFFECT_PULSE_GATE_BPM::~EFFECT_PULSE_GATE_BPM(void)
152
void EFFECT_PULSE_GATE_BPM::set_parameter(int param, parameter_t value)
156
pulsegate_rep.set_parameter(1, value / 60.0f);
159
pulsegate_rep.set_parameter(2, value);
164
CHAIN_OPERATOR::parameter_t EFFECT_PULSE_GATE_BPM::get_parameter(int param) const {
167
return (pulsegate_rep.get_parameter(1) * 60.0f);
170
return (pulsegate_rep.get_parameter(2));
176
void EFFECT_PULSE_GATE_BPM::init(SAMPLE_BUFFER* sbuf)
178
pulsegate_rep.init(sbuf);
179
EFFECT_ENV_MOD::init(sbuf);
182
void EFFECT_PULSE_GATE_BPM::process(void) { pulsegate_rep.process(); }
184
void EFFECT_PULSE_GATE_BPM::set_samples_per_second(SAMPLE_SPECS::sample_rate_t v)
186
pulsegate_rep.set_samples_per_second(v);
187
EFFECT_ENV_MOD::set_samples_per_second(v);
190
EFFECT_TREMOLO::EFFECT_TREMOLO (parameter_t freq_bpm,
191
parameter_t depth_percent)
193
set_parameter(1, freq_bpm);
194
set_parameter(2, depth_percent);
198
EFFECT_TREMOLO::~EFFECT_TREMOLO(void)
202
void EFFECT_TREMOLO::set_parameter(int param, parameter_t value)
208
freq = value/(2*60); // convert from bpm to Hz
213
otemp << "(audiofx_envelope_modulation) WARNING! bpm must be greater than 0! ";
214
ECA_LOG_MSG(ECA_LOGGER::info, otemp.to_string());
218
depth = (value/100.0); // from percent to fraction
223
CHAIN_OPERATOR::parameter_t EFFECT_TREMOLO::get_parameter(int param) const
236
void EFFECT_TREMOLO::init(SAMPLE_BUFFER* sbuf)
239
set_channels(sbuf->number_of_channels());
240
incrTime = 1.0/samples_per_second();
241
EFFECT_ENV_MOD::init(sbuf);
244
void EFFECT_TREMOLO::process(void)
246
i.begin(); // iterate through all samples, one sample-frame at a
247
// time (interleaved)
250
currentTime += incrTime;
251
double envelope = (1-depth)+depth*fabs(sin(2*3.1416*currentTime*freq));
256
for(int n = 0; n < channels(); n++)
258
*i.current(n) *= envelope;