1 2 /* 3 # Sfront, a SAOL to C translator 4 # This file: Included file in sfront 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 #include <stdio.h> 41 #include <stdlib.h> 42 #include <math.h> 43 #include <float.h> 44 #include <string.h> 45 #include <errno.h> 46 #include <time.h> 47 #include <signal.h> 48 49 /********************************/ 50 /* readabiliy-improving defines */ 51 /********************************/ 52 53 #define ROUND(x) ( ((x) > 0.0F) ? ((int) ((x) + 0.5F)) : ((int) ((x) - 0.5F))) 54 #define POS(x) (((x) > 0.0F) ? x : 0.0F) 55 #define RMULT ((float)(1.0F/(RAND_MAX + 1.0F))) 56 57 #define NOTUSEDYET 0 58 #define TOBEPLAYED 1 59 #define PAUSED 2 60 #define PLAYING 3 61 #define ALLDONE 4 62 63 #define NOTLAUNCHED 0 64 #define LAUNCHED 1 65 66 #define ASYS_DONE 0 67 #define ASYS_EXIT 1 68 #define ASYS_ERROR 2 69 70 #define IPASS 1 71 #define KPASS 2 72 #define APASS 3 73 74 #define IOERROR_RETRY 256 75 76 /* integer type that holds a cast pointer */ 77 78 #define PSIZE long 79 80 /************************************/ 81 /* union for a data stack element */ 82 /************************************/ 83 84 typedef union { 85 86 float f; 87 int i; 88 unsigned int ui; 89 PSIZE ps; 90 91 } dstack; 92 93 /************************************/ 94 /* ntables: table entries for notes */ 95 /************************************/ 96 97 typedef struct tableinfo { 98 99 int len; /* length of table */ 100 float lenf; /* length of table, as a float */ 101 102 int start; /* loop start position */ 103 int end; /* loop end position */ 104 float sr; /* table sampling rate */ 105 float base; /* table base frequency */ 106 107 /* precomputed constants */ 108 int tend; /* len -1 if end==0 */ 109 float oconst; /* len*ATIME */ 110 111 unsigned int dint; /* doscil: 64-bit phase incr */ 112 unsigned int dfrac; 113 /* doscil: sinc interpolation */ 114 unsigned int sfui; /* scale_factor as unsigned int */ 115 float sffl; /* scale_factor as a float */ 116 unsigned int dsincr; /* sinc pointer increment (d=doscil) */ 117 118 float *t; /* pointer to table entries */ 119 float stamp; /* timestamp on table contents */ 120 char llmem; /* 1 if *t was malloced */ 121 122 } tableinfo; 123 124 /********************/ 125 /* tempo lines */ 126 /********************/ 127 128 typedef struct stempo_lines { 129 130 float t; /* trigger time */ 131 float newtempo; /* new tempo */ 132 133 } stempo_lines; 134 135 /********************/ 136 /* table lines */ 137 /********************/ 138 139 typedef struct stable_lines { 140 141 float t; /* trigger time */ 142 int gindex; /* global table to target */ 143 int size; /* size of data */ 144 void (*tmake) (); /* function */ 145 void * data; /* data block */ 146 147 } stable_lines; 148 149