1 /*
2     fm4op.h:
3 
4     Copyright (C) 1998 Perry Cook, John ffitch
5 
6     This file is part of Csound.
7 
8     The Csound Library is free software; you can redistribute it
9     and/or modify it under the terms of the GNU Lesser General Public
10     License as published by the Free Software Foundation; either
11     version 2.1 of the License, or (at your option) any later version.
12 
13     Csound is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU Lesser General Public License for more details.
17 
18     You should have received a copy of the GNU Lesser General Public
19     License along with Csound; if not, write to the Free Software
20     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21     02110-1301 USA
22 */
23 
24 /*******************************************/
25 /*  Master Class for 4 Operator FM Synth   */
26 /*  by Perry R. Cook, 1995-96              */
27 /*  This instrument contains an 4 waves,   */
28 /*  4 envelopes, and various state vars.   */
29 /*                                         */
30 /*  The basic Chowning/Stanford FM patent  */
31 /*  expired April 1995, but there exist    */
32 /*  follow-on patents, mostly assigned to  */
33 /*  Yamaha.  If you are of the type who    */
34 /*  should worry about this (making money) */
35 /*  worry away.                            */
36 /*                                         */
37 /*******************************************/
38 
39 #if !defined(__FM4OP_h)
40 #define __FM4OP_h
41 
42 #include "physutil.h"
43 
44 /*******************************************/
45 /*  Two Zero Filter Class,                 */
46 /*  by Perry R. Cook, 1995-96              */
47 /*  See books on filters to understand     */
48 /*  more about how this works.  Nothing    */
49 /*  out of the ordinary in this version.   */
50 /*******************************************/
51 
52 typedef struct TwoZero {
53     MYFLT gain;
54     MYFLT lastOutput;
55     MYFLT inputs[2];
56     MYFLT zeroCoeffs[2];
57 } TwoZero;
58 
59 /* ********************************************************************** */
60 
61 typedef struct FM4OP {
62     OPDS        h;
63     MYFLT       *ar;                  /* Output */
64     MYFLT       *amp, *frequency;
65     MYFLT       *control1, *control2, *modDepth; /* Control1 doubles as vowel */
66     MYFLT       *vibFreq;
67     MYFLT       *ifn0, *ifn1, *ifn2, *ifn3, *vifn;
68     MYFLT       *opt;
69     ADSR        adsr[4];
70     FUNC        *waves[4];
71     MYFLT       w_rate[4];         /* Parameters for vibrato */
72     MYFLT       w_time[4];
73     MYFLT       w_phase[4];
74     FUNC        *vibWave;
75     MYFLT       v_rate;         /* Parameters for vibrato */
76     MYFLT       v_time;
77 /*     MYFLT    v_phaseOffset; */
78     TwoZero     twozero;
79     MYFLT       baseFreq;
80     MYFLT       ratios[4];
81     MYFLT       gains[4];
82 } FM4OP;
83 
84 typedef struct FM4OPV {
85     OPDS        h;
86     MYFLT       *ar;                  /* Output */
87     MYFLT       *amp, *frequency;
88     MYFLT       *control1, *control2, *modDepth; /* Control1 doubles as vowel */
89     MYFLT       *vibFreq;
90     MYFLT       *ifn0, *ifn1, *ifn2, *ifn3, *vifn;
91 
92     ADSR        adsr[4];
93     FUNC        *waves[4];
94     MYFLT       w_rate[4];
95     MYFLT       w_time[4];
96     MYFLT       w_phase[4];
97     FUNC        *vibWave;
98     MYFLT       v_rate;         /* Parameters for vibrato */
99     MYFLT       v_time;         /* Parameters for vibrato */
100 /*     MYFLT    v_phaseOffset; */
101     TwoZero     twozero;
102     MYFLT       baseFreq;
103     MYFLT       ratios[4];
104     MYFLT       gains[4];
105     MYFLT       tilt[3];
106     MYFLT       mods[3];
107     MYFLT       last_control;
108 } FM4OPV;
109 
110 #endif
111