summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Jung <flo@thinkpad.(none)>2011-01-08 19:35:27 +0100
committerFlorian Jung <flo@thinkpad.(none)>2011-01-09 13:14:48 +0100
commit918f4c99f37b9ca2ae2bbd6c906b7e0f994af014 (patch)
treeb7ff7f1dd45bb9328c8bae128c6511b16327d3c5
parent5ae35443bfaa8e321365d549a812d853e0734b89 (diff)
Envelope::get_level() gets called rarely now
Also, changed .gitignore to ignore gmon.out
-rw-r--r--.gitignore2
-rw-r--r--synth/envelope.cpp14
-rw-r--r--synth/envelope.h10
-rw-r--r--synth/note.cpp27
-rw-r--r--synth/note.h4
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<ONE) //to avoid a div. by zero
@@ -69,7 +73,7 @@ void Envelope::set_sustain(fixed_t s)
void Envelope::set_release(jack_nframes_t r)
{
release_orig=r;
- release=r*ratefactor >>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 <string>
#include <cmath>
@@ -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<n_oscillators;i++)
pfactor.fm[i]=new fixed_t [n_oscillators];
+ envval=new fixed_t[n_oscillators];
oscval=new fixed_t[n_oscillators];
old_oscval=new fixed_t[n_oscillators];
for (int i=0;i<n_oscillators;i++)
- oscval[i]=old_oscval[i]=0;
+ envval[i]=oscval[i]=old_oscval[i]=0;
envelope=new Envelope*[n_oscillators];
for (int i=0;i<n_oscillators;i++)
- envelope[i]=new Envelope(prg.env_settings[i]);
+ envelope[i]=new Envelope(prg.env_settings[i], ENV_NTH_FRAME);
oscillator=new oscillator_t[n_oscillators];
orig.oscillator=new oscillator_t[n_oscillators];
@@ -78,10 +81,13 @@ Note::Note(int n, float v, program_t &prg, jack_nframes_t pf, fixed_t pb, int pr
if (filter_params.enabled)
{
- filter_envelope=new Envelope(filter_params.env_settings);
+ filter_envelope=new Envelope(filter_params.env_settings,1);
filter_update_counter=filter_update_frames;
}
+ env_frame_counter=ENV_NTH_FRAME; //force update in first frame
+
+
sync_factor=prg.sync_factor;
sync_phase=0;
}
@@ -101,6 +107,7 @@ Note::~Note()
delete [] oscillator;
delete [] envelope;
+ delete [] envval;
delete [] oscval;
delete [] old_oscval;
@@ -376,6 +383,16 @@ fixed_t Note::get_sample()
}
}
+
+ env_frame_counter++;
+ if (env_frame_counter>=ENV_NTH_FRAME)
+ {
+ env_frame_counter=0;
+ for (i=0;i<n_oscillators;i++)
+ envval[i]=envelope[i]->get_level();
+ }
+
+
for (i=0;i<n_oscillators;i++)
{
fm=0;
@@ -396,12 +413,12 @@ fixed_t Note::get_sample()
{
//sampler
custom_wave_t *cw=oscillator[i].custom_wave;
- oscval[i]=cw->wave[ ((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;