summaryrefslogtreecommitdiff
path: root/synth
diff options
context:
space:
mode:
authorFlorian Jung <flo@thinkpad.(none)>2011-01-08 19:35:27 +0100
committerFlorian Jung <flo@thinkpad.(none)>2011-01-08 19:35:27 +0100
commit8320af55e716f352f2720801fcd73913f2e7d19c (patch)
treee36f1ea85d688f8314348a22e6b863af7c6eafeb /synth
parentd84da6cdfb9027a67b8ab50fe2c23374acc3b245 (diff)
Envelope::get_level() gets called rarely now
Also, changed .gitignore to ignore gmon.out
Diffstat (limited to 'synth')
-rw-r--r--synth/Makefile2
-rw-r--r--synth/envelope.cpp14
-rw-r--r--synth/envelope.h10
-rw-r--r--synth/note.cpp27
-rw-r--r--synth/note.h5
5 files changed, 44 insertions, 14 deletions
diff --git a/synth/Makefile b/synth/Makefile
index 8007339..7ddccd7 100644
--- a/synth/Makefile
+++ b/synth/Makefile
@@ -1,5 +1,5 @@
CXX=g++
-CFLAGS=-Wall -O2 -pg
+CFLAGS=-Wall -pg
CXXFLAGS=$(CFLAGS)
LDFLAGS=-lm `pkg-config --cflags --libs jack`
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 86e4b2b..8479153 100644
--- a/synth/note.cpp
+++ b/synth/note.cpp
@@ -1,3 +1,5 @@
+#define ENV_NTH_FRAME 50
+
#include <cmath>
#include "note.h"
@@ -30,16 +32,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];
@@ -72,10 +75,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;
@@ -111,6 +117,7 @@ Note::~Note()
delete [] oscillator;
delete [] envelope;
+ delete [] envval;
delete [] oscval;
delete [] old_oscval;
@@ -334,6 +341,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;
@@ -354,12 +371,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 7c36d69..03a7180 100644
--- a/synth/note.h
+++ b/synth/note.h
@@ -32,7 +32,10 @@ class Note : public NoteSkel
void apply_pfactor();
Envelope **envelope;
-
+
+ int env_frame_counter;
+
+ fixed_t *envval;
fixed_t *oscval;
fixed_t *old_oscval;
int n_oscillators;