summaryrefslogtreecommitdiff
path: root/attic/muse_qt4_evolution/synti/zynaddsubfx/Synth/ADnote.h
blob: 28c1897581d7d465818c1e1ff837c18bd4dbf285 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*
  ZynAddSubFX - a software synthesizer
 
  ADnote.h - The "additive" synthesizer
  Copyright (C) 2002-2005 Nasca Octavian Paul
  Author: Nasca Octavian Paul

  This program is free software; you can redistribute it and/or modify
  it under the terms of version 2 of the GNU General Public License 
  as published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License (version 2) for more details.

  You should have received a copy of the GNU General Public License (version 2)
  along with this program; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA

*/

#ifndef AD_NOTE_H
#define AD_NOTE_H

#include "../globals.h"
#include "Envelope.h"
#include "LFO.h"
#include "../DSP/Filter.h"
#include "../Params/ADnoteParameters.h"
#include "../Params/Controller.h"

//Globals

//FM amplitude tune
#define FM_AMP_MULTIPLIER 14.71280603

#define OSCIL_SMP_EXTRA_SAMPLES 5

class ADnote{   //ADDitive note
 public:
  ADnote(ADnoteParameters *pars,Controller *ctl_,REALTYPE freq,REALTYPE velocity,int portamento_,int midinote_);
  ~ADnote();
  int noteout(REALTYPE *outl,REALTYPE *outr); 
  void relasekey();
  int finished();


  /*ready - this is 0 if it is not ready (the parameters has to be computed)
   or other value if the parameters has been computed and if it is ready to output*/
  char ready;

 private:
     
  void setfreq(int nvoice,REALTYPE freq);
  void setfreqFM(int nvoice,REALTYPE freq);
  void computecurrentparameters();
  void initparameters();
  void KillVoice(int nvoice);
  void KillNote();
  inline REALTYPE getvoicebasefreq(int nvoice);
  inline REALTYPE getFMvoicebasefreq(int nvoice);
  inline void ComputeVoiceOscillator_LinearInterpolation(int nvoice);
  inline void ComputeVoiceOscillator_CubicInterpolation(int nvoice);
  inline void ComputeVoiceOscillatorMorph(int nvoice);
  inline void ComputeVoiceOscillatorRingModulation(int nvoice);
  inline void ComputeVoiceOscillatorFrequencyModulation(int nvoice,int FMmode);//FMmode=0 for phase modulation, 1 for Frequency modulation
//  inline void ComputeVoiceOscillatorFrequencyModulation(int nvoice);
  inline void ComputeVoiceOscillatorPitchModulation(int nvoice);

  inline void ComputeVoiceNoise(int nvoice);

  inline void fadein(REALTYPE *smps);


   //GLOBALS
    ADnoteParameters *partparams;
    unsigned char stereo;//if the note is stereo (allows note Panning)
    int midinote;
    REALTYPE velocity,basefreq;

    ONOFFTYPE NoteEnabled;
    Controller *ctl;

   /*****************************************************************/
   /*                    GLOBAL PARAMETERS                          */
   /*****************************************************************/

    struct ADnoteGlobal{
       /******************************************
	*     FREQUENCY GLOBAL PARAMETERS        *
	******************************************/
	REALTYPE Detune;//cents

	Envelope *FreqEnvelope;
	LFO *FreqLfo;

       /********************************************
	*     AMPLITUDE GLOBAL PARAMETERS          *
	********************************************/
	REALTYPE Volume;// [ 0 .. 1 ]

	REALTYPE Panning;// [ 0 .. 1 ]

	Envelope *AmpEnvelope;
	LFO *AmpLfo;   
	
	struct {
	    int Enabled;
	    REALTYPE initialvalue,dt,t;
	} Punch;

       /******************************************
	*        FILTER GLOBAL PARAMETERS        *
	******************************************/
	Filter *GlobalFilterL,*GlobalFilterR;

	REALTYPE FilterCenterPitch;//octaves
	REALTYPE FilterQ;
	REALTYPE FilterFreqTracking;
    
	Envelope *FilterEnvelope;
    
	LFO *FilterLfo;
    } NoteGlobalPar;  


    
   /***********************************************************/
   /*                    VOICE PARAMETERS                     */
   /***********************************************************/
    struct ADnoteVoice{
        /* If the voice is enabled */
        ONOFFTYPE Enabled; 

	/* Voice Type (sound/noise)*/
	int noisetype;

	/* Filter Bypass */
	int filterbypass;
	        
	/* Delay (ticks) */
	int DelayTicks;
	  
        /* Waveform of the Voice */ 
        REALTYPE *OscilSmp;    

        /************************************
	*     FREQUENCY PARAMETERS          *
	************************************/
	int fixedfreq;//if the frequency is fixed to 440 Hz
	int fixedfreqET;//if the "fixed" frequency varies according to the note (ET)

	// cents = basefreq*VoiceDetune
	REALTYPE Detune,FineDetune;
    
	Envelope *FreqEnvelope;
	LFO *FreqLfo;
    

	/***************************
	*   AMPLITUDE PARAMETERS   *
	***************************/

	/* Panning 0.0=left, 0.5 - center, 1.0 = right */
	REALTYPE Panning;
	REALTYPE Volume;// [-1.0 .. 1.0]

	Envelope *AmpEnvelope;
	LFO *AmpLfo;

	/*************************
	*   FILTER PARAMETERS    *
	*************************/
    
	Filter *VoiceFilter;
    
	REALTYPE FilterCenterPitch;/* Filter center Pitch*/
	REALTYPE FilterFreqTracking;

	Envelope *FilterEnvelope;
	LFO *FilterLfo;


	/****************************
	*   MODULLATOR PARAMETERS   *
	****************************/

	FMTYPE FMEnabled;

	int FMVoice;

	// Voice Output used by other voices if use this as modullator
	REALTYPE *VoiceOut;

        /* Wave of the Voice */ 
	REALTYPE *FMSmp;    

	REALTYPE FMVolume;
	REALTYPE FMDetune; //in cents
    
	Envelope *FMFreqEnvelope;
	Envelope *FMAmpEnvelope;
    } NoteVoicePar[NUM_VOICES]; 


   /********************************************************/
   /*    INTERNAL VALUES OF THE NOTE AND OF THE VOICES     */
   /********************************************************/

    //time from the start of the note
    REALTYPE time;

    //fractional part (skip)
    REALTYPE oscposlo[NUM_VOICES],oscfreqlo[NUM_VOICES];    

    //integer part (skip)
    int oscposhi[NUM_VOICES],oscfreqhi[NUM_VOICES];

    //fractional part (skip) of the Modullator
    REALTYPE oscposloFM[NUM_VOICES],oscfreqloFM[NUM_VOICES]; 

    //integer part (skip) of the Modullator
    unsigned short int oscposhiFM[NUM_VOICES],oscfreqhiFM[NUM_VOICES];

    //used to compute and interpolate the amplitudes of voices and modullators
    REALTYPE oldamplitude[NUM_VOICES],
	     newamplitude[NUM_VOICES],
             FMoldamplitude[NUM_VOICES],
	     FMnewamplitude[NUM_VOICES];

    //used by Frequency Modulation (for integration)
    REALTYPE FMoldsmp[NUM_VOICES];
    
    //temporary buffer
    REALTYPE *tmpwave;
    
    //Filter bypass samples
    REALTYPE *bypassl,*bypassr;

    //interpolate the amplitudes    
    REALTYPE globaloldamplitude,globalnewamplitude;
    
    //1 - if it is the fitst tick (used to fade in the sound)
    char firsttick[NUM_VOICES];
    
    //1 if the note has portamento 
    int portamento;
    
    //how the fine detunes are made bigger or smaller
    REALTYPE bandwidthDetuneMultiplier;
};

#endif