From 550497e9b09894a79c1c9888901bbbf4949a614b Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sat, 15 Jan 2011 15:27:38 +0100 Subject: Added rudimentary support for freq-envelopes todo: pfactor'ed amount todo: support for compiled notes plus some tiny bugfixes: - in Envelope (get_sustain now returns orig_sustain) - parser now uses isnum instead of isfloat where appropriate --- TODO | 12 +++++++++++- synth/envelope.h | 2 +- synth/note.cpp | 29 ++++++++++++++++++++++++++++- synth/note.h | 3 +++ synth/parser.cpp | 29 ++++++++++++++++++++++++++++- synth/programs.cpp | 7 +++++++ synth/programs.h | 28 ++++++++++++++++++---------- synth/util.cpp | 12 ++++++++++++ 8 files changed, 108 insertions(+), 14 deletions(-) diff --git a/TODO b/TODO index fae6026..2f39587 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,17 @@ wenn man danach die noten spielen will. nicht reproduzierbar TODO für den synth -!! o freq-envelopes +!! o freq-envelopes: + o TESTEN: set_param für freq-envs + o pfactor-einfluss für freq_env_amount + o parsen: (case 4 muss noch gemacht werden) + o alles auch für compiled_notes implementieren! + x set_param für factor setzt orig-factor und berechnet eigentl. faktor neu + +!! o im in-synth-cli auch die snh-freq setzen!!! + + o optimierung: foo++ durch ++foo ersetzen + o optimierung: bei allen iterationen: foo.end() cachen! o zu testen: funktionieren no-release-envs auch in compilierten noten? diff --git a/synth/envelope.h b/synth/envelope.h index be50fa2..a9bb15b 100644 --- a/synth/envelope.h +++ b/synth/envelope.h @@ -35,7 +35,7 @@ class Envelope bool get_hold() { return hold; } jack_nframes_t get_attack() { return attack_orig; } jack_nframes_t get_decay() { return decay_orig; } - fixed_t get_sustain() { return sustain; } + fixed_t get_sustain() { return sustain_orig; } jack_nframes_t get_release() { return release_orig; } diff --git a/synth/note.cpp b/synth/note.cpp index 91291d7..046642f 100644 --- a/synth/note.cpp +++ b/synth/note.cpp @@ -27,6 +27,7 @@ Note::Note(int n, float v, program_t &prg, jack_nframes_t pf, fixed_t pb, int pr for (int i=0;iset_attack(v*samp_rate >>SCALE); break; + case FREQ_DECAY: factor_env[p.osc]->set_decay(v*samp_rate >>SCALE); break; + case FREQ_SUSTAIN: factor_env[p.osc]->set_sustain(v); break; + case FREQ_RELEASE: factor_env[p.osc]->set_release(v*samp_rate >>SCALE); break; + case FREQ_HOLD: factor_env[p.osc]->set_hold((v!=0)); break; + case FREQ_ENV_AMOUNT: oscillator[p.osc].freq_env_amount=double(v)/ONE; break; + default: throw string("trying to set an unknown parameter"); } @@ -255,7 +271,10 @@ void Note::release_quickly(jack_nframes_t maxt) void Note::release() { for (int i=0;irelease_key(); + factor_env[i]->release_key(); + } if (filter_params.enabled) filter_envelope->release_key(); @@ -264,7 +283,10 @@ void Note::release() void Note::reattack() { for (int i=0;ireattack(); + factor_env[i]->reattack(); + } if (filter_params.enabled) filter_envelope->reattack(); @@ -343,7 +365,12 @@ fixed_t Note::get_sample() { env_frame_counter=0; for (i=0;iget_level(); + + freqfactor_factor[i]=pow(2.0, oscillator[i].freq_env_amount*(factor_env[i]->get_level() - factor_env[i]->get_sustain())/ONE); + oscillator[i].factor=orig.oscillator[i].factor*freqfactor_factor[i]; + } } diff --git a/synth/note.h b/synth/note.h index cc043e6..7181f6d 100644 --- a/synth/note.h +++ b/synth/note.h @@ -35,6 +35,9 @@ class Note : public NoteSkel int env_frame_counter; + double *freqfactor_factor; + Envelope **factor_env; + fixed_t *envval; fixed_t *oscval; fixed_t *old_oscval; diff --git a/synth/parser.cpp b/synth/parser.cpp index 10accac..a6f27cb 100644 --- a/synth/parser.cpp +++ b/synth/parser.cpp @@ -198,6 +198,13 @@ void init_oscs(int n_osc, oscillator_t *osc) osc[i].vibrato_depth=0; osc[i].vibrato_lfo=0; osc[i].custom_wave=NULL; + + osc[i].freq_env_amount=0; + osc[i].freq_env.attack=0; + osc[i].freq_env.decay=0; + osc[i].freq_env.sustain=ONE; + osc[i].freq_env.release=-1; + osc[i].freq_env.hold=true; } } @@ -380,7 +387,7 @@ program_t parse(string fn) osc[ind].output=val*ONE; break; case WAVEFORM: - if (isfloat(strval)) + if (isnum(strval)) { osc[ind].waveform=int(val); } @@ -497,6 +504,26 @@ program_t parse(string fn) case SYNC_FACTOR: sync_factor=val*ONE; break; + + case FREQ_ATTACK: + osc[ind].freq_env.attack=val*samp_rate; + break; + case FREQ_DECAY: + osc[ind].freq_env.decay=val*samp_rate; + break; + case FREQ_SUSTAIN: + osc[ind].freq_env.sustain=val*ONE; + break; + case FREQ_RELEASE: + osc[ind].freq_env.release=val*samp_rate; + break; + case FREQ_HOLD: + osc[ind].freq_env.hold=(val!=0); + break; + case FREQ_ENV_AMOUNT: + osc[ind].freq_env_amount=val; + break; + default: throw string("unknown variable ('"+array+"')"); } diff --git a/synth/programs.cpp b/synth/programs.cpp index b896a06..cfbd9a1 100644 --- a/synth/programs.cpp +++ b/synth/programs.cpp @@ -174,6 +174,13 @@ void program_t::set_param(const parameter_t &p, fixed_t v) //ACHTUNG: case FILTER_TREM_LFO: filter_settings.trem_lfo=v; break; case SYNC_FACTOR: sync_factor=v; break; + + case FREQ_ATTACK: osc_settings[p.osc].freq_env.attack=v*samp_rate >>SCALE; break; + case FREQ_DECAY: osc_settings[p.osc].freq_env.decay=v*samp_rate >>SCALE; break; + case FREQ_SUSTAIN: osc_settings[p.osc].freq_env.sustain=v; break; + case FREQ_RELEASE: osc_settings[p.osc].freq_env.release=v*samp_rate >>SCALE; break; + case FREQ_HOLD: osc_settings[p.osc].freq_env.hold=(v!=0); break; + case FREQ_ENV_AMOUNT: osc_settings[p.osc].freq_env_amount=double(v)/ONE; break; default: throw string("trying to set an unknown parameter"); } diff --git a/synth/programs.h b/synth/programs.h index 1ed9d6f..6a24db3 100644 --- a/synth/programs.h +++ b/synth/programs.h @@ -48,7 +48,12 @@ enum parameter_enum FILTER_TREMOLO, FILTER_TREM_LFO, SYNC_FACTOR, - + FREQ_ATTACK, + FREQ_DECAY, + FREQ_SUSTAIN, + FREQ_RELEASE, + FREQ_HOLD, + FREQ_ENV_AMOUNT, PARAMETER_N_ENTRIES, UNKNOWN=-1 @@ -113,12 +118,24 @@ struct custom_wave_t }; +struct env_settings_t +{ + jack_nframes_t attack; + jack_nframes_t decay; + fixed_t sustain; + signed int release; + bool hold; +}; + struct oscillator_t { fixed_t *fm_strength; //this osc gets modulated by osc #i by fm_strength[i]. fixed_t output; //NOT: osc #i gets modulated by this osc! int waveform; fixed_t factor; + float freq_env_amount; + env_settings_t freq_env; + fixed_t phase; fixed_t tremolo_depth; @@ -139,15 +156,6 @@ struct oscillator_t oscillator_t& operator=(const oscillator_t &that); }; -struct env_settings_t -{ - jack_nframes_t attack; - jack_nframes_t decay; - fixed_t sustain; - signed int release; - bool hold; -}; - struct filter_params_t { bool enabled; diff --git a/synth/util.cpp b/synth/util.cpp index 2862fdb..c54f2d5 100644 --- a/synth/util.cpp +++ b/synth/util.cpp @@ -171,6 +171,18 @@ parameter_enum param_to_enum(string param) return FILTER_TREM_LFO; else if (param=="sync_factor") return SYNC_FACTOR; + else if (param=="freq.env_amount") + return FREQ_ENV_AMOUNT; + else if (param=="freq.attack") + return FREQ_ATTACK; + else if (param=="freq.decay") + return FREQ_DECAY; + else if (param=="freq.sustain") + return FREQ_SUSTAIN; + else if (param=="freq.release") + return FREQ_RELEASE; + else if (param=="freq.hold") + return FREQ_HOLD; else return UNKNOWN; } -- cgit v1.2.3