forked from sjlongland/atinysynth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadsr.h
72 lines (63 loc) · 2.04 KB
/
adsr.h
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
/*!
* Polyphonic synthesizer for microcontrollers. ADSR Envelope generator.
* (C) 2017 Stuart Longland - Luciano Martorella
*
* 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., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#ifndef _ADSR_H
#define _ADSR_H
#include "sequencer.h"
#include <stdint.h>
#define ADSR_TIME_UNITS 0x40
/* ADSR states, in time units. MAX_TIME_UNIT is fixed, and terminates the envelope */
#define ADSR_STATE_INIT (0 + 1)
#define ADSR_STATE_SUSTAIN_START (6 + 1)
#define ADSR_STATE_DECAY_START (10 + 1)
// Release start is dynamic
#define ADSR_STATE_RELEASE_DURATION (6 * 8)
#define ADSR_STATE_END 0
#include "poly_cfg.h"
/*!
* ADSR Envelope Generator definition.
*/
struct adsr_env_def_t {
/*! Time scale, samples per unit. */
TIME_SCALE_T time_scale;
/*! When the release period starts, time units over the ADSR_TIME_UNITS scale */
uint8_t release_start;
};
/*!
* ADSR Envelope Generator data.
*/
struct adsr_env_gen_t {
/*! Definition */
struct adsr_env_def_t def;
/*! Time to next event in samples.*/
TIME_SCALE_T next_event;
/*! Current ADSR state / counter */
uint8_t state_counter;
/*! Present negative gain (0 is max, 1 is half amplitude, so -10dB, 2 is -20dB etc...) */
uint8_t gain;
};
/*!
* Configure the ADSR.
*/
void adsr_config(struct seq_frame_t* const frame);
/*!
* Compute the ADSR gain as bit shift count (0 is full amplitude, 1 is half, etc...)
*/
void adsr_next();
#endif