1
// ------------------------------------------------------------------------
2
// audiofx_misc.cpp: Miscellanous effect processing routines.
3
// Copyright (C) 1999-2003,2005 Kai Vehmanen
6
// eca-style-version: 3
8
// This program is free software; you can redistribute it and/or modify
9
// it under the terms of the GNU General Public License as published by
10
// the Free Software Foundation; either version 2 of the License, or
11
// (at your option) any later version.
13
// This program is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
// GNU General Public License for more details.
18
// You should have received a copy of the GNU General Public License
19
// along with this program; if not, write to the Free Software
20
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
// ------------------------------------------------------------------------
27
#include <kvu_numtostr.h>
28
#include <kvu_utils.h>
30
#include "samplebuffer_iterators.h"
31
#include "eca-operator.h"
32
#include "audiofx_misc.h"
33
#include "eca-logger.h"
34
#include "eca-error.h"
36
EFFECT_DCFIX::EFFECT_DCFIX (void)
40
EFFECT_DCFIX::EFFECT_DCFIX (const EFFECT_DCFIX& x)
42
deltafixes_rep = x.deltafixes_rep;
46
void EFFECT_DCFIX::set_parameter(int param, CHAIN_OPERATOR::parameter_t value)
49
deltafixes_rep.resize(static_cast<int>(value));
51
else if (param > 1 && param - 2 < static_cast<int>(deltafixes_rep.size())) {
52
deltafixes_rep[param - 2] = value;
56
CHAIN_OPERATOR::parameter_t EFFECT_DCFIX::get_parameter(int param) const
58
parameter_t result = 0.0f;
61
result = static_cast<parameter_t>(deltafixes_rep.size());
63
else if (param > 1 && param - 2 < static_cast<int>(deltafixes_rep.size())) {
64
result = deltafixes_rep[param - 2];
70
string EFFECT_DCFIX::parameter_names(void) const
72
std::vector<std::string> t;
74
t.push_back("channel-count");
76
for(int n = 0; n < static_cast<int>(deltafixes_rep.size()); n++) {
77
t.push_back("delta-ch" + kvu_numtostr(n + 1));
80
return kvu_vector_to_string(t, ",");
83
void EFFECT_DCFIX::parameter_description(int param, struct PARAM_DESCRIPTION *pd) const
85
OPERATOR::parameter_description(param, pd);
88
void EFFECT_DCFIX::init(SAMPLE_BUFFER *insample)
91
set_channels(insample->number_of_channels());
92
if (channels() > static_cast<int>(deltafixes_rep.size())) {
93
deltafixes_rep.resize(channels());
97
void EFFECT_DCFIX::process(void)
99
for(int n = 0; n < channels(); n++) {
101
while(!i_rep.end()) {
102
*i_rep.current() = *i_rep.current() + deltafixes_rep[n];
108
const int EFFECT_PITCH_SHIFT::resample_low_limit = 8;
110
EFFECT_PITCH_SHIFT::EFFECT_PITCH_SHIFT (const EFFECT_PITCH_SHIFT& x)
112
pmod_rep = x.pmod_rep;
113
target_rate_rep = x.target_rate_rep;
117
void EFFECT_PITCH_SHIFT::set_parameter(int param, CHAIN_OPERATOR::parameter_t value)
121
double lowlimit = 1.0f / EFFECT_PITCH_SHIFT::resample_low_limit * 100.0f;
123
if (value <= lowlimit) {
124
ECA_LOG_MSG(ECA_LOGGER::info,
125
"WARNING! Shift-% must be greater than " +
126
kvu_numtostr(lowlimit) +
127
"%! Limiting to the low-limit.");
133
if (sbuf_repp != 0) {
134
target_rate_rep = static_cast<long int>(samples_per_second() * 100.0 / pmod_rep);
143
CHAIN_OPERATOR::parameter_t EFFECT_PITCH_SHIFT::get_parameter(int param) const
152
void EFFECT_PITCH_SHIFT::parameter_description(int param, struct PARAM_DESCRIPTION *pd) const
154
OPERATOR::parameter_description(param, pd);
159
pd->default_value = 100.0f;
160
pd->bounded_above = true;
161
/* 100x speed-up is a sensible upper limit */
162
pd->upper_bound = 10000.0f;
163
pd->bounded_below = true;
164
/* ~8x slow-down is a sensible lower limit: */
165
pd->lower_bound = 1.0f / EFFECT_PITCH_SHIFT::resample_low_limit * 100.0f;
170
void EFFECT_PITCH_SHIFT::init(SAMPLE_BUFFER *insample)
172
sbuf_repp = insample;
173
// truncate, not round, to integer
174
target_rate_rep = static_cast<long int>((samples_per_second() * 100.0 / pmod_rep));
176
long int lowlimit = sbuf_repp->length_in_samples() * EFFECT_PITCH_SHIFT::resample_low_limit;
177
sbuf_repp->reserve_length_in_samples(lowlimit);
178
ECA_LOG_MSG(ECA_LOGGER::system_objects,
179
"Setting resampling lowlimit to " +
180
kvu_numtostr(lowlimit) + " bytes.");
182
sbuf_repp->resample_init_memory(samples_per_second(), target_rate_rep);
183
sbuf_repp->resample_set_quality(50);
184
ECA_LOG_MSG(ECA_LOGGER::user_objects, "Resampling from " +
185
kvu_numtostr(samples_per_second()) +
187
kvu_numtostr(target_rate_rep) + ".");
190
void EFFECT_PITCH_SHIFT::release(void)
195
void EFFECT_PITCH_SHIFT::process(void)
197
sbuf_repp->resample(samples_per_second(), target_rate_rep);
200
long int EFFECT_PITCH_SHIFT::max_output_samples(long int i_samples) const
202
DBC_CHECK(sbuf_repp != 0);
203
return static_cast<long int>(static_cast<double>(target_rate_rep) /
204
samples_per_second() *
208
EFFECT_AUDIO_STAMP::EFFECT_AUDIO_STAMP(void)
213
EFFECT_AUDIO_STAMP::EFFECT_AUDIO_STAMP(const EFFECT_AUDIO_STAMP& arg)
218
void EFFECT_AUDIO_STAMP::set_parameter(int param, CHAIN_OPERATOR::parameter_t value)
222
set_id(static_cast<int>(value));
227
CHAIN_OPERATOR::parameter_t EFFECT_AUDIO_STAMP::get_parameter(int param) const
231
return static_cast<parameter_t>(id());
236
void EFFECT_AUDIO_STAMP::parameter_description(int param, struct PARAM_DESCRIPTION *pd) const
238
OPERATOR::parameter_description(param, pd);
242
pd->default_value = 1;
243
pd->description = get_parameter_name(param);
244
pd->bounded_above = false;
245
pd->bounded_below = true;
252
void EFFECT_AUDIO_STAMP::init(SAMPLE_BUFFER *insample)
254
sbuf_repp = insample;
257
void EFFECT_AUDIO_STAMP::release(void)
262
void EFFECT_AUDIO_STAMP::process(void)
265
// std::cerr << "Storing audio stamp with id " << id() << "." << std::endl;