summaryrefslogtreecommitdiff
path: root/synth
diff options
context:
space:
mode:
authorFlorian Jung <flo@thinkpad.(none)>2011-01-15 15:27:38 +0100
committerFlorian Jung <flo@thinkpad.(none)>2011-01-15 15:27:38 +0100
commit550497e9b09894a79c1c9888901bbbf4949a614b (patch)
tree22a1b1f5eac70051eb8336312569ad07c512cc82 /synth
parent9e3998bbaddf4eb6df8544497e42231137824998 (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')
-rw-r--r--synth/envelope.h2
-rw-r--r--synth/note.cpp29
-rw-r--r--synth/note.h3
-rw-r--r--synth/parser.cpp29
-rw-r--r--synth/programs.cpp7
-rw-r--r--synth/programs.h28
-rw-r--r--synth/util.cpp12
7 files changed, 97 insertions, 13 deletions
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;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];
+ }
}
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;
}