1 
2 /*
3 #    Sfront, a SAOL to C translator
4 #    This file: Global variable initialization
5 #
6 # Copyright (c) 1999-2006, Regents of the University of California
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are
11 # met:
12 #
13 #  Redistributions of source code must retain the above copyright
14 #  notice, this list of conditions and the following disclaimer.
15 #
16 #  Redistributions in binary form must reproduce the above copyright
17 #  notice, this list of conditions and the following disclaimer in the
18 #  documentation and/or other materials provided with the distribution.
19 #
20 #  Neither the name of the University of California, Berkeley nor the
21 #  names of its contributors may be used to endorse or promote products
22 #  derived from this software without specific prior written permission.
23 #
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #
36 #    Maintainer: John Lazzaro, lazzaro@cs.berkeley.edu
37 */
38 
39 
40 #include "tree.h"
41 #include "parser.tab.h"
42 
43 FILE * saolfile = NULL;
44 FILE * saslfile = NULL;
45 FILE * sstrfile = NULL;
46 FILE * midifile = NULL;
47 FILE * mstrfile = NULL;
48 FILE * outfile  = NULL;
49 FILE * boutfile  = NULL;
50 FILE * orcoutfile = NULL;
51 FILE * scooutfile = NULL;
52 FILE * midoutfile = NULL;
53 FILE * bitfile = NULL;
54 FILE * soundfile = NULL;
55 
56 int sfront_argc = 0;
57 char ** sfront_argv = NULL;
58 
59 int aout = 0;
60 char * aoutname = NULL;
61 int aoutflow = PASSIVE_FLOW;
62 
63 int ain = 0;
64 int ainlatency = HIGH_LATENCY_DRIVER;
65 int ainflow = PASSIVE_FLOW;
66 char * ainname = NULL;
67 
68 int outfile_wordsize = WORDSIZE_16BIT;
69 
70 int cin = 0;
71 int cmidi = 0;
72 int csasl = 0;
73 int cmaxchan = 0;
74 int cinmaxchan = 0;
75 int clatency = HIGH_LATENCY_DRIVER;
76 char * cinname = NULL;
77 
78 int reentrant = 0;
79 int creentrant = 0;
80 int nomain = 0;
81 int adebug = 0;
82 
83 char * session = NULL;
84 char * sessionkey = NULL;
85 int feclevel = FEC_STANDARD;
86 int lateplay = 0;
87 float latetime = LATETIME_LIMIT;
88 int null_program = 0;
89 int netstart;
90 int netmsets = DEFAULTBANDSIZE;
91 unsigned short sip_port = SIP_RTP_PORT;
92 char sip_ip[16] = SIP_IP;
93 int msession_interval = MSESSION_INTERVAL;
94 
95 char * au_component_type = NULL;
96 char * au_component_manu = NULL;
97 char * au_component_subtype = NULL;
98 char * au_filesystem_name = NULL;
99 char * au_ui_name = NULL;
100 char * au_ui_manu = NULL;
101 char * au_manu_url = NULL;
102 char * au_view_bundlename = NULL;
103 char * au_view_baseclass = NULL;
104 
105 int timeoptions = UNKNOWN;
106 float latency = -1.0F;
107 int catchsignals = 0;
108 int fixedseed = 0;
109 int isocompliant = 0;
110 int compilertype = UNKNOWN_COMPILER;
111 int cppsaol = 0;
112 char * cppincludes = NULL;
113 int systemshell;
114 int hexstrings = 0;
115 
116 tnode * saolfilelist = NULL;
117 tnode * saslfilelist = NULL;
118 tnode * sstrfilelist = NULL;
119 tnode * currsaolfile = NULL;
120 
121 int ascsaolptree = 0;
122 
123 char * z[ZSIZE];
124 znode * zlist = NULL;
125 
126 struct hasarray has;
127 
128 /* compiler flags */
129 
130 int midiverbose = 0;
131 int isocheck = 0;
132 int rateoptimize = 1;
133 int constoptimize = 1;
134 
135 int srate = -1;
136 int krate = -1;
137 int saol_krate = -1;
138 int twocycle = -1;
139 int inchannels = -1;
140 int outchannels = -1;
141 int interp = -1;
142 float globaltune = 440.0;
143 
144 int interp_cmdline = -1;
145 unsigned int sinc_pilen = 128;
146 unsigned int sinc_zcross = 3;
147 float sinc_upmax = 4.0F;
148 
149 tnode  * troot = NULL;
150 tnode  * groot = NULL;
151 tnode  * instances = NULL;
152 tnode  * outputbusinstance = NULL;
153 tnode  * outbustable = NULL;
154 tnode  * printfunctions = NULL;
155 tnode  * locopcodecalls = NULL;
156 tnode  * tlocopcodecalls = NULL;
157 tnode  * locdyncalls = NULL;
158 tnode  * tlocdyncalls = NULL;
159 tnode  * globalopcodecalls = NULL;
160 
161 tnode maplistopcall;
162 tnode maplistoparraycall;
163 
164 sigsym * bitsampleout = NULL;
165 sigsym * bitsamplein = NULL;
166 sigsym * bitsymtable = NULL;
167 sigsym * bitsymin = NULL;
168 sigsym * locsymtable = NULL;
169 sigsym * tlocsymtable = NULL;
170 sigsym * globalsymtable = NULL;
171 sigsym * instrnametable = NULL;
172 sigsym * unusedinstrtable = NULL;
173 sigsym * opcodenametable = NULL;
174 sigsym * busnametable = NULL;
175 sigsym * outputbus = NULL;
176 sigsym * startupinstr = NULL;
177 sigsym * instrpresets = NULL;
178 sigsym * targetsymtable = NULL;
179 sigsym * mpegtokens = NULL;
180 
181 char   * currinstancename = NULL;
182 char   * curropcodeprefix = NULL;
183 tnode  * currinstance = NULL;
184 tnode  * curropcodeinstance = NULL;
185 sigsym * curropcodestack = NULL;
186 sigsym * currinstrument = NULL;
187 sigsym * currconstoptlevel = NULL;
188 
189 int currinstrwidth = 1;
190 int currinputwidth = 0;
191 int curropcoderate = IRATETYPE;
192 int currspecialrate = UNKNOWN;
193 int currtreerate = UNKNOWN;
194 int currblockrate = IRATETYPE;
195 int currintprint = ASFLOAT;
196 int currconstoptif = 0;
197 int currconstoptwhile = 0;
198 int currconstwhilerate = UNKNOWN;
199 int currrateunguarded = 0;
200 
201 int globalblockcount = 0;
202 int suspendvarchecks = 0;
203 int conditionalblocks = 0;
204 int currarrayindex = 0;
205 int currscalarflag = 1;
206 int outstrict = 0;
207 int setbusnum = 1;   /* always know output bus */
208 int isaninstr = 0;
209 int nonpolyparams = 0;
210 int numinstrnames = 0;
211 int maxoparraydepth = 0;
212 int curroparraydepth = 0;
213 int curropcalldepth = 0;
214 int useshadowbus = 0;
215 int mpegtokencount;
216 
217 int ifrefdepth = 0;
218 int whilerefdepth = 0;
219 int ifrefglobaldepth = 0;
220 int whilerefglobaldepth = 0;
221 
222 int saollinenumber = 1;
223 char * saolsourcefile = NULL;
224 
225 int lexstackret[LEXSTACKSIZE];
226 tnode * lexstacktnode[LEXSTACKSIZE];
227 int lexstackptr = -1;
228 
229 int lexholdret[LEXSTACKSIZE];
230 tnode * lexholdtnode[LEXSTACKSIZE];
231 int lexholdptr = -1;
232 
233 int lexstatemachine = TEMPLATE_REST;
234 int lexttl = S_SEM;
235 int sendsemicoloncount = 0;
236 
237 int numpfields = 1;
238 int maxmidipreset = 0;
239 
240 /* sasl reading stuff */
241 
242 sasdata * confsasl = NULL;
243 sasdata * sstrsasl = NULL;
244 sasdata * allsasl = NULL;
245 sasdata * abssasl = NULL;
246 
247 tnode * tempomap = NULL;
248 
249 /* midi reading stuff */
250 
251 midata * confmidi = NULL;       /* state for conf midi file      */
252 midata * sstrmidi = NULL;       /* state for streaming midi file */
253 int totmidichan = -1;           /* cmidi+confmidi+sstrmidi chans */
254 int midiallsoundsoff = 0;       /* uses the MIDI all sounds off command */
255 
256                                 /* temporary midi variables */
257 
258 unsigned int midictime = 0;    /* current time (during parse) */
259 unsigned char midirunstat = 0;  /* running status for streaming MIDI */
260 
261 int midiext[MCHAN];
262 unsigned int midibank[MCHAN];   /* note state for each note/chan */
263 int midifirst[MCHAN];           /* flags first event in new channel */
264 tnode * midicurrinstr[MCHAN];   /* current instr for each channel */
265 tnode * midicurrnote[MCHAN];    /* last note for each channel */
266 tnode * midilastnote[MCHAN][MNOTE]; /* note state for each note/chan */
267 
268 int midihasctrlflag[MCHAN][MNOTE]; /* flags controller use for verbose mode */
269 int midihastouchc[MCHAN];
270 int midihastouchk[MCHAN];
271 int midihaswheel[MCHAN];
272 
273 
274 unsigned char bitstowrite = 0;  /* buffers for mp4 binary write */
275 int bitwritepos = 7;            /* keeps track of bit position */
276 
277 unsigned char bitstoread = 0;   /* buffers for mp4 binary read */
278 int bitreadpos = -1;            /* keeps track of bit position */
279 
280                                 /* for mp4 binary intrachunk read */
281 unsigned int bitreadlen = 0;   /* number of bytes left in chunk */
282 int bitscoretype = 0;           /* type of line read in progress */
283 int bitlinecount = 0;           /* score line finished */
284 float bitscotime = 0;           /* score time */
285 int bitscohastime = 0;          /* score line hastime bit */
286 int bitscolabel = -1;           /* score label (-1 if no label) */
287 int bitscopfields = -1;         /* score number of pfields */
288 int bitscopfieldsmax = -1;      /* score number of pfields */
289 int bitsampletoken = -1;        /* score token for sample table gen */
290 int bittabletoken = -1;         /* score token for sample table gen */
291 int bitsamplefirst = 0;         /* counter for sample table gen */
292 float bitaccesstime = 0.0F;     /* time of current access unit */
293 int bitwritenosymbols = 1;
294 int bitreadaccessunits = 0;
295 
296 int ffttables[FFTTABSIZE];      /* checklist for including fft tables */
297 
298