summaryrefslogtreecommitdiff
path: root/note_compiler/plugin_factory/infile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'note_compiler/plugin_factory/infile.cpp')
-rw-r--r--note_compiler/plugin_factory/infile.cpp118
1 files changed, 45 insertions, 73 deletions
diff --git a/note_compiler/plugin_factory/infile.cpp b/note_compiler/plugin_factory/infile.cpp
index aca9ff1..f8e34a0 100644
--- a/note_compiler/plugin_factory/infile.cpp
+++ b/note_compiler/plugin_factory/infile.cpp
@@ -2,7 +2,6 @@
#include <cmath>
#include <string>
-#include <iostream>
#include "defines.h"
#include "programs.h"
@@ -59,12 +58,15 @@ class Note : public NoteSkel
//sync is disabled
- LowPassFilter filter;
- filter_params_t filter_params;
- int filter_update_counter;
- Envelope *filter_envelope;
+ //filter is disabled
- //pfactors/velocity influence are disabled
+ pfactor_value_t pfactor;
+ struct
+ {
+ oscillator_t osc0;
+ oscillator_t osc1;
+ //filter is disabled
+ } orig;
// member variables end here
};
@@ -95,20 +97,17 @@ Note::Note(int n, float v, program_t &prg, jack_nframes_t pf, fixed_t pb, int pr
env1=new Envelope (prg.env_settings[1]);
osc0=prg.osc_settings[0];
+ orig.osc0=prg.osc_settings[0];
osc1=prg.osc_settings[1];
+ orig.osc1=prg.osc_settings[1];
//initalize oscillator.phase to multiples of their wave resolution
osc0.phase=ONE * PHASE_INIT;
- osc1.phase=init_custom_osc_phase(osc1.custom_wave->wave_len, osc1.custom_wave->samp_rate);
+ osc1.phase=ONE * PHASE_INIT;
do_ksl();
- filter_params=prg.filter_settings;
- filter_envelope=new Envelope(filter_params.env_settings);
- filter_update_counter=filter_update_frames;
-
-
portamento_frames=0;
set_portamento_frames(pf);
@@ -125,13 +124,18 @@ Note::~Note()
{
delete [] osc0.fm_strength;
delete env0;
+ delete pfactor.fm[0];
delete [] osc1.fm_strength;
delete env1;
+ delete pfactor.fm[1];
delete [] oscval;
delete [] old_oscval;
+
+ delete [] pfactor.out;
+ delete [] pfactor.fm;
}
void Note::destroy()
{
@@ -140,9 +144,22 @@ void Note::destroy()
void Note::recalc_factors()
{
+ for (int i=0;i<2;i++)
+ {
+ pfactor.out[i]=calc_pfactor(curr_prg->pfactor.out[i], vel);
+
+ for (int j=0;j<2;j++)
+ pfactor.fm[i][j]=calc_pfactor(curr_prg->pfactor.fm[i][j], vel);
+ }
}
void Note::apply_pfactor()
{
+ osc0.output=orig.osc0.output*pfactor.out[0] >>SCALE;
+ for (int i=0;i<2;i++)
+ osc0.fm_strength[i]=orig.osc0.fm_strength[i]*pfactor.fm[0][i] >>SCALE;
+ osc1.output=orig.osc1.output*pfactor.out[1] >>SCALE;
+ for (int i=0;i<2;i++)
+ osc1.fm_strength[i]=orig.osc1.fm_strength[i]*pfactor.fm[1][i] >>SCALE;
}
bool Note::still_active()
@@ -157,8 +174,6 @@ void Note::release()
{
env0->release_key();
env1->release_key();
-
- filter_envelope->release_key();
}
void Note::release_quickly(jack_nframes_t maxt)
{
@@ -175,8 +190,6 @@ void Note::reattack()
{
env0->reattack();
env1->reattack();
-
- filter_envelope->reattack();
}
void Note::do_ksr()
@@ -219,29 +232,18 @@ fixed_t Note::get_sample()
//sync is disabled
- osc0.phase+= (actual_freq*osc0.factor/samp_rate)>>SCALE;
- oscval[0] = wave[0][ ( ( osc0.phase + ( + (old_oscval[1] * osc0.fm_strength[1]) >>SCALE ) ) * WAVE_RES >>SCALE ) % WAVE_RES ] * env0->get_level() >>SCALE;
- //oscillator0 has no tremolo
+ osc0.phase+= ( (osc0.vibrato_depth==0) ? ((actual_freq*osc0.factor/samp_rate)>>SCALE) : (( (curr_lfo[osc0.vibrato_lfo][osc0.vibrato_depth]*actual_freq >>SCALE)*osc0.factor/samp_rate)>>SCALE) );
+ oscval[0] = wave[1][ ( ( osc0.phase + ( + (old_oscval[0] * 104857) + (old_oscval[1] * osc0.fm_strength[1]) >>SCALE ) ) * WAVE_RES >>SCALE ) % WAVE_RES ] * env0->get_level() >>SCALE;
+ if (osc0.tremolo_depth)
+ oscval[0] = oscval[0] * curr_lfo[0][osc0.tremolo_depth] >>SCALE;
- osc1.phase+= (actual_freq*osc1.factor/samp_rate)>>SCALE;
- oscval[1] = osc1.custom_wave->wave[ ( osc1.phase * osc1.custom_wave->samp_rate >>(2*SCALE) ) % osc1.custom_wave->wave_len ] * env1->get_level() >>SCALE;
+ osc1.phase+= ( (curr_lfo[osc1.vibrato_lfo][osc1.vibrato_depth]*actual_freq >>SCALE)*osc1.factor/samp_rate)>>SCALE;
+ oscval[1] = wave[0][ ( osc1.phase * WAVE_RES >>SCALE ) % WAVE_RES ] * env1->get_level() >>SCALE;
//oscillator1 has no tremolo
fixed_t out = ( + osc0.output*oscval[0] >>SCALE );
- filter_update_counter++;
- if (filter_update_counter>=filter_update_frames)
- {
- filter_update_counter=0;
-
- float cutoff= float(actual_freq)/ONE *
- float(curr_lfo[filter_params.trem_lfo][filter_params.trem_strength])/ONE *
- ( filter_params.freqfactor_offset + filter_envelope->get_level() * filter_params.env_amount / float(ONE) );
- filter.set_params( cutoff, filter_params.resonance );
- }
-
- filter.process_sample(&out);
return out;
}
@@ -285,51 +287,22 @@ void Note::set_param(const parameter_t &p, fixed_t v)
case WAVEFORM: sel_osc->waveform=v; break;
case SYNC: sel_osc->sync=(v!=0); break;
- case MODULATION: sel_osc->fm_strength[p.index]=v; break;
- case OUTPUT: sel_osc->output=v; break;
-
- case FILTER_ENABLED: output_note("NOTE: cannot enable filter in playing notes"); break;
-
+ case MODULATION: sel_osc->fm_strength[p.index]=v*pfactor.fm[p.osc][p.index] >>SCALE; break;
+ case OUTPUT: sel_osc->output=v*pfactor.out[p.osc] >>SCALE; break;
+ case FILTER_ENABLED:
+ case FILTER_ENV_AMOUNT:
case FILTER_ATTACK:
- if (filter_params.enabled)
- filter_envelope->set_attack(v*samp_rate/filter_update_frames >>SCALE);
- else
- output_note("NOTE: cannot set filter-attack when filter is disabled");
- break;
-
case FILTER_DECAY:
- if (filter_params.enabled)
- filter_envelope->set_decay(v*samp_rate/filter_update_frames >>SCALE);
- else
- output_note("NOTE: cannot set filter-decay when filter is disabled");
- break;
-
case FILTER_SUSTAIN:
- if (filter_params.enabled)
- filter_envelope->set_sustain(v);
- else
- output_note("NOTE: cannot set filter-sustain when filter is disabled");
- break;
-
case FILTER_RELEASE:
- if (filter_params.enabled)
- filter_envelope->set_release(v*samp_rate/filter_update_frames >>SCALE);
- else
- output_note("NOTE: cannot set filter-release when filter is disabled");
- break;
-
case FILTER_HOLD:
- if (filter_params.enabled)
- filter_envelope->set_hold(v!=0);
- else
- output_note("NOTE: cannot set filter-hold when filter is disabled");
+ case FILTER_OFFSET:
+ case FILTER_RESONANCE:
+ case FILTER_TREMOLO:
+ case FILTER_TREM_LFO:
+ output_note("NOTE: trying to set some filter-param, but filter is disabled");
break;
- case FILTER_ENV_AMOUNT: filter_params.env_amount=float(v)/ONE; break;
- case FILTER_OFFSET: filter_params.freqfactor_offset=float(v)/ONE; break;
- case FILTER_RESONANCE: filter_params.resonance=float(v)/ONE; break;
- case FILTER_TREMOLO: filter_params.trem_strength=v; break;
- case FILTER_TREM_LFO: filter_params.trem_lfo=v; break;
case SYNC_FACTOR: output_note("NOTE: trying to set sync_factor, but it's disabled"); break;
@@ -341,7 +314,6 @@ void Note::set_param(const parameter_t &p, fixed_t v)
extern "C" NoteSkel* create_note(int n, float v,program_t &prg, jack_nframes_t pf, fixed_t pb, int prg_no)
{
- cout << "test" << endl;
if (wave==NULL)
throw string("FATAL: trying to create a new note from a shared object without initalizing\n"
" the object first! this should /never/ happen, please contact the developer");
@@ -351,7 +323,6 @@ extern "C" NoteSkel* create_note(int n, float v,program_t &prg, jack_nframes_t p
extern "C" void init_vars(int sr, int fupfr, fixed_t **w, fixed_t **clfo, output_note_func_t* out_n, IntToStr_func_t* its)
{
- cout << "inited." << endl;
samp_rate=sr;
filter_update_frames=fupfr;
wave=w;
@@ -360,3 +331,4 @@ extern "C" void init_vars(int sr, int fupfr, fixed_t **w, fixed_t **clfo, output
output_note=out_n;
}
+