1 /*
2   ZynAddSubFX - a software synthesizer
3 
4   Unison.h - Unison effect (multivoice chorus)
5   Copyright (C) 2002-2009 Nasca Octavian Paul
6   Author: Nasca Octavian Paul
7 
8   This program is free software; you can redistribute it and/or
9   modify it under the terms of the GNU General Public License
10   as published by the Free Software Foundation; either version 2
11   of the License, or (at your option) any later version.
12 */
13 
14 #ifndef UNISON_H
15 #define UNISON_H
16 
17 #include "../Misc/Util.h"
18 
19 //how much the unison frequencies varies (always >= 1.0)
20 #define UNISON_FREQ_SPAN 2.0f
21 
22 namespace zyn {
23 
24 class Allocator;
25 
26 class Unison
27 {
28     public:
29         Unison(Allocator *alloc_, int update_period_samples_, float max_delay_sec_, float srate_f);
30         ~Unison();
31 
32         void setSize(int new_size);
33         void setBaseFrequency(float freq);
34         void setBandwidth(float bandwidth_cents);
35 
36         void process(int bufsize, float *inbuf, float *outbuf = NULL);
37 
38     private:
39         void updateParameters(void);
40         void updateUnisonData(void);
41 
42         int   unison_size;
43         float base_freq;
44         struct UnisonVoice {
45             float step;     //base LFO
46             float position;
47             float realpos1; //the position regarding samples
48             float realpos2;
49             float relative_amplitude;
50             float lin_fpos;
51             float lin_ffreq;
UnisonVoiceUnisonVoice52             UnisonVoice() {
53                 position = RND * 1.8f - 0.9f;
54                 realpos1 = 0.0f;
55                 realpos2 = 0.0f;
56                 step     = 0.0f;
57                 relative_amplitude = 1.0f;
58             }
59         } *uv;
60 
61         int    update_period_samples;
62         int    update_period_sample_k;
63         int    max_delay, delay_k;
64         bool   first_time;
65         float *delay_buffer;
66         float  unison_amplitude_samples;
67         float  unison_bandwidth_cents;
68 
69         // current setup
70         float samplerate_f;
71         Allocator &alloc;
72 };
73 
74 }
75 
76 #endif
77