1
2 /*
3 # Sfront, a SAOL to C translator
4 # This file: Main loop for runtime: active driver, shorts
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
41 #if defined(ASYS_ACTIVE_O)
42
asys_orun(ASYS_OTYPE obuf[],int * osize)43 int asys_orun(ASYS_OTYPE obuf[], int * osize)
44
45 {
46 int obusidx = 0;
47 int busidx;
48
49 if (EV(asys_exit_status) == ASYS_EXIT)
50 return ASYS_EXIT;
51
52 while (obusidx < *osize)
53 if (EV(acycleidx) < EV(ACYCLE))
54 {
55 memset(&(TB(0)), 0, sizeof(TB(0))*ENDBUS);
56 main_apass(ENGINE_PTR);
57 for (busidx=BUS_output_bus; busidx<ENDBUS_output_bus;busidx++)
58 {
59 TB(busidx) = (TB(busidx) > 1.0F) ? 1.0F : TB(busidx);
60
61 #if (ASYS_OTYPENAME == ASYS_SHORT)
62 TB(busidx) = (TB(busidx) < -1.0F) ? -1.0F : TB(busidx);
63 obuf[obusidx++] = (short) (32767.0F * TB(busidx));
64 #endif
65
66 #if (ASYS_OTYPENAME == ASYS_FLOAT)
67 obuf[obusidx++] = (TB(busidx) < -1.0F) ? -1.0F : TB(busidx);
68 #endif
69
70 }
71 EV(acycleidx)++;
72 }
73 else
74 {
75 EV(acycleidx) = 0;
76 if (EV(pass) == APASS)
77 {
78 EV(cpuload) = ksync();
79 EV(kcycleidx)++;
80 }
81 if (EV(kcycleidx) > EV(endkcycle))
82 {
83 *osize = obusidx;
84 return (EV(asys_exit_status) = ASYS_EXIT);
85 }
86 EV(pass) = IPASS;
87 EV(scorebeats) = EV(scoremult)*(EV(kcycleidx) - EV(kbase)) + EV(scorebase);
88 EV(absolutetime) = (EV(kcycleidx) - 1)*EV(KTIME);
89 main_ipass(ENGINE_PTR);
90 EV(pass) = KPASS;
91 main_control(ENGINE_PTR);
92 if (main_kpass(ENGINE_PTR))
93 {
94 *osize = obusidx;
95 return (EV(asys_exit_status) = ASYS_EXIT);
96 }
97 EV(pass) = APASS;
98 }
99
100 return ASYS_DONE;
101 }
102
103 #endif /* ASYS_ACTIVE_O */
104
105
106 #if defined(ASYS_ACTIVE_IO)
107
asys_iorun(ASYS_ITYPE ibuf[],int * isize,ASYS_OTYPE obuf[],int * osize)108 int asys_iorun(ASYS_ITYPE ibuf[], int * isize,ASYS_OTYPE obuf[], int * osize)
109
110 {
111 int ibusidx = 0;
112 int obusidx = 0;
113 int busidx;
114
115 if (EV(asys_exit_status) == ASYS_EXIT)
116 return ASYS_EXIT;
117
118 while ((obusidx < *osize) && (ibusidx < *isize))
119 if (EV(acycleidx) < EV(ACYCLE))
120 {
121 memset(&(TB(0)), 0, sizeof(TB(0))*ENDBUS);
122
123 #if (ASYS_ITYPENAME == ASYS_SHORT)
124 for(busidx=BUS_input_bus;busidx<ENDBUS_input_bus;busidx++)
125 TB(busidx) = 3.051851e-5F*ibuf[ibusidx++];
126 #endif
127
128 #if (ASYS_ITYPENAME == ASYS_FLOAT)
129 for(busidx=BUS_input_bus;busidx<ENDBUS_input_bus;busidx++)
130 TB(busidx) = ibuf[ibusidx++];
131 #endif
132
133 main_apass(ENGINE_PTR);
134 for (busidx=BUS_output_bus; busidx<ENDBUS_output_bus;busidx++)
135 {
136 TB(busidx) = (TB(busidx) > 1.0F) ? 1.0F : TB(busidx);
137
138 #if (ASYS_OTYPENAME == ASYS_SHORT)
139 TB(busidx) = (TB(busidx) < -1.0F) ? -1.0F : TB(busidx);
140 obuf[obusidx++] = (short) (32767.0F * TB(busidx));
141 #endif
142
143 #if (ASYS_OTYPENAME == ASYS_FLOAT)
144 obuf[obusidx++] = (TB(busidx) < -1.0F) ? -1.0F : TB(busidx);
145 #endif
146 }
147 EV(acycleidx)++;
148 }
149 else
150 {
151 EV(acycleidx) = 0;
152 if (EV(pass) == APASS)
153 {
154 EV(cpuload) = ksync();
155 EV(kcycleidx)++;
156 }
157 if (EV(kcycleidx) > EV(endkcycle))
158 {
159 *osize = obusidx;
160 *isize = ibusidx;
161 return (EV(asys_exit_status) = ASYS_EXIT);
162 }
163 EV(pass) = IPASS;
164 EV(scorebeats) = EV(scoremult)*(EV(kcycleidx) - EV(kbase)) + EV(scorebase);
165 EV(absolutetime) = (EV(kcycleidx) - 1)*EV(KTIME);
166 main_ipass(ENGINE_PTR);
167 EV(pass) = KPASS;
168 main_control(ENGINE_PTR);
169 if (main_kpass(ENGINE_PTR))
170 {
171 *osize = obusidx;
172 *isize = ibusidx;
173 return (EV(asys_exit_status) = ASYS_EXIT);
174 }
175 EV(pass) = APASS;
176 }
177
178 if (obusidx < *osize)
179 *osize = obusidx;
180 if (ibusidx < *isize)
181 *isize = ibusidx;
182 return ASYS_DONE;
183 }
184
185 #endif /* ASYS_ACTIVE_IO */
186
187
main(int argc,char * argv[])188 int main(int argc, char *argv[])
189
190 {
191 system_init(argc, argv, SAOL_SRATE);
192 effects_init(ENGINE_PTR);
193 main_initpass(ENGINE_PTR);
194
195 EV(kcycleidx) = EV(kbase);
196 EV(acycleidx) = EV(ACYCLE);
197 EV(pass) = IPASS;
198
199 asys_main();
200 shut_down(ENGINE_PTR);
201 return 0;
202 }
203
204
205
206
207
208