Deluge Firmware
1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
env.h
1
/*
2
* Copyright 2017 Pascal Gauthier.
3
* Copyright 2012 Google Inc.
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*/
17
18
#pragma once
19
20
#include <stdint.h>
21
22
// DX7 envelope generation
23
24
#define ACCURATE_ENVELOPE
25
26
class
EnvParams
{
27
public
:
28
uint8_t rates[4];
29
uint8_t levels[4];
30
};
31
32
class
Env
{
33
public
:
34
// The rates and levels arrays are calibrated to match the Dx7 parameters
35
// (ie, value 0..99). The outlevel parameter is calibrated in microsteps
36
// (ie units of approx .023 dB), with 99 * 32 = nominal full scale. The
37
// rate_scaling parameter is in qRate units (ie 0..63).
38
void
init(
const
EnvParams
& p,
int
outlevel,
int
rate_scaling);
39
void
update(
const
EnvParams
& p,
int
outlevel,
int
rate_scaling);
40
41
// Result is in Q24/doubling log format. Also, result is subsampled
42
// for every N samples.
43
// A couple more things need to happen for this to be used as a gain
44
// value. First, the # of outputs scaling needs to be applied. Also,
45
// modulation.
46
// Then, of course, log to linear.
47
int32_t getsample(
const
EnvParams
& p,
int
n,
int
extra_rate);
48
void
keydown(
const
EnvParams
& p,
bool
down);
49
static
int
scaleoutlevel(
int
outlevel);
50
void
getPosition(
char
* step);
51
52
static
void
init_sr(
double
sample_rate);
53
void
transfer(
Env
& src);
54
55
private
:
56
// PG: This code is normalized to 44100, need to put a multiplier
57
// if we are not using 44100.
58
static
uint32_t sr_multiplier;
59
60
// Level is stored so that 2^24 is one doubling, ie 16 more bits than
61
// the DX7 itself (fraction is stored in level rather than separate
62
// counter)
63
int32_t level_;
64
int
targetlevel_;
65
int
ix_;
66
int
inc_;
67
#ifdef ACCURATE_ENVELOPE
68
int
staticcount_;
69
#endif
70
71
int
outlevel_;
72
int
rate_scaling_;
73
bool
down_;
74
bool
rising_;
75
76
void
advance(
const
EnvParams
& p,
int
newix,
int
extra_rate);
77
};
EnvParams
Definition
env.h:26
Env
Definition
env.h:32