1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
/*
ZynAddSubFX - a software synthesizer
EnvelopeParams.C - Parameters for Envelope
Copyright (C) 2002-2005 Nasca Octavian Paul
Author: Nasca Octavian Paul
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License
as published by the Free Software Foundation.
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 (version 2) for more details.
You should have received a copy of the GNU General Public License (version 2)
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <math.h> // pow()
#include <assert.h>
#include "globals.h"
#include "envelope_parameters.h"
EnvelopeParams::EnvelopeParams()
{
int i;
for (i = 0 ; i < MAX_ENVELOPE_POINTS ; i++)
{
Penvdt[i] = 32;
m_values[i] = 64;
}
Penvdt[0] = 0; // no used
Penvsustain = 1;
Penvpoints = 1;
m_stretch = 64;
m_forced_release = true;
m_linear = false;
m_attack_duration_index = -1;
m_decay_duration_index = -1;
m_release_duration_index = -1;
m_attack_value_index = -1;
m_decay_value_index = -1;
m_sustain_value_index = -1;
m_release_value_index = -1;
}
EnvelopeParams::~EnvelopeParams()
{
}
REALTYPE EnvelopeParams::getdt(unsigned char i)
{
return (pow(2.0 , Penvdt[i] / 127.0 * 12.0) - 1.0) * 10.0; // miliseconds
}
void EnvelopeParams::set_point_value(int i, unsigned char value)
{
m_values_params[i] = value;
switch (m_mode)
{
case ZYN_ENVELOPE_MODE_ADSR:
if (m_linear)
{
m_values[i] = value / 127.0;
}
else
{
m_values[i] = (1.0 - value / 127.0) * MIN_ENVELOPE_DB;
}
break;
case ZYN_ENVELOPE_MODE_ASR:
m_values[i] = (pow(2,6.0 * fabs(value - 64.0) / 64.0) - 1.0) * 100.0;
if (value < 64)
{
m_values[i] = -m_values[i];
}
break;
case ZYN_ENVELOPE_MODE_ADSR_FILTER:
m_values[i] = (value - 64.0) / 64.0 * 6.0; // 6 octaves (filtru)
break;
case ZYN_ENVELOPE_MODE_ASR_BW:
m_values[i] = (value - 64.0) / 64.0 * 10;
break;
default:
assert(0);
}
}
void
EnvelopeParams::init_adsr(
unsigned char stretch,
bool forced_release,
char attack_duration,
char decay_duration,
char sustain_value,
char release_duration,
bool linear)
{
m_stretch = stretch;
m_forced_release = forced_release;
m_linear = linear;
m_mode = ZYN_ENVELOPE_MODE_ADSR;
Penvpoints = 4;
Penvsustain = 2;
set_point_value(0, 0);
m_attack_duration_index = 1;
Penvdt[1] = attack_duration;
set_point_value(1, 127);
Penvdt[2] = decay_duration;
m_decay_duration_index = 2;
set_point_value(2, sustain_value);
m_sustain_value_index = 2;
Penvdt[3] = release_duration;
m_release_duration_index = 3;
set_point_value(3, 0);
}
void
EnvelopeParams::init_asr(
unsigned char stretch,
bool forced_release,
char attack_value,
char attack_duration,
char release_value,
char release_duration)
{
m_stretch = stretch;
m_forced_release = forced_release;
m_mode = ZYN_ENVELOPE_MODE_ASR;
Penvpoints = 3;
Penvsustain = 1;
set_point_value(0, attack_value);
m_attack_value_index = 0;
Penvdt[1] = attack_duration;
m_attack_duration_index = 1;
set_point_value(1, 64);
set_point_value(2, release_value);
m_release_value_index = 2;
Penvdt[2] = release_duration;
m_release_duration_index = 2;
}
void
EnvelopeParams::init_adsr_filter(
unsigned char stretch,
bool forced_release,
char attack_value,
char attack_duration,
char decay_value,
char decay_duration,
char release_value,
char release_duration)
{
m_stretch = stretch;
m_forced_release = forced_release;
m_mode = ZYN_ENVELOPE_MODE_ADSR_FILTER;
Penvpoints = 4;
Penvsustain = 2;
set_point_value(0, attack_value);
m_attack_value_index = 0;
Penvdt[1] = attack_duration;
m_attack_duration_index = 1;
set_point_value(1, decay_value);
m_decay_value_index = 1;
Penvdt[2] = decay_duration;
m_decay_duration_index = 2;
set_point_value(2, 64);
Penvdt[3] = release_duration;
m_release_duration_index = 3;
set_point_value(3, release_value);
m_release_value_index = 3;
}
void
EnvelopeParams::init_asr_bw(
unsigned char stretch,
bool forced_release,
char attack_value,
char attack_duration,
char release_value,
char release_duration)
{
m_stretch = stretch;
m_forced_release = forced_release;
m_mode = ZYN_ENVELOPE_MODE_ASR_BW;
Penvpoints = 3;
Penvsustain = 1;
set_point_value(0, attack_value);
m_attack_value_index = 0;
set_point_value(1, 64);
Penvdt[1] = attack_duration;
m_attack_duration_index = 1;
Penvdt[2] = release_duration;
m_release_duration_index = 2;
set_point_value(2, release_value);
m_release_value_index = 2;
}
unsigned char
EnvelopeParams::get_value(
int index)
{
assert(index >= 0);
assert(index < MAX_ENVELOPE_POINTS);
return m_values_params[index];
}
void
EnvelopeParams::set_value(
int index,
unsigned char value)
{
assert(index >= 0);
assert(index < MAX_ENVELOPE_POINTS);
set_point_value(index, value);
}
unsigned char
EnvelopeParams::get_duration(
int index)
{
assert(index >= 0);
assert(index < MAX_ENVELOPE_POINTS);
return Penvdt[index];
}
void
EnvelopeParams::set_duration(
int index,
unsigned char duration)
{
assert(index >= 0);
assert(index < MAX_ENVELOPE_POINTS);
Penvdt[index] = duration;
}
|