From 67025394dcbc2d0917c89856c40be3b9198eca5e Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sat, 15 Jan 2011 18:13:48 +0100 Subject: Implemented freq-envelopes for non-compiled notes plus some tiny bugfixes: - in Envelope (get_sustain now returns orig_sustain) - parser now uses isnum instead of isfloat where appropriate --- synth/note.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'synth/note.cpp') diff --git a/synth/note.cpp b/synth/note.cpp index 91291d7..35a7115 100644 --- a/synth/note.cpp +++ b/synth/note.cpp @@ -23,10 +23,12 @@ Note::Note(int n, float v, program_t &prg, jack_nframes_t pf, fixed_t pb, int pr pfactor.out=new fixed_t [n_oscillators]; + pfactor.freq_env_amount=new fixed_t [n_oscillators]; pfactor.fm=new fixed_t* [n_oscillators]; for (int i=0;ipfactor.out[i], vel) * volume_factor; + pfactor.freq_env_amount[i]=calc_pfactor(curr_prg->pfactor.freq_env_amount[i], vel); for (int j=0;jpfactor.fm[i][j], vel); @@ -143,6 +154,7 @@ void Note::apply_pfactor() for (int i=0;i>SCALE; + oscillator[i].freq_env_amount=orig.oscillator[i].freq_env_amount*pfactor.freq_env_amount[i] /ONE; //because it's a float for (int j=0;j>SCALE; @@ -166,7 +178,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 +232,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: orig.oscillator[p.osc].freq_env_amount=double(v)/ONE; apply_pfactor(); break; + default: throw string("trying to set an unknown parameter"); } @@ -255,7 +275,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 +287,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 +369,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]; + } } -- cgit v1.2.3