gosu 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL/include/SDL.h +108 -14
  3. data/dependencies/SDL/include/SDL_assert.h +81 -50
  4. data/dependencies/SDL/include/SDL_atomic.h +135 -35
  5. data/dependencies/SDL/include/SDL_audio.h +960 -355
  6. data/dependencies/SDL/include/SDL_bits.h +11 -6
  7. data/dependencies/SDL/include/SDL_blendmode.h +91 -14
  8. data/dependencies/SDL/include/SDL_clipboard.h +30 -7
  9. data/dependencies/SDL/include/SDL_config.h +277 -27
  10. data/dependencies/SDL/include/SDL_config_android.h +13 -38
  11. data/dependencies/SDL/include/SDL_config_iphoneos.h +21 -62
  12. data/dependencies/SDL/include/SDL_config_macosx.h +23 -92
  13. data/dependencies/SDL/include/SDL_config_minimal.h +1 -4
  14. data/dependencies/SDL/include/SDL_config_pandora.h +15 -22
  15. data/dependencies/SDL/include/SDL_config_psp.h +16 -37
  16. data/dependencies/SDL/include/SDL_config_windows.h +28 -91
  17. data/dependencies/SDL/include/SDL_config_winrt.h +33 -61
  18. data/dependencies/SDL/include/SDL_config_wiz.h +28 -56
  19. data/dependencies/SDL/include/SDL_copying.h +1 -1
  20. data/dependencies/SDL/include/SDL_cpuinfo.h +331 -71
  21. data/dependencies/SDL/include/SDL_egl.h +906 -280
  22. data/dependencies/SDL/include/SDL_endian.h +101 -47
  23. data/dependencies/SDL/include/SDL_error.h +70 -19
  24. data/dependencies/SDL/include/SDL_events.h +387 -79
  25. data/dependencies/SDL/include/SDL_filesystem.h +73 -64
  26. data/dependencies/SDL/include/SDL_gamecontroller.h +585 -125
  27. data/dependencies/SDL/include/SDL_gesture.h +36 -6
  28. data/dependencies/SDL/include/SDL_haptic.h +304 -210
  29. data/dependencies/SDL/include/SDL_hidapi.h +451 -0
  30. data/dependencies/SDL/include/SDL_hints.h +1286 -897
  31. data/dependencies/SDL/include/SDL_joystick.h +577 -130
  32. data/dependencies/SDL/include/SDL_keyboard.h +162 -63
  33. data/dependencies/SDL/include/SDL_keycode.h +7 -5
  34. data/dependencies/SDL/include/SDL_loadso.h +42 -8
  35. data/dependencies/SDL/include/SDL_locale.h +34 -32
  36. data/dependencies/SDL/include/SDL_log.h +212 -19
  37. data/dependencies/SDL/include/SDL_main.h +72 -17
  38. data/dependencies/SDL/include/SDL_messagebox.h +70 -23
  39. data/dependencies/SDL/include/SDL_metal.h +27 -32
  40. data/dependencies/SDL/include/SDL_misc.h +19 -15
  41. data/dependencies/SDL/include/SDL_mouse.h +262 -110
  42. data/dependencies/SDL/include/SDL_mutex.h +286 -66
  43. data/dependencies/SDL/include/SDL_name.h +1 -1
  44. data/dependencies/SDL/include/SDL_opengl.h +1 -1
  45. data/dependencies/SDL/include/SDL_opengles.h +1 -1
  46. data/dependencies/SDL/include/SDL_opengles2.h +2 -2
  47. data/dependencies/SDL/include/SDL_pixels.h +199 -34
  48. data/dependencies/SDL/include/SDL_platform.h +39 -2
  49. data/dependencies/SDL/include/SDL_power.h +23 -10
  50. data/dependencies/SDL/include/SDL_quit.h +1 -1
  51. data/dependencies/SDL/include/SDL_rect.h +78 -28
  52. data/dependencies/SDL/include/SDL_render.h +1204 -472
  53. data/dependencies/SDL/include/SDL_revision.h +2 -2
  54. data/dependencies/SDL/include/SDL_rwops.h +605 -33
  55. data/dependencies/SDL/include/SDL_scancode.h +1 -1
  56. data/dependencies/SDL/include/SDL_sensor.h +76 -42
  57. data/dependencies/SDL/include/SDL_shape.h +38 -27
  58. data/dependencies/SDL/include/SDL_stdinc.h +96 -24
  59. data/dependencies/SDL/include/SDL_surface.h +571 -139
  60. data/dependencies/SDL/include/SDL_system.h +339 -101
  61. data/dependencies/SDL/include/SDL_syswm.h +50 -20
  62. data/dependencies/SDL/include/SDL_test.h +1 -1
  63. data/dependencies/SDL/include/SDL_test_assert.h +2 -2
  64. data/dependencies/SDL/include/SDL_test_common.h +23 -6
  65. data/dependencies/SDL/include/SDL_test_compare.h +1 -1
  66. data/dependencies/SDL/include/SDL_test_crc32.h +1 -1
  67. data/dependencies/SDL/include/SDL_test_font.h +3 -3
  68. data/dependencies/SDL/include/SDL_test_fuzzer.h +28 -26
  69. data/dependencies/SDL/include/SDL_test_harness.h +6 -6
  70. data/dependencies/SDL/include/SDL_test_images.h +1 -1
  71. data/dependencies/SDL/include/SDL_test_log.h +1 -1
  72. data/dependencies/SDL/include/SDL_test_md5.h +1 -1
  73. data/dependencies/SDL/include/SDL_test_memory.h +1 -1
  74. data/dependencies/SDL/include/SDL_test_random.h +2 -2
  75. data/dependencies/SDL/include/SDL_thread.h +226 -128
  76. data/dependencies/SDL/include/SDL_timer.h +129 -22
  77. data/dependencies/SDL/include/SDL_touch.h +48 -8
  78. data/dependencies/SDL/include/SDL_types.h +1 -1
  79. data/dependencies/SDL/include/SDL_version.h +72 -46
  80. data/dependencies/SDL/include/SDL_video.h +1266 -460
  81. data/dependencies/SDL/include/SDL_vulkan.h +100 -161
  82. data/dependencies/SDL/include/begin_code.h +22 -1
  83. data/dependencies/SDL/include/close_code.h +1 -1
  84. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  85. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  86. data/dependencies/SDL_sound/SDL_sound.c +83 -7
  87. data/dependencies/SDL_sound/SDL_sound.h +4 -4
  88. data/dependencies/SDL_sound/SDL_sound_aiff.c +9 -12
  89. data/dependencies/SDL_sound/SDL_sound_au.c +7 -7
  90. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +3 -3
  91. data/dependencies/SDL_sound/SDL_sound_flac.c +1 -1
  92. data/dependencies/SDL_sound/SDL_sound_internal.h +17 -10
  93. data/dependencies/SDL_sound/SDL_sound_modplug.c +25 -27
  94. data/dependencies/SDL_sound/SDL_sound_mp3.c +5 -17
  95. data/dependencies/SDL_sound/SDL_sound_raw.c +11 -11
  96. data/dependencies/SDL_sound/SDL_sound_shn.c +8 -7
  97. data/dependencies/SDL_sound/SDL_sound_voc.c +6 -4
  98. data/dependencies/SDL_sound/SDL_sound_vorbis.c +6 -11
  99. data/dependencies/SDL_sound/SDL_sound_wav.c +35 -29
  100. data/dependencies/SDL_sound/dr_flac.h +618 -220
  101. data/dependencies/SDL_sound/dr_mp3.h +263 -94
  102. data/dependencies/SDL_sound/libmodplug/fastmix.c +58 -64
  103. data/dependencies/SDL_sound/libmodplug/libmodplug.h +25 -103
  104. data/dependencies/SDL_sound/libmodplug/load_669.c +14 -17
  105. data/dependencies/SDL_sound/libmodplug/load_amf.c +11 -7
  106. data/dependencies/SDL_sound/libmodplug/load_ams.c +65 -22
  107. data/dependencies/SDL_sound/libmodplug/load_dbm.c +8 -4
  108. data/dependencies/SDL_sound/libmodplug/load_dmf.c +55 -25
  109. data/dependencies/SDL_sound/libmodplug/load_far.c +9 -13
  110. data/dependencies/SDL_sound/libmodplug/load_gdm.c +448 -0
  111. data/dependencies/SDL_sound/libmodplug/load_it.c +45 -49
  112. data/dependencies/SDL_sound/libmodplug/load_mdl.c +80 -53
  113. data/dependencies/SDL_sound/libmodplug/load_med.c +20 -12
  114. data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
  115. data/dependencies/SDL_sound/libmodplug/load_mt2.c +29 -17
  116. data/dependencies/SDL_sound/libmodplug/load_okt.c +12 -8
  117. data/dependencies/SDL_sound/libmodplug/load_psm.c +101 -78
  118. data/dependencies/SDL_sound/libmodplug/load_ptm.c +18 -17
  119. data/dependencies/SDL_sound/libmodplug/load_s3m.c +9 -7
  120. data/dependencies/SDL_sound/libmodplug/load_stm.c +3 -2
  121. data/dependencies/SDL_sound/libmodplug/load_ult.c +2 -2
  122. data/dependencies/SDL_sound/libmodplug/load_umx.c +315 -35
  123. data/dependencies/SDL_sound/libmodplug/load_xm.c +25 -21
  124. data/dependencies/SDL_sound/libmodplug/mmcmp.c +295 -149
  125. data/dependencies/SDL_sound/libmodplug/modplug.c +7 -123
  126. data/dependencies/SDL_sound/libmodplug/modplug.h +32 -29
  127. data/dependencies/SDL_sound/libmodplug/snd_dsp.c +0 -1
  128. data/dependencies/SDL_sound/libmodplug/snd_flt.c +2 -2
  129. data/dependencies/SDL_sound/libmodplug/snd_fx.c +24 -18
  130. data/dependencies/SDL_sound/libmodplug/sndfile.c +55 -156
  131. data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -12
  132. data/dependencies/SDL_sound/libmodplug/tables.h +10 -15
  133. data/dependencies/SDL_sound/stb_vorbis.h +508 -325
  134. data/dependencies/{al_soft → mojoAL}/AL/al.h +38 -30
  135. data/dependencies/{al_soft → mojoAL}/AL/alc.h +27 -56
  136. data/dependencies/mojoAL/mojoal.c +4594 -0
  137. data/ext/gosu/extconf.rb +29 -30
  138. data/include/Gosu/Audio.hpp +70 -85
  139. data/include/Gosu/Color.hpp +19 -11
  140. data/include/Gosu/Font.hpp +40 -44
  141. data/include/Gosu/Graphics.hpp +58 -71
  142. data/include/Gosu/GraphicsBase.hpp +26 -33
  143. data/include/Gosu/Image.hpp +56 -62
  144. data/include/Gosu/ImageData.hpp +23 -27
  145. data/include/Gosu/Inspection.hpp +1 -4
  146. data/include/Gosu/TextInput.hpp +34 -40
  147. data/include/Gosu/Version.hpp +1 -1
  148. data/include/Gosu/Window.hpp +71 -70
  149. data/lib/SDL2.dll +0 -0
  150. data/lib/gosu/compat.rb +24 -37
  151. data/lib/gosu.rb +2 -2
  152. data/lib64/SDL2.dll +0 -0
  153. data/src/Audio.cpp +86 -86
  154. data/src/AudioFile.hpp +6 -6
  155. data/src/AudioFileAudioToolbox.cpp +1 -1
  156. data/src/AudioFileSDLSound.cpp +1 -1
  157. data/src/AudioImpl.hpp +5 -5
  158. data/src/BitmapIO.cpp +0 -20
  159. data/src/BlockAllocator.cpp +2 -1
  160. data/src/Channel.cpp +22 -20
  161. data/src/Color.cpp +12 -9
  162. data/src/EmptyImageData.hpp +15 -17
  163. data/src/FileUnix.cpp +1 -1
  164. data/src/FileWin.cpp +1 -1
  165. data/src/Font.cpp +48 -53
  166. data/src/Graphics.cpp +135 -143
  167. data/src/Image.cpp +41 -42
  168. data/src/Input.cpp +1 -1
  169. data/src/InputUIKit.cpp +1 -1
  170. data/src/LargeImageData.cpp +108 -101
  171. data/src/LargeImageData.hpp +17 -15
  172. data/src/Log.hpp +6 -6
  173. data/src/Macro.cpp +35 -37
  174. data/src/Macro.hpp +11 -11
  175. data/src/Math.cpp +8 -1
  176. data/src/Resolution.cpp +12 -7
  177. data/src/RubyGosu.cxx +5 -5
  178. data/src/TexChunk.cpp +50 -41
  179. data/src/TexChunk.hpp +22 -22
  180. data/src/Text.cpp +37 -37
  181. data/src/TextBuilder.cpp +60 -57
  182. data/src/TextBuilder.hpp +20 -20
  183. data/src/TextInput.cpp +127 -135
  184. data/src/TrueTypeFont.cpp +107 -107
  185. data/src/TrueTypeFont.hpp +39 -38
  186. data/src/TrueTypeFontApple.cpp +19 -22
  187. data/src/TrueTypeFontUnix.cpp +21 -26
  188. data/src/TrueTypeFontWin.cpp +30 -30
  189. data/src/Window.cpp +95 -86
  190. data/src/WindowUIKit.cpp +46 -49
  191. metadata +7 -17
  192. data/dependencies/SDL/include/SDL_config_os2.h +0 -188
  193. data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
  194. data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
  195. data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
  196. data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
  197. data/dependencies/al_soft/AL/alext.h +0 -585
  198. data/dependencies/al_soft/AL/efx-creative.h +0 -3
  199. data/dependencies/al_soft/AL/efx-presets.h +0 -402
  200. data/dependencies/al_soft/AL/efx.h +0 -762
  201. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  202. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  203. data/lib/OpenAL32.dll +0 -0
  204. data/lib64/OpenAL32.dll +0 -0
@@ -1,1143 +0,0 @@
1
- /*
2
-
3
- MikMod Sound System
4
-
5
- By Jake Stine of Divine Entertainment (1996-2000)
6
-
7
- Support:
8
- If you find problems with this code, send mail to:
9
- air@divent.org
10
-
11
- Distribution / Code rights:
12
- Use this source code in any fashion you see fit. Giving me credit where
13
- credit is due is optional, depending on your own levels of integrity and
14
- honesty.
15
-
16
- -----------------------------------------
17
- Module: LOAD_PAT
18
-
19
- PAT sample loader.
20
- by Peter Grootswagers (2006)
21
- <email:pgrootswagers@planet.nl>
22
-
23
- It's primary purpose is loading samples for the .abc and .mid modules
24
- Can also be used stand alone, in that case a tune (frere Jacques)
25
- is generated using al samples available in the .pat file
26
-
27
- Portability:
28
- All systems - all compilers (hopefully)
29
- */
30
-
31
- #include "libmodplug.h"
32
-
33
- #include <stdlib.h>
34
- #include <time.h>
35
- #include <string.h>
36
- #include <math.h>
37
- #include <ctype.h>
38
- #ifndef _WIN32
39
- #include <limits.h> // for PATH_MAX
40
- #endif
41
- #ifndef PATH_MAX
42
- #define PATH_MAX 256
43
- #endif
44
-
45
- #include "load_pat.h"
46
-
47
- #ifdef MSC_VER
48
- #define DIRDELIM '\\'
49
- #define TIMIDITYCFG "C:\\TIMIDITY\\TIMIDITY.CFG"
50
- #define PATHFORPAT "C:\\TIMIDITY\\INSTRUMENTS"
51
- #else
52
- #define DIRDELIM '/'
53
- #define TIMIDITYCFG "/usr/local/share/timidity/timidity.cfg"
54
- #define PATHFORPAT "/usr/local/share/timidity/instruments"
55
- #endif
56
-
57
- #define PAT_ENV_PATH2CFG "MMPAT_PATH_TO_CFG"
58
-
59
- /* !!! FIXME: global state */
60
- // 128 gm and 63 drum
61
- #define MAXSMP 191
62
- static char midipat[MAXSMP][PATH_MAX];
63
- static char pathforpat[PATH_MAX];
64
- static char timiditycfg[PATH_MAX];
65
-
66
- #pragma pack(1)
67
-
68
- typedef struct {
69
- char header[12]; // ascizz GF1PATCH110
70
- char gravis_id[10]; // allways ID#000002
71
- char description[60];
72
- BYTE instruments;
73
- BYTE voices;
74
- BYTE channels;
75
- WORD waveforms;
76
- WORD master_volume;
77
- DWORD data_size;
78
- char reserved[36];
79
- } PatchHeader;
80
-
81
- typedef struct {
82
- WORD instrument_id;
83
- char instrument_name[16];
84
- DWORD instrument_size;
85
- BYTE layers;
86
- char reserved[40];
87
- } InstrumentHeader;
88
-
89
- typedef struct {
90
- BYTE layer_dup;
91
- BYTE layer_id;
92
- DWORD layer_size;
93
- BYTE samples;
94
- char reserved[40];
95
- } LayerHeader;
96
-
97
- typedef struct {
98
- char wave_name[7];
99
- BYTE fractions;
100
- DWORD wave_size;
101
- DWORD start_loop;
102
- DWORD end_loop;
103
- WORD sample_rate;
104
- DWORD low_frequency ;
105
- DWORD high_frequency;
106
- DWORD root_frequency;
107
- short int tune;
108
- BYTE balance;
109
- BYTE envelope_rate[6];
110
- BYTE envelope_offset[6];
111
- BYTE tremolo_sweep;
112
- BYTE tremolo_rate;
113
- BYTE tremolo_depth;
114
- BYTE vibrato_sweep;
115
- BYTE vibrato_rate;
116
- BYTE vibrato_depth;
117
- BYTE modes;
118
- DWORD scale_frequency;
119
- DWORD scale_factor;
120
- char reserved[32];
121
- } WaveHeader;
122
-
123
- // WaveHeader.modes bits
124
- #define PAT_16BIT 1
125
- #define PAT_UNSIGNED 2
126
- #define PAT_LOOP 4
127
- #define PAT_PINGPONG 8
128
- #define PAT_BACKWARD 16
129
- #define PAT_SUSTAIN 32
130
- #define PAT_ENVELOPE 64
131
- #define PAT_CLAMPED 128
132
-
133
- #define C4SPD 8363
134
- #define C4mHz 523251
135
- #define C4 523.251f
136
- #define PI 3.141592653589793f
137
- #define OMEGA ((2.0f * PI * C4)/(float)C4SPD)
138
-
139
- /**************************************************************************
140
- **************************************************************************/
141
- /* !!! FIXME: global state */
142
- static BYTE pat_gm_used[MAXSMP];
143
- static BYTE pat_loops[MAXSMP];
144
-
145
- /**************************************************************************
146
- **************************************************************************/
147
-
148
- static SDL_INLINE int IsAlpha(const char c) {
149
- return ( ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) );
150
- }
151
-
152
- static SDL_INLINE int IsBlank(const char c) {
153
- return ( (c == ' ') || (c == '\t') );
154
- }
155
-
156
-
157
- typedef struct _PATHANDLE
158
- {
159
- char patname[16];
160
- int samples;
161
- } PATHANDLE;
162
-
163
- // local prototypes
164
- static int pat_getopt(const char *s, const char *o, int dflt);
165
-
166
- static void pat_message(const char *s1, const char *s2)
167
- {
168
- char txt[256];
169
- if( SDL_strlen(s1) + SDL_strlen(s2) > 255 ) return;
170
- SDL_snprintf(txt, sizeof (txt), s1, s2);
171
- SDL_LogInfo(SDL_LOG_CATEGORY_AUDIO, "load_pat > %s\n", txt);
172
- }
173
-
174
- void pat_resetsmp(void)
175
- {
176
- int i;
177
- for( i=0; i<MAXSMP; i++ ) {
178
- pat_loops[i] = 0;
179
- pat_gm_used[i] = 0;
180
- }
181
- }
182
-
183
- int pat_numsmp()
184
- {
185
- return SDL_strlen((const char *)pat_gm_used);
186
- }
187
-
188
- int pat_numinstr(void)
189
- {
190
- return SDL_strlen((const char *)pat_gm_used);
191
- }
192
-
193
- int pat_smptogm(int smp)
194
- {
195
- if( smp < MAXSMP )
196
- return pat_gm_used[smp - 1];
197
- return 1;
198
- }
199
-
200
- int pat_gmtosmp(int gm)
201
- {
202
- int smp;
203
- for( smp=0; pat_gm_used[smp]; smp++ )
204
- if( pat_gm_used[smp] == gm )
205
- return smp+1;
206
- if( smp < MAXSMP ) {
207
- pat_gm_used[smp] = gm;
208
- return smp+1;
209
- }
210
- return 1;
211
- }
212
-
213
- int pat_smplooped(int smp)
214
- {
215
- if( smp < MAXSMP ) return pat_loops[smp - 1];
216
- return 1;
217
- }
218
-
219
- const char *pat_gm_name(int gm)
220
- {
221
- static char buf[40];
222
- if( gm < 1 || gm > MAXSMP ) {
223
- SDL_snprintf(buf, sizeof (buf), "invalid gm %d", gm);
224
- return buf;
225
- }
226
- return midipat[gm - 1];
227
- }
228
-
229
- int pat_gm_drumnr(int n)
230
- {
231
- if( n < 25 ) return 129;
232
- if( n+129-25 < MAXSMP )
233
- return 129+n-25; // timidity.cfg drum patches start at 25
234
- return MAXSMP;
235
- }
236
-
237
- int pat_gm_drumnote(int n)
238
- {
239
- char *p;
240
- p = SDL_strchr(midipat[pat_gm_drumnr(n)-1], ':');
241
- if( p ) return pat_getopt(p+1, "note", n);
242
- return n;
243
- }
244
-
245
- static float pat_sinus(int i)
246
- {
247
- float res = SDL_sinf(OMEGA * (float)i);
248
- return res;
249
- }
250
-
251
- static float pat_square(int i)
252
- {
253
- float res = 30.0f * SDL_sinf(OMEGA * (float)i);
254
- if( res > 0.99f ) return 0.99f;
255
- if( res < -0.99f ) return -0.99f;
256
- return res;
257
- }
258
-
259
- static float pat_sawtooth(int i)
260
- {
261
- float res = OMEGA * (float)i;
262
- while( res > 2 * PI )
263
- res -= 2 * PI;
264
- i = 2;
265
- if( res > PI ) {
266
- res = PI - res;
267
- i = -2;
268
- }
269
- res = (float)i * res / PI;
270
- if( res > 0.9f ) return 1.0f - res;
271
- if( res < -0.9f ) return 1.0f + res;
272
- return res;
273
- }
274
-
275
- typedef float (*PAT_SAMPLE_FUN)(int);
276
-
277
- static PAT_SAMPLE_FUN pat_fun[] = { pat_sinus, pat_square, pat_sawtooth };
278
-
279
- long _mm_getfsize(MMSTREAM *mmpat) {
280
- long fsize;
281
- _mm_fseek(mmpat, 0L, SEEK_END);
282
- fsize = _mm_ftell(mmpat);
283
- _mm_fseek(mmpat, 0L, SEEK_SET);
284
- return(fsize);
285
- }
286
-
287
- void pat_init_patnames(void)
288
- {
289
- int z, i, nsources, isdrumset, nskip, pfnlen;
290
- char *p, *q;
291
- char line[PATH_MAX];
292
- char cfgsources[5][PATH_MAX];
293
- MMSTREAM *mmcfg;
294
- SDL_memset(cfgsources, 0, sizeof (cfgsources));
295
- SDL_strlcpy(pathforpat, PATHFORPAT, PATH_MAX);
296
- SDL_strlcpy(timiditycfg, TIMIDITYCFG, PATH_MAX);
297
- p = SDL_getenv(PAT_ENV_PATH2CFG);
298
- if( p ) {
299
- SDL_snprintf(timiditycfg, sizeof (timiditycfg), "%s/timidity.cfg", p);
300
- SDL_snprintf(pathforpat, sizeof (pathforpat), "%s", p);
301
- }
302
- SDL_strlcpy(cfgsources[0], timiditycfg, PATH_MAX - 1);
303
- nsources = 1;
304
-
305
- for( i=0; i<MAXSMP; i++ ) midipat[i][0] = '\0';
306
-
307
- for ( z=0; z<5; z++ ) {
308
- if (cfgsources[z][0] == 0) continue;
309
- mmcfg = _mm_fopen(cfgsources[z],"r");
310
- if( !mmcfg ) {
311
- pat_message("can not open %s, use environment variable " PAT_ENV_PATH2CFG " for the directory", cfgsources[z]);
312
- }
313
- else {
314
- // read in bank 0 and drum patches
315
- isdrumset = 0;
316
- _mm_fgets(mmcfg, line, PATH_MAX);
317
- while( !_mm_feof(mmcfg) ) {
318
- if( SDL_isdigit(line[0]) || (IsBlank(line[0]) && SDL_isdigit(line[1])) ) {
319
- p = line;
320
- // get pat number
321
- while ( SDL_isspace(*p) ) p ++;
322
- i = SDL_atoi(p);
323
- while ( SDL_isdigit(*p) ) p ++;
324
- while ( SDL_isspace(*p) ) p ++;
325
- // get pat file name
326
- if( *p && i < MAXSMP && i >= 0 && *p != '#' ) {
327
- q = isdrumset ? midipat[pat_gm_drumnr(i)-1] : midipat[i];
328
- pfnlen = 0;
329
- while( *p && !SDL_isspace(*p) && *p != '#' && pfnlen < 128 ) {
330
- pfnlen ++;
331
- *q++ = *p++;
332
- }
333
- if( IsBlank(*p) && *(p+1) != '#' && pfnlen < 128 ) {
334
- *q++ = ':'; pfnlen ++;
335
- while( SDL_isspace(*p) ) {
336
- while( SDL_isspace(*p) ) p++;
337
- if ( *p == '#' ) { // comment
338
-
339
- } else while( *p && !SDL_isspace(*p) && pfnlen < 128 ) {
340
- pfnlen ++;
341
- *q++ = *p++;
342
- }
343
- if( SDL_isspace(*p) ) { *q++ = ' '; pfnlen++; }
344
- }
345
- }
346
- *q++ = '\0';
347
- }
348
- }
349
- if( !SDL_strncmp(line,"drumset",7) ) isdrumset = 1;
350
- if( !SDL_strncmp(line,"source",6) && nsources < 5 ) {
351
- q = cfgsources[nsources];
352
- p = &line[7];
353
- while ( SDL_isspace(*p) ) p ++;
354
- pfnlen = 0;
355
- while ( *p && *p != '#' && !SDL_isspace(*p) && pfnlen < 128 ) {
356
- pfnlen ++;
357
- *q++ = *p++;
358
- }
359
- *q = 0; // null termination
360
- nsources++;
361
- }
362
- _mm_fgets(mmcfg, line, PATH_MAX);
363
-
364
- } /* end file parsing */
365
- _mm_fclose(mmcfg);
366
- }
367
- }
368
- q = midipat[0];
369
- nskip = 0;
370
- // make all empty patches duplicates the previous valid one.
371
- for( i=0; i<MAXSMP; i++ ) {
372
- if( midipat[i][0] ) q = midipat[i];
373
- else {
374
- if( midipat[i] != q)
375
- SDL_strlcpy(midipat[i], q, PATH_MAX);
376
- if( midipat[i][0] == '\0' ) nskip++;
377
- }
378
- }
379
- if( nskip ) {
380
- for( i=MAXSMP; i-- > 0; ) {
381
- if( midipat[i][0] ) q = midipat[i];
382
- else if( midipat[i] != q )
383
- SDL_strlcpy(midipat[i], q, PATH_MAX);
384
- }
385
- }
386
- }
387
-
388
- static char *pat_build_path(char *fname, const size_t fnamelen, int pat)
389
- {
390
- char *ps;
391
- char *patfile = midipat[pat];
392
- int isabspath = (patfile[0] == '/');
393
- if ( isabspath ) patfile ++;
394
- ps = SDL_strrchr(patfile, ':');
395
- if( ps ) {
396
- SDL_snprintf(fname, fnamelen, "%s%c%s", isabspath ? "" : pathforpat, DIRDELIM, patfile);
397
- char *replaceptr = SDL_strrchr(fname, ':');
398
- SDL_assert(replaceptr != NULL);
399
- *replaceptr = '\0';
400
- SDL_strlcat(fname, ".pat", fnamelen);
401
- return ps;
402
- }
403
- SDL_snprintf(fname, fnamelen, "%s%c%s.pat", isabspath ? "" : pathforpat, DIRDELIM, patfile);
404
- return 0;
405
- }
406
-
407
- static void pat_read_patname(PATHANDLE *h, MMFILE *mmpat) {
408
- InstrumentHeader ih;
409
- mmfseek(mmpat,sizeof(PatchHeader), SEEK_SET);
410
- mmreadUBYTES((BYTE *)&ih, sizeof(InstrumentHeader), mmpat);
411
- SDL_strlcpy(h->patname, ih.instrument_name, 16);
412
- h->patname[15] = '\0';
413
- }
414
-
415
- static void pat_read_layerheader(MMSTREAM *mmpat, LayerHeader *hl)
416
- {
417
- _mm_fseek(mmpat,sizeof(PatchHeader)+sizeof(InstrumentHeader), SEEK_SET);
418
- _mm_read_UBYTES((BYTE *)hl, sizeof(LayerHeader), mmpat);
419
- }
420
-
421
- static void pat_get_layerheader(MMFILE *mmpat, LayerHeader *hl)
422
- {
423
- InstrumentHeader ih;
424
- mmfseek(mmpat,sizeof(PatchHeader), SEEK_SET);
425
- mmreadUBYTES((BYTE *)&ih, sizeof(InstrumentHeader), mmpat);
426
- mmreadUBYTES((BYTE *)hl, sizeof(LayerHeader), mmpat);
427
- SDL_strlcpy(hl->reserved, ih.instrument_name, 40);
428
- }
429
-
430
- static int pat_read_numsmp(MMFILE *mmpat) {
431
- LayerHeader hl;
432
- pat_get_layerheader(mmpat, &hl);
433
- return hl.samples;
434
- }
435
-
436
- static void pat_read_waveheader(MMSTREAM *mmpat, WaveHeader *hw, int layer)
437
- {
438
- long int pos, bestpos=0;
439
- LayerHeader hl;
440
- ULONG bestfreq, freqdist;
441
- int i;
442
- // read the very first and maybe only sample
443
- pat_read_layerheader(mmpat, &hl);
444
- if( hl.samples > 1 ) {
445
- if( layer ) {
446
- if( layer > hl.samples ) layer = hl.samples; // you don't fool me....
447
- for( i=1; i<layer; i++ ) {
448
- _mm_read_UBYTES((BYTE *)hw, sizeof(WaveHeader), mmpat);
449
- _mm_fseek(mmpat, hw->wave_size, SEEK_CUR);
450
- }
451
- }
452
- else {
453
- bestfreq = C4mHz * 1000; // big enough
454
- for( i=0; i<hl.samples; i++ ) {
455
- pos = _mm_ftell(mmpat);
456
- _mm_read_UBYTES((BYTE *)hw, sizeof(WaveHeader), mmpat);
457
- if( hw->root_frequency > C4mHz )
458
- freqdist = hw->root_frequency - C4mHz;
459
- else
460
- freqdist = 2 * (C4mHz - hw->root_frequency);
461
- if( freqdist < bestfreq ) {
462
- bestfreq = freqdist;
463
- bestpos = pos;
464
- }
465
- _mm_fseek(mmpat, hw->wave_size, SEEK_CUR);
466
- }
467
- _mm_fseek(mmpat, bestpos, SEEK_SET);
468
- }
469
- }
470
- _mm_read_UBYTES((BYTE *)hw, sizeof(WaveHeader), mmpat);
471
- SDL_strlcpy(hw->reserved, hl.reserved, 32);
472
- hw->reserved[31] = 0;
473
- if( hw->start_loop >= hw->wave_size ) {
474
- hw->start_loop = 0;
475
- hw->end_loop = 0;
476
- hw->modes &= ~PAT_LOOP; // mask off loop indicator
477
- }
478
- if( hw->end_loop > hw->wave_size )
479
- hw->end_loop = hw->wave_size;
480
- }
481
-
482
- static void pat_get_waveheader(MMFILE *mmpat, WaveHeader *hw, int layer)
483
- {
484
- long int pos, bestpos=0;
485
- LayerHeader hl;
486
- ULONG bestfreq, freqdist;
487
- int i;
488
- // read the very first and maybe only sample
489
- pat_get_layerheader(mmpat, &hl);
490
- if( hl.samples > 1 ) {
491
- if( layer ) {
492
- if( layer > hl.samples ) layer = hl.samples; // you don't fool me....
493
- for( i=1; i<layer; i++ ) {
494
- mmreadUBYTES((BYTE *)hw, sizeof(WaveHeader), mmpat);
495
- mmfseek(mmpat, hw->wave_size, SEEK_CUR);
496
- if ( mmpat->error ) {
497
- hw->wave_size = 0;
498
- return;
499
- }
500
- }
501
- }
502
- else {
503
- bestfreq = C4mHz * 1000; // big enough
504
- for( i=0; i<hl.samples; i++ ) {
505
- pos = mmftell(mmpat);
506
- mmreadUBYTES((BYTE *)hw, sizeof(WaveHeader), mmpat);
507
- if( hw->root_frequency > C4mHz )
508
- freqdist = hw->root_frequency - C4mHz;
509
- else
510
- freqdist = 2 * (C4mHz - hw->root_frequency);
511
- if( freqdist < bestfreq ) {
512
- bestfreq = freqdist;
513
- bestpos = pos;
514
- }
515
- mmfseek(mmpat, hw->wave_size, SEEK_CUR);
516
- }
517
- mmfseek(mmpat, bestpos, SEEK_SET);
518
- }
519
- }
520
- mmreadUBYTES((BYTE *)hw, sizeof(WaveHeader), mmpat);
521
- if( hw->start_loop >= hw->wave_size ) {
522
- hw->start_loop = 0;
523
- hw->end_loop = 0;
524
- hw->modes &= ~PAT_LOOP; // mask off loop indicator
525
- }
526
- if( hw->end_loop > hw->wave_size )
527
- hw->end_loop = hw->wave_size;
528
- }
529
-
530
- static int pat_readpat_attr(int pat, WaveHeader *hw, int layer)
531
- {
532
- char fname[128];
533
- unsigned long fsize;
534
- MMSTREAM *mmpat;
535
- pat_build_path(fname, sizeof (fname), pat);
536
- mmpat = _mm_fopen(fname, "r");
537
- if( !mmpat )
538
- return 0;
539
- fsize = _mm_getfsize(mmpat);
540
- pat_read_waveheader(mmpat, hw, layer);
541
- _mm_fclose(mmpat);
542
- if (hw->wave_size > fsize)
543
- return 0;
544
- return 1;
545
- }
546
-
547
- static void pat_amplify(char *b, int num, int amp, int m)
548
- {
549
- char *pb;
550
- BYTE *pu;
551
- short int *pi;
552
- WORD *pw;
553
- int i,n,v;
554
- n = num;
555
- if( m & PAT_16BIT ) { // 16 bit
556
- n >>= 1;
557
- if( m & 2 ) { // unsigned
558
- pw = (WORD *)b;
559
- for( i=0; i<n; i++ ) {
560
- v = (((int)(*pw) - 0x8000) * amp) / 100;
561
- if( v < -0x8000 ) v = -0x8000;
562
- if( v > 0x7fff ) v = 0x7fff;
563
- *pw++ = v + 0x8000;
564
- }
565
- }
566
- else {
567
- pi = (short int *)b;
568
- for( i=0; i<n; i++ ) {
569
- v = ((*pi) * amp) / 100;
570
- if( v < -0x8000 ) v = -0x8000;
571
- if( v > 0x7fff ) v = 0x7fff;
572
- *pi++ = v;
573
- }
574
- }
575
- }
576
- else {
577
- if( m & 2 ) { // unsigned
578
- pu = (BYTE *)b;
579
- for( i=0; i<n; i++ ) {
580
- v = (((int)(*pu) - 0x80) * amp) / 100;
581
- if( v < -0x80 ) v = -0x80;
582
- if( v > 0x7f ) v = 0x7f;
583
- *pu++ = v + 0x80;
584
- }
585
- }
586
- else {
587
- pb = (char *)b;
588
- for( i=0; i<n; i++ ) {
589
- v = ((*pb) * amp) / 100;
590
- if( v < -0x80 ) v = -0x80;
591
- if( v > 0x7f ) v = 0x7f;
592
- *pb++ = v;
593
- }
594
- }
595
- }
596
- }
597
-
598
- static int pat_getopt(const char *s, const char *o, int dflt)
599
- {
600
- const char *p;
601
- if( !s ) return dflt;
602
- p = SDL_strstr(s,o);
603
- if( !p ) return dflt;
604
- return SDL_atoi(SDL_strchr(p,'=')+1);
605
- }
606
-
607
- static void pat_readpat(int pat, char *dest, int num)
608
- {
609
- static int readlasttime = 0, wavesize = 0;
610
- static MMSTREAM *mmpat = 0;
611
- static char *opt = 0;
612
- int amp;
613
- char fname[128];
614
- WaveHeader hw;
615
- if( !readlasttime ) {
616
- opt=pat_build_path(fname, sizeof (fname), pat);
617
- mmpat = _mm_fopen(fname, "r");
618
- if( !mmpat )
619
- return;
620
- pat_read_waveheader(mmpat, &hw, 0);
621
- wavesize = hw.wave_size;
622
- }
623
- _mm_read_SBYTES(dest, num, mmpat);
624
- amp = pat_getopt(opt,"amp",100);
625
- if( amp != 100 ) pat_amplify(dest, num, amp, hw.modes);
626
- readlasttime += num;
627
- if( readlasttime < wavesize ) return;
628
- readlasttime = 0;
629
- _mm_fclose(mmpat);
630
- mmpat = 0;
631
- }
632
-
633
- static BOOL dec_pat_Decompress16Bit(short int *dest, int cbcount, int samplenum)
634
- {
635
- int i;
636
- PAT_SAMPLE_FUN f;
637
- if( samplenum < MAXSMP ) pat_readpat(samplenum, (char *)dest, cbcount*2);
638
- else {
639
- f = pat_fun[(samplenum - MAXSMP) % 3];
640
- for( i=0; i<cbcount; i++ )
641
- dest[i] = (short int)(32000.0*f(i));
642
- }
643
- return cbcount;
644
- }
645
-
646
- // convert 8 bit data to 16 bit!
647
- // We do the conversion in reverse so that the data we're converting isn't overwritten
648
- // by the result.
649
- static void pat_blowup_to16bit(short int *dest, int cbcount) {
650
- char *s;
651
- short int *d;
652
- int t;
653
- s = (char *)dest;
654
- d = dest;
655
- s += cbcount;
656
- d += cbcount;
657
- for(t=0; t<cbcount; t++)
658
- { s--;
659
- d--;
660
- *d = (*s) << 8;
661
- }
662
- }
663
-
664
- static BOOL dec_pat_Decompress8Bit(short int *dest, int cbcount, int samplenum)
665
- {
666
- int i;
667
- PAT_SAMPLE_FUN f;
668
- if( samplenum < MAXSMP ) pat_readpat(samplenum, (char *)dest, cbcount);
669
- else {
670
- f = pat_fun[(samplenum - MAXSMP) % 3];
671
- for( i=0; i<cbcount; i++ )
672
- dest[i] = (char)(120.0*f(i));
673
- }
674
- pat_blowup_to16bit(dest, cbcount);
675
- return cbcount;
676
- }
677
-
678
- BOOL CSoundFile_TestPAT(const BYTE *lpStream, DWORD dwMemLength)
679
- // =====================================================================================
680
- {
681
- PatchHeader ph;
682
- if( dwMemLength < sizeof(PatchHeader) ) return 0;
683
- SDL_memcpy((BYTE *)&ph, lpStream, sizeof(PatchHeader));
684
- if( !SDL_strcmp(ph.header,"GF1PATCH110") && !SDL_strcmp(ph.gravis_id,"ID#000002") ) return 1;
685
- return 0;
686
- }
687
-
688
- // =====================================================================================
689
- static PATHANDLE *PAT_Init(void)
690
- {
691
- PATHANDLE *retval;
692
- retval = (PATHANDLE *)SDL_calloc(1,sizeof(PATHANDLE));
693
- if( !retval ) return NULL;
694
- return retval;
695
- }
696
-
697
- // =====================================================================================
698
- static void PAT_Cleanup(PATHANDLE *handle)
699
- // =====================================================================================
700
- {
701
- if(handle) {
702
- SDL_free(handle);
703
- }
704
- }
705
-
706
- static char tune[] = "c d e c|c d e c|e f g..|e f g..|gagfe c|gagfe c|c G c..|c G c..|";
707
- static int pat_note(int abc)
708
- {
709
- switch( abc ) {
710
- case 'C': return 48;
711
- case 'D': return 50;
712
- case 'E': return 52;
713
- case 'F': return 53;
714
- case 'G': return 55;
715
- case 'A': return 57;
716
- case 'B': return 59;
717
- case 'c': return 60;
718
- case 'd': return 62;
719
- case 'e': return 64;
720
- case 'f': return 65;
721
- case 'g': return 67;
722
- case 'a': return 69;
723
- case 'b': return 71;
724
- default:
725
- break;
726
- }
727
- return 0;
728
- }
729
-
730
- int pat_modnote(int midinote)
731
- {
732
- int n;
733
- n = midinote;
734
- n += 13;
735
- return n;
736
- }
737
-
738
- static void PAT_ReadPatterns(MODCOMMAND *pattern[], WORD psize[], PATHANDLE *h, int numpat)
739
- // =====================================================================================
740
- {
741
- int pat,row,i,ch;
742
- BYTE n,ins,vol;
743
- int t;
744
- int tt1, tt2;
745
- MODCOMMAND *m;
746
- if( numpat > MAX_PATTERNS ) numpat = MAX_PATTERNS;
747
-
748
- tt2 = (h->samples - 1) * 16 + 128;
749
- for( pat = 0; pat < numpat; pat++ ) {
750
- pattern[pat] = CSoundFile_AllocatePattern(64, h->samples);
751
- if( !pattern[pat] ) return;
752
- psize[pat] = 64;
753
- for( row = 0; row < 64; row++ ) {
754
- tt1 = (pat * 64 + row);
755
- for( ch = 0; ch < h->samples; ch++ ) {
756
- t = tt1 - ch * 16;
757
- m = &pattern[pat][row * h->samples + ch];
758
- m->param = 0;
759
- m->command = CMD_NONE;
760
- if( t >= 0 ) {
761
- i = tt2 - 16 * ((h->samples - 1 - ch) & 3);
762
- if( tt1 < i ) {
763
- t = t % 64;
764
- if( IsAlpha(tune[t]) ) {
765
- n = pat_modnote(pat_note(tune[t]));
766
- ins = ch + 1;
767
- vol = 40;
768
- if( (t % 16) == 0 ) {
769
- vol += vol / 10;
770
- if( vol > 64 ) vol = 64;
771
- }
772
- m->instr = ins;
773
- m->note = n; // <- normal note
774
- m->volcmd = VOLCMD_VOLUME;
775
- m->vol = vol;
776
- }
777
- if( tt1 == i - 1 && ch == 0 && row < 63 ) {
778
- m->command = CMD_PATTERNBREAK;
779
- }
780
- }
781
- else {
782
- if( tt1 == i ) {
783
- m->param = 0;
784
- m->command = CMD_KEYOFF;
785
- m->volcmd = VOLCMD_VOLUME;
786
- m->vol = 0;
787
- }
788
- }
789
- }
790
- }
791
- }
792
- }
793
- }
794
-
795
- // calculate the best speed that approximates the pat root frequency as a C note
796
- static ULONG pat_patrate_to_C4SPD(ULONG patRate , ULONG patMilliHz)
797
- {
798
- ULONG u;
799
- double x, y;
800
- u = patMilliHz;
801
- x = 0.1 * patRate;
802
- x = x * C4mHz;
803
- y = u * 0.4;
804
- x = x / y;
805
- u = (ULONG)(x+0.5);
806
- return u;
807
- }
808
-
809
- // return relative position in samples for the rate starting with offset start ending with offset end
810
- static int pat_envelope_rpos(int rate, int start, int end)
811
- {
812
- int r, p, t, s;
813
- // rate byte is 3 bits exponent and 6 bits increment size
814
- // eeiiiiii
815
- // every 8 to the power ee the volume is incremented/decremented by iiiiii
816
- // Thank you Gravis for this weirdness...
817
- r = 3 - ((rate >> 6) & 3) * 3;
818
- p = rate & 0x3f;
819
- if( !p ) return 0;
820
- t = end - start;
821
- if( !t ) return 0;
822
- if (t < 0) t = -t;
823
- s = (t << r)/ p;
824
- return s;
825
- }
826
-
827
- static void pat_modenv(WaveHeader *hw, int mpos[6], int mvol[6])
828
- {
829
- int i, sum, s;
830
- BYTE *prate = hw->envelope_rate, *poffset = hw->envelope_offset;
831
- for( i=0; i<6; i++ ) {
832
- mpos[i] = 0;
833
- mvol[i] = 64;
834
- }
835
- if( !SDL_memcmp(prate, "??????", 6) || poffset[5] >= 100 ) return; // weird rates or high env end volume
836
- if( !(hw->modes & PAT_SUSTAIN) ) return; // no sustain thus no need for envelope
837
- s = hw->wave_size;
838
- if (s == 0) return;
839
- if( hw->modes & PAT_16BIT )
840
- s >>= 1;
841
- // offsets 0 1 2 3 4 5 are distributed over 0 2 4 6 8 10, the odd numbers are set in between
842
- sum = 0;
843
- for( i=0; i<6; i++ ) {
844
- mvol[i] = poffset[i];
845
- mpos[i] = pat_envelope_rpos(prate[i], i? poffset[i-1]: 0, poffset[i]);
846
- sum += mpos[i];
847
- }
848
- if( sum == 0 ) return;
849
- if( sum > s ) {
850
- for( i=0; i<6; i++ )
851
- mpos[i] = (s * mpos[i]) / sum;
852
- }
853
- for( i=1; i<6; i++ )
854
- mpos[i] += mpos[i-1];
855
- for( i=0; i<6 ; i++ ) {
856
- mpos[i] = (256 * mpos[i]) / s;
857
- mpos[i]++;
858
- if( i > 0 && mpos[i] <= mpos[i-1] ) {
859
- if( mvol[i] == mvol[i-1] ) mpos[i] = mpos[i-1];
860
- else mpos[i] = mpos[i-1] + 1;
861
- }
862
- if( mpos[i] > 256 ) mpos[i] = 256;
863
- }
864
- mvol[5] = 0; // kill Bill....
865
- }
866
-
867
- static void pat_setpat_inst(WaveHeader *hw, INSTRUMENTHEADER *d, int smp)
868
- {
869
- int u, inuse;
870
- int envpoint[6], envvolume[6];
871
- d->nMidiProgram = 0;
872
- d->nFadeOut = 0;
873
- d->nPan = 128;
874
- d->nPPC = 5*12;
875
- d->dwFlags = 0;
876
- if( hw->modes & PAT_ENVELOPE ) d->dwFlags |= ENV_VOLUME;
877
- if( hw->modes & PAT_SUSTAIN ) d->dwFlags |= ENV_VOLSUSTAIN;
878
- if( (hw->modes & PAT_LOOP) && (hw->start_loop != hw->end_loop) ) d->dwFlags |= ENV_VOLLOOP;
879
- d->nVolEnv = 6;
880
- //if (!d->nVolEnv) d->dwFlags &= ~ENV_VOLUME;
881
- d->nPanEnv = 0;
882
- d->nVolSustainBegin = 1;
883
- d->nVolSustainEnd = 1;
884
- d->nVolLoopStart = 1;
885
- d->nVolLoopEnd = 2;
886
- d->nPanSustainBegin = 0;
887
- d->nPanSustainEnd = 0;
888
- d->nPanLoopStart = 0;
889
- d->nPanLoopEnd = 0;
890
- d->nGlobalVol = 64;
891
- pat_modenv(hw, envpoint, envvolume);
892
- inuse = 0;
893
- for( u=0; u<6; u++)
894
- {
895
- if( envvolume[u] != 64 ) inuse = 1;
896
- d->VolPoints[u] = envpoint[u];
897
- d->VolEnv[u] = envvolume[u];
898
- d->PanPoints[u] = 0;
899
- d->PanEnv[u] = 0;
900
- if (u)
901
- {
902
- if (d->VolPoints[u] < d->VolPoints[u-1])
903
- {
904
- d->VolPoints[u] &= 0xFF;
905
- d->VolPoints[u] += d->VolPoints[u-1] & 0xFF00;
906
- if (d->VolPoints[u] < d->VolPoints[u-1]) d->VolPoints[u] += 0x100;
907
- }
908
- }
909
- }
910
- if( !inuse ) d->nVolEnv = 0;
911
- for( u=0; u<128; u++)
912
- {
913
- d->NoteMap[u] = u+1;
914
- d->Keyboard[u] = smp;
915
- }
916
- }
917
-
918
- static void PATinst(INSTRUMENTHEADER *d, int smp, int gm)
919
- {
920
- WaveHeader hw;
921
- char s[32];
922
- if( pat_readpat_attr(gm-1, &hw, 0) ) {
923
- pat_setpat_inst(&hw, d, smp);
924
- }
925
- else {
926
- hw.modes = PAT_16BIT|PAT_ENVELOPE|PAT_SUSTAIN|PAT_LOOP;
927
- hw.start_loop = 0;
928
- hw.end_loop = 30000;
929
- hw.wave_size = 30000;
930
- // envelope rates and offsets pinched from timidity's acpiano.pat sample no 1
931
- hw.envelope_rate[0] = 0x3f;
932
- hw.envelope_rate[1] = 0x3f;
933
- hw.envelope_rate[2] = 0x3f;
934
- hw.envelope_rate[3] = 0x08|(3<<6);
935
- hw.envelope_rate[4] = 0x3f;
936
- hw.envelope_rate[5] = 0x3f;
937
- hw.envelope_offset[0] = 246;
938
- hw.envelope_offset[1] = 246;
939
- hw.envelope_offset[2] = 246;
940
- hw.envelope_offset[3] = 0;
941
- hw.envelope_offset[4] = 0;
942
- hw.envelope_offset[5] = 0;
943
- SDL_strlcpy(hw.reserved, midipat[gm-1], sizeof(hw.reserved));
944
- pat_setpat_inst(&hw, d, smp);
945
- }
946
- SDL_strlcpy(s, midipat[gm-1], 12);
947
- SDL_memset(d->filename, 0, 12);
948
- SDL_strlcpy((char *)d->filename, s, sizeof (d->filename));
949
- }
950
-
951
- static void pat_setpat_attr(WaveHeader *hw, MODINSTRUMENT *q)
952
- {
953
- q->nC4Speed = pat_patrate_to_C4SPD(hw->sample_rate , hw->root_frequency);
954
- q->nLength = hw->wave_size;
955
- q->nLoopStart = hw->start_loop;
956
- q->nLoopEnd = hw->end_loop;
957
- q->nVolume = 256;
958
- if( hw->modes & PAT_16BIT ) {
959
- q->nLength >>= 1;
960
- q->nLoopStart >>= 1;
961
- q->nLoopEnd >>= 1;
962
- }
963
- if( hw->modes & PAT_LOOP ) {
964
- q->uFlags |= CHN_LOOP;
965
- if( hw->modes & PAT_PINGPONG ) q->uFlags |= CHN_PINGPONGSUSTAIN;
966
- if( hw->modes & PAT_SUSTAIN ) q->uFlags |= CHN_SUSTAINLOOP;
967
- }
968
- }
969
-
970
- // ==========================
971
- // Load those darned Samples!
972
- static void PATsample(CSoundFile *cs, MODINSTRUMENT *q, int smp, int gm)
973
- {
974
- WaveHeader hw;
975
- q->nGlobalVol = 64;
976
- q->nPan = 128;
977
- q->uFlags = CHN_16BIT;
978
- if( pat_readpat_attr(gm-1, &hw, 0) ) {
979
- char *p;
980
- pat_setpat_attr(&hw, q);
981
- pat_loops[smp-1] = (q->uFlags & CHN_LOOP)? 1: 0;
982
- if( hw.modes & PAT_16BIT ) p = (char *)SDL_malloc(hw.wave_size);
983
- else p = (char *)SDL_malloc(hw.wave_size * sizeof(char)*2);
984
- if( p ) {
985
- if( hw.modes & PAT_16BIT ) {
986
- dec_pat_Decompress16Bit((short int *)p, hw.wave_size>>1, gm - 1);
987
- CSoundFile_ReadSample(cs, q, (hw.modes&PAT_UNSIGNED)?RS_PCM16U:RS_PCM16S, (LPSTR)p, hw.wave_size);
988
- }
989
- else {
990
- dec_pat_Decompress8Bit((short int *)p, hw.wave_size, gm - 1);
991
- CSoundFile_ReadSample(cs, q, (hw.modes&PAT_UNSIGNED)?RS_PCM16U:RS_PCM16S, (LPSTR)p, hw.wave_size * sizeof(short int));
992
- }
993
- SDL_free(p);
994
- }
995
- }
996
- else {
997
- char *p;
998
- q->nC4Speed = C4SPD;
999
- q->nLength = 30000;
1000
- q->nLoopStart = 0;
1001
- q->nLoopEnd = 30000;
1002
- q->nVolume = 256;
1003
- q->uFlags |= CHN_LOOP;
1004
- q->uFlags |= CHN_16BIT;
1005
- p = (char *)SDL_malloc(q->nLength*sizeof(char)*2);
1006
- if( p ) {
1007
- dec_pat_Decompress8Bit((short int *)p, q->nLength, smp + MAXSMP - 1);
1008
- CSoundFile_ReadSample(cs, q, RS_PCM16S, (LPSTR)p, q->nLength*2);
1009
- SDL_free(p);
1010
- }
1011
- }
1012
- }
1013
-
1014
- // =====================================================================================
1015
- BOOL PAT_Load_Instruments(void *c)
1016
- {
1017
- uint32_t t;
1018
- CSoundFile *of=(CSoundFile *)c;
1019
- if( !pat_numsmp() ) pat_gmtosmp(1); // make sure there is a sample
1020
- of->m_nSamples = pat_numsmp() + 1; // xmms modplug does not use slot zero
1021
- of->m_nInstruments = pat_numinstr() + 1;
1022
- for(t=1; t<of->m_nInstruments; t++) { // xmms modplug doesn't use slot zero
1023
- if( (of->Headers[t] = (INSTRUMENTHEADER *) SDL_malloc(sizeof (INSTRUMENTHEADER))) == NULL ) return FALSE;
1024
- SDL_memset(of->Headers[t], 0, sizeof(INSTRUMENTHEADER));
1025
- PATinst(of->Headers[t], t, pat_smptogm(t));
1026
- }
1027
- for(t=1; t<of->m_nSamples; t++) { // xmms modplug doesn't use slot zero
1028
- PATsample(of, &of->Ins[t], t, pat_smptogm(t));
1029
- }
1030
- // copy last of the mohicans to entry 0 for XMMS modinfo to work....
1031
- t = of->m_nInstruments - 1;
1032
- if( (of->Headers[0] = (INSTRUMENTHEADER *) SDL_malloc(sizeof (INSTRUMENTHEADER))) == NULL ) return FALSE;
1033
- SDL_memcpy(of->Headers[0], of->Headers[t], sizeof(INSTRUMENTHEADER));
1034
- t = of->m_nSamples - 1;
1035
- SDL_memcpy(&of->Ins[0], &of->Ins[t], sizeof(MODINSTRUMENT));
1036
- return TRUE;
1037
- }
1038
- // =====================================================================================
1039
- BOOL CSoundFile_ReadPAT(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLength)
1040
- {
1041
- static int avoid_reentry = 0;
1042
- char buf[60];
1043
- int t;
1044
- PATHANDLE *h;
1045
- int numpat;
1046
- MMFILE mm, *mmfile;
1047
- MODINSTRUMENT *q;
1048
- INSTRUMENTHEADER *d;
1049
- if( !CSoundFile_TestPAT(lpStream, dwMemLength) ) return FALSE;
1050
- h = PAT_Init();
1051
- if( !h ) return FALSE;
1052
- mmfile = &mm;
1053
- mm.mm = (char *)lpStream;
1054
- mm.sz = dwMemLength;
1055
- mm.pos = 0;
1056
- mm.error = 0;
1057
- while( avoid_reentry ) SDL_Delay(1);
1058
- avoid_reentry = 1;
1059
- pat_read_patname(h, mmfile);
1060
- h->samples = pat_read_numsmp(mmfile);
1061
- if( SDL_strlen(h->patname) )
1062
- SDL_snprintf(buf,sizeof (buf),"%s canon %d-v (Fr. Jacques)", h->patname, h->samples);
1063
- else
1064
- SDL_snprintf(buf,sizeof (buf),"%d-voice canon (Fr. Jacques)", h->samples);
1065
- if( SDL_strlen(buf) > 31 ) buf[31] = '\0'; // chop it of
1066
- _this->m_nDefaultTempo = 60; // 120 / 2
1067
- t = (h->samples - 1) * 16 + 128;
1068
- if( t % 64 ) t += 64;
1069
- t = t / 64;
1070
- _this->m_nType = MOD_TYPE_PAT;
1071
- _this->m_nInstruments = h->samples >= MAX_INSTRUMENTS-1 ? MAX_INSTRUMENTS-1 : h->samples + 1; // we know better but use each sample in the pat...
1072
- _this->m_nSamples = h->samples >= MAX_SAMPLES-1 ? MAX_SAMPLES-1 : h->samples + 1; // xmms modplug does not use slot zero
1073
- _this->m_nDefaultSpeed = 6;
1074
- _this->m_nChannels = h->samples;
1075
- numpat = t;
1076
-
1077
- _this->m_dwSongFlags = SONG_LINEARSLIDES;
1078
- _this->m_nMinPeriod = 28 << 2;
1079
- _this->m_nMaxPeriod = 1712 << 3;
1080
- // orderlist
1081
- for(t=0; t < numpat; t++)
1082
- _this->Order[t] = t;
1083
- for(t=1; t<(int)_this->m_nInstruments; t++) { // xmms modplug doesn't use slot zero
1084
- WaveHeader hw;
1085
- char s[32];
1086
- if( (d = (INSTRUMENTHEADER *) SDL_malloc(sizeof (INSTRUMENTHEADER))) == NULL ) {
1087
- avoid_reentry = 0;
1088
- return FALSE;
1089
- }
1090
- SDL_memset(d, 0, sizeof(INSTRUMENTHEADER));
1091
- _this->Headers[t] = d;
1092
- SDL_memset(d->filename, 0, 12);
1093
- SDL_strlcpy((char *)d->filename, s, 12);
1094
- pat_get_waveheader(mmfile, &hw, t);
1095
- pat_setpat_inst(&hw, d, t);
1096
- }
1097
- for(t=1; t<(int)_this->m_nSamples; t++) { // xmms modplug doesn't use slot zero
1098
- WaveHeader hw;
1099
- char *p;
1100
- q = &_this->Ins[t]; // we do not use slot zero
1101
- q->nGlobalVol = 64;
1102
- q->nPan = 128;
1103
- q->uFlags = CHN_16BIT;
1104
- pat_get_waveheader(mmfile, &hw, t);
1105
- pat_setpat_attr(&hw, q);
1106
- if ( hw.wave_size == 0 ) p = NULL;
1107
- else if( hw.modes & PAT_16BIT ) p = (char *)SDL_malloc(hw.wave_size);
1108
- else p = (char *)SDL_malloc(hw.wave_size * sizeof(char) * 2);
1109
- if( p ) {
1110
- mmreadSBYTES(p, hw.wave_size, mmfile);
1111
- if( hw.modes & PAT_16BIT ) {
1112
- CSoundFile_ReadSample(_this, q, (hw.modes&PAT_UNSIGNED)?RS_PCM16U:RS_PCM16S, (LPSTR)p, hw.wave_size);
1113
- }
1114
- else {
1115
- pat_blowup_to16bit((short int *)p, hw.wave_size);
1116
- CSoundFile_ReadSample(_this, q, (hw.modes&PAT_UNSIGNED)?RS_PCM16U:RS_PCM16S, (LPSTR)p, hw.wave_size * sizeof(short int));
1117
- }
1118
- SDL_free(p);
1119
- }
1120
- }
1121
- // copy last of the mohicans to entry 0 for XMMS modinfo to work....
1122
- t = _this->m_nInstruments - 1;
1123
- if( (_this->Headers[0] = (INSTRUMENTHEADER *) SDL_malloc(sizeof (INSTRUMENTHEADER))) == NULL ) {
1124
- avoid_reentry = 0;
1125
- return FALSE;
1126
- }
1127
- SDL_memcpy(_this->Headers[0], _this->Headers[t], sizeof(INSTRUMENTHEADER));
1128
- t = _this->m_nSamples - 1;
1129
- SDL_memcpy(&_this->Ins[0], &_this->Ins[t], sizeof(MODINSTRUMENT));
1130
- // ==============================
1131
- // Load the pattern info now!
1132
- PAT_ReadPatterns(_this->Patterns, _this->PatternSize, h, numpat);
1133
- // ============================================================
1134
- // set panning positions
1135
- for(t=0; t<(int)_this->m_nChannels; t++) {
1136
- _this->ChnSettings[t].nPan = 0x30+((t+2)%5)*((0xD0 - 0x30)/5); // 0x30 = std s3m val
1137
- _this->ChnSettings[t].nVolume = 64;
1138
- }
1139
- avoid_reentry = 0; // it is safe now, I'm finished
1140
- PAT_Cleanup(h); // we dont need it anymore
1141
- return 1;
1142
- }
1143
-