1
2 /*
3 # Sfront, a SAOL to C translator
4 # This file: Main loop for runtime
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
main(int argc,char * argv[])41 int main(int argc, char *argv[])
42
43 {
44 ENGINE_PTR_DECLARE_SEMICOLON
45 int busidx;
46
47 ENGINE_PTR_ASSIGNED_TO system_init(argc, argv, SAOL_SRATE);
48 if (ENGINE_PTR_IS_NULL) return -1;
49 effects_init(ENGINE_PTR);
50 main_initpass(ENGINE_PTR);
51 for (EV(kcycleidx)=EV(kbase); EV(kcycleidx)<=EV(endkcycle); EV(kcycleidx)++)
52 {
53 EV(pass) = IPASS;
54 EV(scorebeats) = EV(scoremult)*(EV(kcycleidx) - EV(kbase)) + EV(scorebase);
55 EV(absolutetime) = (EV(kcycleidx) - 1)*EV(KTIME);
56 main_ipass(ENGINE_PTR);
57 EV(pass) = KPASS;
58 main_control(ENGINE_PTR);
59 if (main_kpass(ENGINE_PTR))
60 break;
61 EV(pass) = APASS;
62 for (EV(acycleidx)=0; EV(acycleidx)<EV(ACYCLE); EV(acycleidx)++)
63 {
64 memset(&(TB(0)), 0, sizeof(TB(0))*ENDBUS);
65 main_apass(ENGINE_PTR);
66 for (busidx=BUS_output_bus; busidx<ENDBUS_output_bus;busidx++)
67 {
68 TB(busidx) = (TB(busidx) > 1.0F) ? 1.0F : TB(busidx);
69 TB(busidx) = (TB(busidx) < -1.0F) ? -1.0F : TB(busidx);
70 EV(asys_obuf)[EV(obusidx)++] = (short) (32767.0F * TB(busidx));
71 }
72 if (EV(obusidx) >= EV(asys_osize))
73 {
74 EV(obusidx) = 0;
75 if (asys_putbuf(&EV(asys_obuf), &EV(asys_osize)))
76 {
77 fprintf(stderr," Sfront: Audio output device problem\n\n");
78 EV(kcycleidx) = EV(endkcycle);
79 break;
80 }
81 }
82 }
83 EV(acycleidx) = 0;
84 EV(cpuload) = ksync();
85 }
86 shut_down(ENGINE_PTR);
87 return 0;
88 }
89
90
91
92
93
94