diff options
author | Florian Jung <flo@thinkpad.(none)> | 2011-01-15 15:27:38 +0100 |
---|---|---|
committer | Florian Jung <flo@thinkpad.(none)> | 2011-01-15 15:27:38 +0100 |
commit | 550497e9b09894a79c1c9888901bbbf4949a614b (patch) | |
tree | 22a1b1f5eac70051eb8336312569ad07c512cc82 /synth/note.cpp | |
parent | 9e3998bbaddf4eb6df8544497e42231137824998 (diff) |
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
Diffstat (limited to 'synth/note.cpp')
-rw-r--r-- | synth/note.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
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;i<n_oscillators;i++) pfactor.fm[i]=new fixed_t [n_oscillators]; + freqfactor_factor=new double[n_oscillators]; envval=new fixed_t[n_oscillators]; oscval=new fixed_t[n_oscillators]; old_oscval=new fixed_t[n_oscillators]; @@ -35,9 +36,13 @@ Note::Note(int n, float v, program_t &prg, jack_nframes_t pf, fixed_t pb, int pr envval[i]=oscval[i]=old_oscval[i]=0; envelope=new Envelope*[n_oscillators]; + factor_env=new Envelope*[n_oscillators]; for (int i=0;i<n_oscillators;i++) + { envelope[i]=new Envelope(prg.env_settings[i], envelope_update_frames); + factor_env[i]=new Envelope(prg.osc_settings[i].freq_env, envelope_update_frames); + } oscillator=new oscillator_t[n_oscillators]; orig.oscillator=new oscillator_t[n_oscillators]; @@ -106,13 +111,16 @@ Note::~Note() { delete [] oscillator[i].fm_strength; delete envelope[i]; + delete factor_env[i]; delete [] pfactor.fm[i]; } delete [] oscillator; delete [] envelope; + delete [] factor_env; + delete [] freqfactor_factor; delete [] envval; delete [] oscval; delete [] old_oscval; @@ -166,7 +174,7 @@ void Note::set_param(const parameter_t &p, fixed_t v) //ACHTUNG: case KSR: oscillator[p.osc].ksr=float(v)/ONE; break; case KSL: oscillator[p.osc].ksl=float(v)/ONE; break; - case FACTOR: oscillator[p.osc].factor=v; break; + case FACTOR: orig.oscillator[p.osc].factor=v; oscillator[p.osc].factor=v*freqfactor_factor[p.osc]; break; case MODULATION: orig.oscillator[p.osc].fm_strength[p.index]=v; apply_pfactor(); break; case OUTPUT: orig.oscillator[p.osc].output=v; apply_pfactor(); break; case TREMOLO: oscillator[p.osc].tremolo_depth=v; break; @@ -220,6 +228,14 @@ void Note::set_param(const parameter_t &p, fixed_t v) //ACHTUNG: case FILTER_TREM_LFO: filter_params.trem_lfo=v; break; case SYNC_FACTOR: sync_factor=v; break; + + case FREQ_ATTACK: factor_env[p.osc]->set_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;i<n_oscillators;i++) + { envelope[i]->release_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;i<n_oscillators;i++) + { envelope[i]->reattack(); + 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;i<n_oscillators;i++) + { envval[i]=envelope[i]->get_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]; + } } |