.gitignore file
[zyn.git] / addnote.h
blob8b57c302ae28ec2f70f20b09bd16c67fad5d15ae
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 private:
58 void setfreq(int nvoice,REALTYPE freq);
59 void setfreqFM(int nvoice,REALTYPE freq);
60 void computecurrentparameters();
62 void initparameters(bool random_grouping);
64 void KillVoice(unsigned int voice_index);
65 void KillNote();
66 inline REALTYPE getvoicebasefreq(int nvoice);
67 inline REALTYPE getFMvoicebasefreq(int nvoice);
68 inline void ComputeVoiceOscillator_LinearInterpolation(int nvoice);
69 inline void ComputeVoiceOscillator_CubicInterpolation(int nvoice);
70 inline void ComputeVoiceOscillatorMorph(int nvoice);
71 inline void ComputeVoiceOscillatorRingModulation(int nvoice);
72 inline void ComputeVoiceOscillatorFrequencyModulation(int nvoice,int FMmode);//FMmode=0 for phase modulation, 1 for Frequency modulation
73 // inline void ComputeVoiceOscillatorFrequencyModulation(int nvoice);
74 inline void ComputeVoiceOscillatorPitchModulation(int nvoice);
76 inline void ComputeVoiceNoise(int nvoice);
78 inline void fadein(REALTYPE *smps);
81 // GLOBALS
82 bool m_stereo; // if the note is stereo (allows note Panning)
83 int m_midinote;
84 REALTYPE m_velocity;
85 REALTYPE m_basefreq;
87 bool m_note_enabled;
89 /***********************************************************/
90 /* VOICE PARAMETERS */
91 /***********************************************************/
92 struct addsynth_voice * m_voices_ptr; // array with one entry per voice
94 /********************************************************/
95 /* INTERNAL VALUES OF THE NOTE AND OF THE VOICES */
96 /********************************************************/
98 // time from the start of the note
99 REALTYPE m_time;
101 // fractional part (skip)
102 float * m_osc_pos_lo_ptr; // array with one entry per voice
103 float * m_osc_freq_lo_ptr; // array with one entry per voice
105 // integer part (skip)
106 int * m_osc_pos_hi_ptr; // array with one entry per voice
107 int * m_osc_freq_hi_ptr; // array with one entry per voice
109 // fractional part (skip) of the Modullator
110 float * m_osc_pos_lo_FM_ptr; // array with one entry per voice
111 float * m_osc_freq_lo_FM_ptr; // array with one entry per voice
113 // integer part (skip) of the Modullator
114 unsigned short int * m_osc_pos_hi_FM_ptr; // array with one entry per voice
115 unsigned short int * m_osc_freq_hi_FM_ptr; // array with one entry per voice
117 // used to compute and interpolate the amplitudes of voices and modullators
118 float * m_old_amplitude_ptr; // array with one entry per voice
119 float * m_new_amplitude_ptr; // array with one entry per voice
120 float * m_FM_old_amplitude_ptr; // array with one entry per voice
121 float * m_FM_new_amplitude_ptr; // array with one entry per voice
123 // used by Frequency Modulation (for integration)
124 float * m_FM_old_smp_ptr; // array with one entry per voice
126 //temporary buffer
127 zyn_sample_type * m_tmpwave;
129 //Filter bypass samples
130 zyn_sample_type * m_bypassl;
131 zyn_sample_type * m_bypassr;
133 //interpolate the amplitudes
134 REALTYPE globaloldamplitude,globalnewamplitude;
136 // whether it is the first tick (used to fade in the sound)
137 bool * m_first_tick_ptr; // array with one entry per voice
139 // whether note has portamento
140 bool m_portamento;
142 //how the fine detunes are made bigger or smaller
143 REALTYPE m_bandwidth_detune_multiplier;
145 LFO m_amplitude_lfo;
146 LFO m_filter_lfo;
147 LFO m_frequency_lfo;
149 int m_filter_category; // One of ZYN_FILTER_TYPE_XXX
150 Filter m_filter_left;
151 Filter m_filter_right;
152 zyn_filter_processor_handle m_filter_sv_processor_left;
153 zyn_filter_processor_handle m_filter_sv_processor_right;
155 float m_filter_center_pitch; // octaves
156 float m_filter_q_factor;
158 Envelope m_amplitude_envelope;
159 Envelope m_filter_envelope;
160 Envelope m_frequency_envelope;
162 float m_detune; // cents
164 struct zyn_addsynth * m_synth_ptr;
166 float m_volume; // [ 0 .. 1 ]
168 float m_panning; // [ 0 .. 1 ]
170 bool m_punch_enabled;
171 float m_punch_initial_value;
172 float m_punch_duration;
173 float m_punch_t;
176 #endif