Update copyright years
[zyn.git] / addnote.h
blobad03d6777820045b72a2689996a9e28799c2cd1e
1 /*
2 ZynAddSubFX - a software synthesizer
4 ADnote.h - The "additive" synthesizer
5 Copyright (C) 2002-2005 Nasca Octavian Paul
6 Author: Nasca Octavian Paul
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of version 2 of the GNU General Public License
10 as published by the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License (version 2) for more details.
17 You should have received a copy of the GNU General Public License (version 2)
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifndef AD_NOTE_H
24 #define AD_NOTE_H
26 #include "filter_sv.h"
28 //Globals
30 //FM amplitude tune
31 #define FM_AMP_MULTIPLIER 14.71280603
33 #define OSCIL_SMP_EXTRA_SAMPLES 5
35 // ADDitive note
36 class ADnote
38 public:
39 ADnote(
40 struct zyn_addsynth * synth_ptr);
42 ~ADnote();
44 void
45 note_on(
46 float panorama,
47 bool random_grouping,
48 REALTYPE freq,
49 REALTYPE velocity,
50 bool portamento,
51 int midinote);
53 void noteout(REALTYPE *outl,REALTYPE *outr);
54 void relasekey();
55 bool finished();
57 void force_disable();
59 private:
60 void setfreq(int nvoice,REALTYPE freq);
61 void setfreqFM(int nvoice,REALTYPE freq);
62 void computecurrentparameters();
64 void initparameters(bool random_grouping);
66 void KillVoice(unsigned int voice_index);
67 void KillNote();
68 inline REALTYPE getvoicebasefreq(int nvoice);
69 inline REALTYPE getFMvoicebasefreq(int nvoice);
70 inline void ComputeVoiceOscillator_LinearInterpolation(int nvoice);
71 inline void ComputeVoiceOscillator_CubicInterpolation(int nvoice);
72 inline void ComputeVoiceOscillatorMorph(int nvoice);
73 inline void ComputeVoiceOscillatorRingModulation(int nvoice);
74 inline void ComputeVoiceOscillatorFrequencyModulation(int nvoice,int FMmode);//FMmode=0 for phase modulation, 1 for Frequency modulation
75 // inline void ComputeVoiceOscillatorFrequencyModulation(int nvoice);
76 inline void ComputeVoiceOscillatorPitchModulation(int nvoice);
78 inline void ComputeVoiceNoise(int nvoice);
80 inline void fadein(REALTYPE *smps);
83 // GLOBALS
84 bool m_stereo; // if the note is stereo (allows note Panning)
85 int m_midinote;
86 REALTYPE m_velocity;
87 REALTYPE m_basefreq;
89 bool m_note_enabled;
91 /***********************************************************/
92 /* VOICE PARAMETERS */
93 /***********************************************************/
94 struct addsynth_voice * m_voices_ptr; // array with one entry per voice
96 /********************************************************/
97 /* INTERNAL VALUES OF THE NOTE AND OF THE VOICES */
98 /********************************************************/
100 // time from the start of the note
101 REALTYPE m_time;
103 // fractional part (skip)
104 float * m_osc_pos_lo_ptr; // array with one entry per voice
105 float * m_osc_freq_lo_ptr; // array with one entry per voice
107 // integer part (skip)
108 int * m_osc_pos_hi_ptr; // array with one entry per voice
109 int * m_osc_freq_hi_ptr; // array with one entry per voice
111 // fractional part (skip) of the Modullator
112 float * m_osc_pos_lo_FM_ptr; // array with one entry per voice
113 float * m_osc_freq_lo_FM_ptr; // array with one entry per voice
115 // integer part (skip) of the Modullator
116 unsigned short int * m_osc_pos_hi_FM_ptr; // array with one entry per voice
117 unsigned short int * m_osc_freq_hi_FM_ptr; // array with one entry per voice
119 // used to compute and interpolate the amplitudes of voices and modullators
120 float * m_old_amplitude_ptr; // array with one entry per voice
121 float * m_new_amplitude_ptr; // array with one entry per voice
122 float * m_FM_old_amplitude_ptr; // array with one entry per voice
123 float * m_FM_new_amplitude_ptr; // array with one entry per voice
125 // used by Frequency Modulation (for integration)
126 float * m_FM_old_smp_ptr; // array with one entry per voice
128 //temporary buffer
129 zyn_sample_type * m_tmpwave;
131 //Filter bypass samples
132 zyn_sample_type * m_bypassl;
133 zyn_sample_type * m_bypassr;
135 //interpolate the amplitudes
136 REALTYPE globaloldamplitude,globalnewamplitude;
138 // whether it is the first tick (used to fade in the sound)
139 bool * m_first_tick_ptr; // array with one entry per voice
141 // whether note has portamento
142 bool m_portamento;
144 //how the fine detunes are made bigger or smaller
145 REALTYPE m_bandwidth_detune_multiplier;
147 LFO m_amplitude_lfo;
148 LFO m_filter_lfo;
149 LFO m_frequency_lfo;
151 int m_filter_category; // One of ZYN_FILTER_TYPE_XXX
152 Filter m_filter_left;
153 Filter m_filter_right;
154 zyn_filter_processor_handle m_filter_sv_processor_left;
155 zyn_filter_processor_handle m_filter_sv_processor_right;
157 float m_filter_center_pitch; // octaves
158 float m_filter_q_factor;
160 Envelope m_amplitude_envelope;
161 Envelope m_filter_envelope;
162 Envelope m_frequency_envelope;
164 float m_detune; // cents
166 struct zyn_addsynth * m_synth_ptr;
168 float m_volume; // [ 0 .. 1 ]
170 float m_panning; // [ 0 .. 1 ]
172 bool m_punch_enabled;
173 float m_punch_initial_value;
174 float m_punch_duration;
175 float m_punch_t;
178 #endif