From 918f4c99f37b9ca2ae2bbd6c906b7e0f994af014 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sat, 8 Jan 2011 19:35:27 +0100 Subject: Envelope::get_level() gets called rarely now Also, changed .gitignore to ignore gmon.out --- .gitignore | 2 ++ synth/envelope.cpp | 14 +++++++++----- synth/envelope.h | 10 ++++++++-- synth/note.cpp | 27 ++++++++++++++++++++++----- synth/note.h | 4 ++++ 5 files changed, 45 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 33ec174..e29f06a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.o *.so *.a +gmon.out + diff --git a/synth/envelope.cpp b/synth/envelope.cpp index 481b78f..3e9c6ac 100644 --- a/synth/envelope.cpp +++ b/synth/envelope.cpp @@ -1,12 +1,14 @@ #include "envelope.h" -Envelope::Envelope(jack_nframes_t a, jack_nframes_t d, fixed_t s, jack_nframes_t r, bool h) +Envelope::Envelope(jack_nframes_t a, jack_nframes_t d, fixed_t s, jack_nframes_t r, bool h, int frames) { level=0; t=0; state=ATTACK; max=ONE; + nth_frame=frames; + set_ratefactor(1.0); set_attack(a); @@ -16,13 +18,15 @@ Envelope::Envelope(jack_nframes_t a, jack_nframes_t d, fixed_t s, jack_nframes_t set_hold(h); } -Envelope::Envelope(env_settings_t s) +Envelope::Envelope(env_settings_t s, int frames) { level=0; t=0; state=ATTACK; max=ONE; + nth_frame=frames; + set_ratefactor(1.0); set_attack(s.attack); @@ -44,7 +48,7 @@ void Envelope::set_ratefactor(double factor) void Envelope::set_attack(jack_nframes_t a) { attack_orig=a; - attack=a*ratefactor >>SCALE; + attack=(a*ratefactor >>SCALE)/nth_frame; if (state==ATTACK) t=attack*level >>SCALE; @@ -53,7 +57,7 @@ void Envelope::set_attack(jack_nframes_t a) void Envelope::set_decay(jack_nframes_t d) { decay_orig=d; - decay=d*ratefactor >>SCALE; + decay=(d*ratefactor >>SCALE)/nth_frame; if ((state==DECAY) && (sustain!=ONE)) if (sustain>SCALE; + release=(r*ratefactor >>SCALE)/nth_frame; if (state==RELEASE) if (sustain>0) //to avoid a div. by zero diff --git a/synth/envelope.h b/synth/envelope.h index e0d3502..65ea723 100644 --- a/synth/envelope.h +++ b/synth/envelope.h @@ -6,12 +6,16 @@ #include "programs.h" #include "fixed.h" +// when frames is given, this tells the envelope that get_level() is +// only called every (frames) frames. 1 means "every time", 2 means +// "every second time" and so on. +// the caller must manage to call get_level() to the appropriate times class Envelope { public: - Envelope(jack_nframes_t a, jack_nframes_t d, fixed_t s, jack_nframes_t r, bool h); - Envelope(env_settings_t s); + Envelope(jack_nframes_t a, jack_nframes_t d, fixed_t s, jack_nframes_t r, bool h, int frames=1); + Envelope(env_settings_t s, int frames=1); void release_key(); void reattack(); fixed_t get_level(); @@ -52,6 +56,8 @@ class Envelope jack_nframes_t t; fixed_t ratefactor; + int nth_frame; + enum { ATTACK, diff --git a/synth/note.cpp b/synth/note.cpp index 2c884bd..b8028bc 100644 --- a/synth/note.cpp +++ b/synth/note.cpp @@ -1,3 +1,5 @@ +#define ENV_NTH_FRAME 50 + #include #include @@ -27,16 +29,17 @@ Note::Note(int n, float v, program_t &prg, jack_nframes_t pf, fixed_t pb, int pr for (int i=0;i=ENV_NTH_FRAME) + { + env_frame_counter=0; + for (i=0;iget_level(); + } + + for (i=0;iwave[ ((oscillator[i].phase + fm) * cw->samp_rate >>(2*SCALE)) % cw->wave_len ] * envelope[i]->get_level() >> (SCALE); + oscval[i]=cw->wave[ ((oscillator[i].phase + fm) * cw->samp_rate >>(2*SCALE)) % cw->wave_len ] * envval[i] >> (SCALE); } else { //normal oscillator - oscval[i]=wave[oscillator[i].waveform][ ((oscillator[i].phase + fm) * WAVE_RES >>SCALE) % WAVE_RES ] * envelope[i]->get_level() >> (SCALE); + oscval[i]=wave[oscillator[i].waveform][ ((oscillator[i].phase + fm) * WAVE_RES >>SCALE) % WAVE_RES ] * envval[i] >> (SCALE); } if (oscillator[i].tremolo_depth!=0) diff --git a/synth/note.h b/synth/note.h index 5035bd2..26ce379 100644 --- a/synth/note.h +++ b/synth/note.h @@ -37,10 +37,14 @@ class Note void apply_pfactor(); Envelope **envelope; + fixed_t freq, dest_freq, old_freq; fixed_t vel; jack_nframes_t portamento_t, portamento_frames; + int env_frame_counter; + + fixed_t *envval; fixed_t *oscval; fixed_t *old_oscval; int n_oscillators; -- cgit v1.2.1