1
0
mirror of https://github.com/sjlongland/atinysynth.git synced 2025-10-24 15:29:32 +10:00

adsr: Add functions for configuring the ADSR.

This commit is contained in:
Stuart Longland 2017-04-09 08:17:03 +10:00
parent 286caebd67
commit 67bf582ee4
Signed by: stuartl
GPG Key ID: F954BBBB7948D546
2 changed files with 26 additions and 10 deletions

8
adsr.c
View File

@ -46,14 +46,6 @@ static uint8_t adsr_release_amp(uint8_t amp, uint8_t count) {
return adsr_attack_amp(amp, 16 - count);
}
/*!
* Reset the ADSR state ready for the next note
*/
void adsr_reset(struct adsr_env_gen_t* const adsr) {
adsr->next_event = 0;
adsr->state = ADSR_STATE_IDLE;
}
/*!
* Compute the ADSR amplitude
*/

28
adsr.h
View File

@ -72,9 +72,33 @@ struct adsr_env_gen_t {
};
/*!
* Reset the ADSR state.
* Reset the ADSR state ready for the next note
*/
void adsr_reset(struct adsr_env_gen_t* const adsr);
static inline void adsr_reset(struct adsr_env_gen_t* const adsr) {
adsr->next_event = 0;
adsr->state = ADSR_STATE_IDLE;
}
/*!
* Configure the ADSR.
*/
static inline void adsr_config(struct adsr_env_gen_t* const adsr,
uint32_t time_scale, uint8_t delay_time,
uint8_t attack_time, uint8_t decay_time,
uint8_t sustain_time, uint8_t release_time,
uint8_t peak_amp, uint8_t sustain_amp) {
adsr->time_scale = time_scale;
adsr->delay_time = delay_time;
adsr->attack_time = attack_time;
adsr->decay_time = decay_time;
adsr->sustain_time = sustain_time;
adsr->release_time = release_time;
adsr->peak_amp = peak_amp;
adsr->sustain_amp = sustain_amp;
adsr_reset(adsr);
}
/*!
* Compute the ADSR amplitude