199
|
1 /*
|
|
2
|
|
3 TiMidity -- Experimental MIDI to WAVE converter
|
|
4 Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
|
|
5
|
|
6 This program is free software; you can redistribute it and/or modify
|
|
7 it under the terms of the GNU General Public License as published by
|
|
8 the Free Software Foundation; either version 2 of the License, or
|
|
9 (at your option) any later version.
|
|
10
|
|
11 This program is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with this program; if not, write to the Free Software
|
|
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
19
|
|
20 */
|
|
21
|
|
22 #if HAVE_CONFIG_H
|
|
23 # include <config.h>
|
|
24 #endif
|
|
25
|
|
26 #include <stdio.h>
|
|
27
|
|
28 #include "SDL_sound.h"
|
|
29
|
|
30 #define __SDL_SOUND_INTERNAL__
|
|
31 #include "SDL_sound_internal.h"
|
|
32
|
|
33 #include "tables.h"
|
|
34
|
|
35 const Sint32 freq_table[128]=
|
|
36 {
|
|
37 8176, 8662, 9177, 9723,
|
|
38 10301, 10913, 11562, 12250,
|
|
39 12978, 13750, 14568, 15434,
|
|
40
|
|
41 16352, 17324, 18354, 19445,
|
|
42 20602, 21827, 23125, 24500,
|
|
43 25957, 27500, 29135, 30868,
|
|
44
|
|
45 32703, 34648, 36708, 38891,
|
|
46 41203, 43654, 46249, 48999,
|
|
47 51913, 55000, 58270, 61735,
|
|
48
|
|
49 65406, 69296, 73416, 77782,
|
|
50 82407, 87307, 92499, 97999,
|
|
51 103826, 110000, 116541, 123471,
|
|
52
|
|
53 130813, 138591, 146832, 155563,
|
|
54 164814, 174614, 184997, 195998,
|
|
55 207652, 220000, 233082, 246942,
|
|
56
|
|
57 261626, 277183, 293665, 311127,
|
|
58 329628, 349228, 369994, 391995,
|
|
59 415305, 440000, 466164, 493883,
|
|
60
|
|
61 523251, 554365, 587330, 622254,
|
|
62 659255, 698456, 739989, 783991,
|
|
63 830609, 880000, 932328, 987767,
|
|
64
|
|
65 1046502, 1108731, 1174659, 1244508,
|
|
66 1318510, 1396913, 1479978, 1567982,
|
|
67 1661219, 1760000, 1864655, 1975533,
|
|
68
|
|
69 2093005, 2217461, 2349318, 2489016,
|
|
70 2637020, 2793826, 2959955, 3135963,
|
|
71 3322438, 3520000, 3729310, 3951066,
|
|
72
|
|
73 4186009, 4434922, 4698636, 4978032,
|
|
74 5274041, 5587652, 5919911, 6271927,
|
|
75 6644875, 7040000, 7458620, 7902133,
|
|
76
|
|
77 8372018, 8869844, 9397273, 9956063,
|
|
78 10548082, 11175303, 11839822, 12543854
|
|
79 };
|
|
80
|
|
81 /* v=2.^((x/127-1) * 6) */
|
|
82 const double vol_table[128] =
|
|
83 {
|
|
84 0.015625, 0.016145143728351113, 0.016682602624583379, 0.017237953096759438,
|
|
85 0.017811790741104401, 0.01840473098076444, 0.019017409725829021, 0.019650484055324921,
|
|
86 0.020304632921913132, 0.020980557880044631, 0.021678983838355849, 0.02240065983711079,
|
|
87 0.023146359851523596, 0.023916883621822989, 0.024713057510949051, 0.025535735390801884,
|
|
88 0.026385799557992876, 0.027264161680080529, 0.028171763773305786, 0.029109579212875332,
|
|
89 0.030078613776876421, 0.031079906724942836, 0.032114531912828696, 0.033183598944085631,
|
|
90 0.034288254360078256, 0.035429682869614412, 0.036609108619508737, 0.037827796507442342,
|
|
91 0.039087053538526394, 0.040388230227024875, 0.041732722044739302, 0.043121970917609151,
|
|
92 0.044557466772132896, 0.046040749133268132, 0.047573408775524545, 0.049157089429020417,
|
|
93 0.050793489542332405, 0.05248436410402918, 0.054231526524842463, 0.056036850582493913,
|
|
94 0.057902272431264008, 0.059829792678457581, 0.061821478529993396, 0.063879466007418645,
|
|
95 0.066005962238725971, 0.068203247825430205, 0.070473679288442961, 0.072819691595368496,
|
|
96 0.075243800771931268, 0.077748606600335793, 0.080336795407452768, 0.083011142945821612,
|
|
97 0.085774517370559328, 0.088629882315368294, 0.091580300070941839, 0.094628934869176312,
|
|
98 0.097779056276712184, 0.10103404270144323, 0.1043973850157546, 0.1078726903003755,
|
|
99 0.11146368571286204, 0.11517422248485852, 0.11900828005242428, 0.12296997032385605,
|
|
100 0.12706354208958254, 0.13129338557886089, 0.13566403716816194, 0.14018018424629392,
|
|
101 0.14484667024148207, 0.14966849981579558, 0.15465084423249356, 0.15979904690204472,
|
|
102 0.16511862911277009, 0.17061529595225433, 0.17629494242587571, 0.18216365977901747,
|
|
103 0.18822774202974024, 0.19449369271892172, 0.20096823188510385, 0.20765830327152621,
|
|
104 0.21457108177307616, 0.22171398113114205, 0.2290946618846218, 0.23672103958561411,
|
|
105 0.2446012932886038, 0.25274387432224471, 0.26115751535314891, 0.26985123975140174,
|
|
106 0.27883437126784744, 0.28811654403352405, 0.29770771289197112, 0.30761816407549192,
|
|
107 0.31785852623682015, 0.32843978184802081, 0.33937327897885317, 0.3506707434672246,
|
|
108 0.36234429149478936, 0.37440644258117928, 0.38687013301080181, 0.39974872970660535,
|
|
109 0.41305604456569134, 0.42680634927214656, 0.44101439060298442, 0.45569540624360722,
|
|
110 0.47086514112975281, 0.48653986433345225, 0.50273638651110641, 0.51947207793239625,
|
|
111 0.53676488710936021, 0.55463336004561792, 0.57309666012638816, 0.59217458867062556,
|
|
112 0.61188760616732485, 0.63225685421876243, 0.65330417821421161, 0.67505215075844849,
|
|
113 0.69752409588017272, 0.72074411404630734, 0.74473710800900605, 0.76952880951308478,
|
|
114 0.79514580689252357, 0.82161557358563286, 0.84896649759946774, 0.87722791195508854,
|
|
115 0.90643012614631979, 0.93660445864574493, 0.96778327049280244, 1
|
|
116 };
|
|
117
|
|
118 const double bend_fine[256] = {
|
|
119 1, 1.0002256593050698, 1.0004513695322617, 1.0006771306930664,
|
|
120 1.0009029427989777, 1.0011288058614922, 1.0013547198921082, 1.0015806849023274,
|
|
121 1.0018067009036538, 1.002032767907594, 1.0022588859256572, 1.0024850549693551,
|
|
122 1.0027112750502025, 1.0029375461797159, 1.0031638683694153, 1.0033902416308227,
|
|
123 1.0036166659754628, 1.0038431414148634, 1.0040696679605541, 1.0042962456240678,
|
|
124 1.0045228744169397, 1.0047495543507072, 1.0049762854369111, 1.0052030676870944,
|
|
125 1.0054299011128027, 1.0056567857255843, 1.00588372153699, 1.006110708558573,
|
|
126 1.0063377468018897, 1.0065648362784985, 1.0067919769999607, 1.0070191689778405,
|
|
127 1.0072464122237039, 1.0074737067491204, 1.0077010525656616, 1.0079284496849015,
|
|
128 1.0081558981184175, 1.008383397877789, 1.008610948974598, 1.0088385514204294,
|
|
129 1.0090662052268706, 1.0092939104055114, 1.0095216669679448, 1.0097494749257656,
|
|
130 1.009977334290572, 1.0102052450739643, 1.0104332072875455, 1.0106612209429215,
|
|
131 1.0108892860517005, 1.0111174026254934, 1.0113455706759138, 1.0115737902145781,
|
|
132 1.0118020612531047, 1.0120303838031153, 1.0122587578762337, 1.012487183484087,
|
|
133 1.0127156606383041, 1.0129441893505169, 1.0131727696323602, 1.0134014014954713,
|
|
134 1.0136300849514894, 1.0138588200120575, 1.0140876066888203, 1.0143164449934257,
|
|
135 1.0145453349375237, 1.0147742765327674, 1.0150032697908125, 1.0152323147233171,
|
|
136 1.015461411341942, 1.0156905596583505, 1.0159197596842091, 1.0161490114311862,
|
|
137 1.0163783149109531, 1.0166076701351838, 1.0168370771155553, 1.0170665358637463,
|
|
138 1.0172960463914391, 1.0175256087103179, 1.0177552228320703, 1.0179848887683858,
|
|
139 1.0182146065309567, 1.0184443761314785, 1.0186741975816487, 1.0189040708931674,
|
|
140 1.0191339960777379, 1.0193639731470658, 1.0195940021128593, 1.0198240829868295,
|
|
141 1.0200542157806898, 1.0202844005061564, 1.0205146371749483, 1.0207449257987866,
|
|
142 1.0209752663893958, 1.0212056589585028, 1.0214361035178368, 1.0216666000791297,
|
|
143 1.0218971486541166, 1.0221277492545349, 1.0223584018921241, 1.0225891065786274,
|
|
144 1.0228198633257899, 1.0230506721453596, 1.023281533049087, 1.0235124460487257,
|
|
145 1.0237434111560313, 1.0239744283827625, 1.0242054977406807, 1.0244366192415495,
|
|
146 1.0246677928971357, 1.0248990187192082, 1.025130296719539, 1.0253616269099028,
|
|
147 1.0255930093020766, 1.0258244439078401, 1.0260559307389761, 1.0262874698072693,
|
|
148 1.0265190611245079, 1.0267507047024822, 1.0269824005529853, 1.027214148687813,
|
|
149 1.0274459491187637, 1.0276778018576387, 1.0279097069162415, 1.0281416643063788,
|
|
150 1.0283736740398595, 1.0286057361284953, 1.0288378505841009, 1.0290700174184932,
|
|
151 1.0293022366434921, 1.0295345082709197, 1.0297668323126017, 1.0299992087803651,
|
|
152 1.030231637686041, 1.0304641190414621, 1.0306966528584645, 1.0309292391488862,
|
|
153 1.0311618779245688, 1.0313945691973556, 1.0316273129790936, 1.0318601092816313,
|
|
154 1.0320929581168212, 1.0323258594965172, 1.0325588134325767, 1.0327918199368598,
|
|
155 1.0330248790212284, 1.0332579906975481, 1.0334911549776868, 1.033724371873515,
|
|
156 1.0339576413969056, 1.0341909635597348, 1.0344243383738811, 1.0346577658512259,
|
|
157 1.034891246003653, 1.0351247788430489, 1.0353583643813031, 1.0355920026303078,
|
|
158 1.0358256936019572, 1.0360594373081489, 1.0362932337607829, 1.0365270829717617,
|
|
159 1.0367609849529913, 1.0369949397163791, 1.0372289472738365, 1.0374630076372766,
|
|
160 1.0376971208186156, 1.0379312868297725, 1.0381655056826686, 1.0383997773892284,
|
|
161 1.0386341019613787, 1.0388684794110492, 1.0391029097501721, 1.0393373929906822,
|
|
162 1.0395719291445176, 1.0398065182236185, 1.0400411602399278, 1.0402758552053915,
|
|
163 1.0405106031319582, 1.0407454040315787, 1.0409802579162071, 1.0412151647977996,
|
|
164 1.0414501246883161, 1.0416851375997183, 1.0419202035439705, 1.0421553225330404,
|
|
165 1.042390494578898, 1.042625719693516, 1.0428609978888699, 1.043096329176938,
|
|
166 1.0433317135697009, 1.0435671510791424, 1.0438026417172486, 1.0440381854960086,
|
|
167 1.0442737824274138, 1.044509432523459, 1.044745135796141, 1.0449808922574599,
|
|
168 1.0452167019194181, 1.0454525647940205, 1.0456884808932754, 1.0459244502291931,
|
|
169 1.0461604728137874, 1.0463965486590741, 1.046632677777072, 1.0468688601798024,
|
|
170 1.0471050958792898, 1.047341384887561, 1.0475777272166455, 1.047814122878576,
|
|
171 1.048050571885387, 1.0482870742491166, 1.0485236299818055, 1.0487602390954964,
|
|
172 1.0489969016022356, 1.0492336175140715, 1.0494703868430555, 1.0497072096012419,
|
|
173 1.0499440858006872, 1.0501810154534512, 1.050417998571596, 1.0506550351671864,
|
|
174 1.0508921252522903, 1.0511292688389782, 1.0513664659393229, 1.0516037165654004,
|
|
175 1.0518410207292894, 1.0520783784430709, 1.0523157897188296, 1.0525532545686513,
|
|
176 1.0527907730046264, 1.0530283450388465, 1.0532659706834067, 1.0535036499504049,
|
|
177 1.0537413828519411, 1.0539791694001188, 1.0542170096070436, 1.0544549034848243,
|
|
178 1.0546928510455722, 1.0549308523014012, 1.0551689072644284, 1.0554070159467728,
|
|
179 1.0556451783605572, 1.0558833945179062, 1.0561216644309479, 1.0563599881118126,
|
|
180 1.0565983655726334, 1.0568367968255465, 1.0570752818826903, 1.0573138207562065,
|
|
181 1.057552413458239, 1.0577910600009348, 1.0580297603964437, 1.058268514656918,
|
|
182 1.0585073227945128, 1.0587461848213857, 1.058985100749698, 1.0592240705916123
|
|
183 };
|
|
184
|
|
185 const double bend_coarse[128] = {
|
|
186 1, 1.0594630943592953, 1.122462048309373, 1.189207115002721,
|
|
187 1.2599210498948732, 1.3348398541700344, 1.4142135623730951, 1.4983070768766815,
|
|
188 1.5874010519681994, 1.681792830507429, 1.7817974362806785, 1.8877486253633868,
|
|
189 2, 2.1189261887185906, 2.244924096618746, 2.3784142300054421,
|
|
190 2.5198420997897464, 2.6696797083400687, 2.8284271247461903, 2.996614153753363,
|
|
191 3.1748021039363992, 3.363585661014858, 3.5635948725613571, 3.7754972507267741,
|
|
192 4, 4.2378523774371812, 4.4898481932374912, 4.7568284600108841,
|
|
193 5.0396841995794928, 5.3393594166801366, 5.6568542494923806, 5.993228307506727,
|
|
194 6.3496042078727974, 6.727171322029716, 7.1271897451227151, 7.5509945014535473,
|
|
195 8, 8.4757047548743625, 8.9796963864749824, 9.5136569200217682,
|
|
196 10.079368399158986, 10.678718833360273, 11.313708498984761, 11.986456615013454,
|
|
197 12.699208415745595, 13.454342644059432, 14.25437949024543, 15.101989002907095,
|
|
198 16, 16.951409509748721, 17.959392772949972, 19.027313840043536,
|
|
199 20.158736798317967, 21.357437666720553, 22.627416997969522, 23.972913230026901,
|
|
200 25.398416831491197, 26.908685288118864, 28.508758980490853, 30.203978005814196,
|
|
201 32, 33.902819019497443, 35.918785545899944, 38.054627680087073,
|
|
202 40.317473596635935, 42.714875333441107, 45.254833995939045, 47.945826460053802,
|
|
203 50.796833662982394, 53.817370576237728, 57.017517960981706, 60.407956011628393,
|
|
204 64, 67.805638038994886, 71.837571091799887, 76.109255360174146,
|
|
205 80.63494719327187, 85.429750666882214, 90.509667991878089, 95.891652920107603,
|
|
206 101.59366732596479, 107.63474115247546, 114.03503592196341, 120.81591202325679,
|
|
207 128, 135.61127607798977, 143.67514218359977, 152.21851072034829,
|
|
208 161.26989438654374, 170.85950133376443, 181.01933598375618, 191.78330584021521,
|
|
209 203.18733465192958, 215.26948230495091, 228.07007184392683, 241.63182404651357,
|
|
210 256, 271.22255215597971, 287.35028436719938, 304.43702144069658,
|
|
211 322.53978877308765, 341.71900266752868, 362.03867196751236, 383.56661168043064,
|
|
212 406.37466930385892, 430.53896460990183, 456.14014368785394, 483.26364809302686,
|
|
213 512, 542.44510431195943, 574.70056873439876, 608.87404288139317,
|
|
214 645.0795775461753, 683.43800533505737, 724.07734393502471, 767.13322336086128,
|
|
215 812.74933860771785, 861.07792921980365, 912.28028737570787, 966.52729618605372,
|
|
216 1024, 1084.8902086239189, 1149.4011374687975, 1217.7480857627863,
|
|
217 1290.1591550923506, 1366.8760106701147, 1448.1546878700494, 1534.2664467217226
|
|
218 };
|