SpectMorph
smlivedecoder.hh
1 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html
2 
3 #ifndef SPECTMORPH_LIVEDECODER_HH
4 #define SPECTMORPH_LIVEDECODER_HH
5 
6 #include "smwavset.hh"
7 #include "smsinedecoder.hh"
8 #include "smnoisedecoder.hh"
9 #include "smlivedecodersource.hh"
10 #include "smpolyphaseinter.hh"
11 #include "smalignedarray.hh"
12 #include <vector>
13 
14 namespace SpectMorph {
15 
17 {
18  struct PartialState
19  {
20  float freq;
21  float phase;
22  };
23  std::vector<PartialState> pstate[2], *last_pstate;
24 
25  struct PortamentoState {
26  std::vector<float> buffer;
27  double pos;
28  bool active;
29 
30  enum { DELTA = 32 };
31  } portamento_state;
32 
33  WavSet *smset;
34  Audio *audio;
35 
36  IFFTSynth *ifft_synth;
37  NoiseDecoder *noise_decoder;
38  LiveDecoderSource *source;
39  PolyPhaseInter *pp_inter;
40 
41  bool sines_enabled;
42  bool noise_enabled;
43  bool debug_fft_perf_enabled;
44  bool original_samples_enabled;
45  bool loop_enabled;
46 
47  size_t frame_size, frame_step;
48  size_t zero_values_at_start_scaled;
49  size_t loop_start_scaled;
50  size_t loop_end_scaled;
51  int loop_point;
52  float current_freq;
53  float current_mix_freq;
54 
55  size_t have_samples;
56  size_t block_size;
57  size_t pos;
58  double env_pos;
59  size_t frame_idx;
60  double original_sample_pos;
61  double original_samples_norm_factor;
62 
63  int noise_seed;
64 
65  AlignedArray<float,16> *sse_samples;
66 
67  // unison
68  int unison_voices;
69  std::vector<float> unison_phases[2];
70  std::vector<float> unison_freq_factor;
71  float unison_gain;
72  Random unison_phase_random_gen;
73 
74  // vibrato
75  bool vibrato_enabled;
76  float vibrato_depth;
77  float vibrato_frequency;
78  float vibrato_attack;
79  float vibrato_phase; // state
80  float vibrato_env; // state
81 
82  Audio::LoopType get_loop_type();
83 
84  void process_internal (size_t n_values,
85  float *audio_out,
86  float portamento_stretch);
87 
88  void portamento_grow (double end_pos, float portamento_stretch);
89  void portamento_shrink();
90 
91  void process_portamento (size_t n_values,
92  const float *freq_in,
93  float *audio_out);
94  void process_vibrato (size_t n_values,
95  const float *freq_in,
96  float *audio_out);
97 public:
98  LiveDecoder (WavSet *smset);
100  ~LiveDecoder();
101 
102  void enable_noise (bool ne);
103  void enable_sines (bool se);
104  void enable_debug_fft_perf (bool dfp);
105  void enable_original_samples (bool eos);
106  void enable_loop (bool eloop);
107  void set_noise_seed (int seed);
108  void set_unison_voices (int voices, float detune);
109  void set_vibrato (bool enable_vibrato, float depth, float frequency, float attack);
110 
111  void precompute_tables (float mix_freq);
112  void retrigger (int channel, float freq, int midi_velocity, float mix_freq);
113  void process (size_t n_values,
114  const float *freq_in,
115  float *audio_out);
116 
117  static size_t compute_loop_frame_index (size_t index, Audio *audio);
118 // later: bool done();
119 };
120 
121 }
122 #endif
Definition: smpolyphaseinter.hh:12
Audio sample containing many blocks.
Definition: smaudio.hh:81
Definition: smwavset.hh:28
Definition: smlivedecodersource.hh:10
Definition: smrandom.hh:14
Definition: smifftsynth.hh:15
Definition: smalignedarray.cc:7
Definition: smlivedecoder.hh:16
Decoder for the noise component (stochastic component) of the signal.
Definition: smnoisedecoder.hh:16