1 /* _______ ____ __ ___ ___
2 * \ _ \ \ / \ / \ \ / / ' ' '
3 * | | \ \ | | || | \/ | . .
4 * | | | | | | || ||\ /| |
5 * | | | | | | || || \/ | | ' ' '
6 * | | | | | | || || | | . .
7 * | |_/ / \ \__// || | |
8 * /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque
9 * / \
10 * / . \
11 * dumb.h - The user header file for DUMB. / / \ \
12 * | < / \_
13 * Include this file in any of your files in | \/ /\ /
14 * which you wish to use the DUMB functions \_ / > /
15 * and variables. | \ / /
16 * | ' /
17 * Allegro users, you will probably want aldumb.h. \__/
18 */
19
20 #ifndef DUMB_H
21 #define DUMB_H
22
23
24 #include <stdlib.h>
25 #include <stdio.h>
26
27 #if defined(_DEBUG) && defined(_MSC_VER)
28 #ifndef _CRTDBG_MAP_ALLOC
29 //#define _CRTDBG_MAP_ALLOC
30 #endif
31 #include <crtdbg.h>
32 #endif
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38
39 #define DUMB_MAJOR_VERSION 1
40 #define DUMB_MINOR_VERSION 0
41 #define DUMB_REVISION_VERSION 0
42
43 #define DUMB_VERSION (DUMB_MAJOR_VERSION*10000 + DUMB_MINOR_VERSION*100 + DUMB_REVISION_VERSION)
44
45 #define DUMB_VERSION_STR "1.0.0"
46
47 #define DUMB_NAME "DUMB v" DUMB_VERSION_STR
48
49 #define DUMB_YEAR 2015
50 #define DUMB_MONTH 1
51 #define DUMB_DAY 17
52
53 #define DUMB_YEAR_STR2 "15"
54 #define DUMB_YEAR_STR4 "2015"
55 #define DUMB_MONTH_STR1 "1"
56 #define DUMB_DAY_STR1 "17"
57
58 #if DUMB_MONTH < 10
59 #define DUMB_MONTH_STR2 "0" DUMB_MONTH_STR1
60 #else
61 #define DUMB_MONTH_STR2 DUMB_MONTH_STR1
62 #endif
63
field_check_field_name_match(Field * field,const char * name)64 #if DUMB_DAY < 10
65 #define DUMB_DAY_STR2 "0" DUMB_DAY_STR1
66 #else
67 #define DUMB_DAY_STR2 DUMB_DAY_STR1
68 #endif
69
70
71 /* WARNING: The month and day were inadvertently swapped in the v0.8 release.
72 * Please do not compare this constant against any date in 2002. In
73 * any case, DUMB_VERSION is probably more useful for this purpose.
74 */
75 #define DUMB_DATE (DUMB_YEAR*10000 + DUMB_MONTH*100 + DUMB_DAY)
76
77 #define DUMB_DATE_STR DUMB_DAY_STR1 "." DUMB_MONTH_STR1 "." DUMB_YEAR_STR4
78
79
80 #undef MIN
81 #undef MAX
82 #undef MID
83
84 #define MIN(x,y) (((x) < (y)) ? (x) : (y))
85 #define MAX(x,y) (((x) > (y)) ? (x) : (y))
86 #define MID(x,y,z) MAX((x), MIN((y), (z)))
87
88 #undef ABS
89 #define ABS(x) (((x) >= 0) ? (x) : (-(x)))
90
91
92 #ifdef DEBUGMODE
93
94 #ifndef ASSERT
95 #include <assert.h>
96 #define ASSERT(n) assert(n)
97 #endif
98 #ifndef TRACE
99 // it would be nice if this did actually trace ...
100 #define TRACE 1 ? (void)0 : (void)printf
101 #endif
102
103 #else
104
105 #ifndef ASSERT
106 #define ASSERT(n)
107 #endif
108 #ifndef TRACE
109 #define TRACE 1 ? (void)0 : (void)printf
110 #endif
111
112 #endif
113
114
115 #define DUMB_ID(a,b,c,d) (((unsigned int)(a) << 24) | \
116 ((unsigned int)(b) << 16) | \
117 ((unsigned int)(c) << 8) | \
118 ((unsigned int)(d) ))
119
120
121 #ifdef __DOS__
122 typedef long int32;
123 typedef unsigned long uint32;
124 typedef signed long sint32;
125 #else
126 typedef int int32;
127 typedef unsigned int uint32;
128 typedef signed int sint32;
129 #endif
130
131 #define CDECL
132 #ifndef LONG_LONG
133 #if defined __GNUC__ || defined __INTEL_COMPILER || defined __MWERKS__
134 #define LONG_LONG long long
135 #elif defined _MSC_VER || defined __WATCOMC__
136 #define LONG_LONG __int64
137 #undef CDECL
138 #define CDECL __cdecl
139 #elif defined __sgi
140 #define LONG_LONG long long
141 #else
142 #error 64-bit integer type unknown
143 #endif
144 #endif
145
146 #if __GNUC__ * 100 + __GNUC_MINOR__ >= 301 /* GCC 3.1+ */
147 #ifndef DUMB_DECLARE_DEPRECATED
148 #define DUMB_DECLARE_DEPRECATED
149 #endif
150 #define DUMB_DEPRECATED __attribute__((__deprecated__))
151 #else
152 #define DUMB_DEPRECATED
153 #endif
154
155 #define DUMBEXPORT CDECL
156 #define DUMBCALLBACK CDECL
157
158 /* Basic Sample Type. Normal range is -0x800000 to 0x7FFFFF. */
159
160 typedef int sample_t;
161
162
163 /* Library Clean-up Management */
164
165 int dumb_atexit(void (*proc)(void));
166
skip(const Rdb_field_packing * fpi,const Field * field,Rdb_string_reader * reader,Rdb_string_reader * unp_reader)167 void dumb_exit(void);
168
169
170 /* File Input Functions */
171
172 typedef struct DUMBFILE_SYSTEM
173 {
174 void *(DUMBCALLBACK *open)(const char *filename);
175 int (DUMBCALLBACK *skip)(void *f, long n);
176 int (DUMBCALLBACK *getc)(void *f);
177 int32 (DUMBCALLBACK *getnc)(char *ptr, int32 n, void *f);
178 void (DUMBCALLBACK *close)(void *f);
179 int (DUMBCALLBACK *seek)(void *f, long n);
180 long (DUMBCALLBACK *get_size)(void *f);
181 }
182 DUMBFILE_SYSTEM;
183
184 typedef struct DUMBFILE DUMBFILE;
185
186 void DUMBEXPORT register_dumbfile_system(const DUMBFILE_SYSTEM *dfs);
187
188 DUMBFILE *DUMBEXPORT dumbfile_open(const char *filename);
189 DUMBFILE *DUMBEXPORT dumbfile_open_ex(void *file, const DUMBFILE_SYSTEM *dfs);
190
191 int32 DUMBEXPORT dumbfile_pos(DUMBFILE *f);
192 int DUMBEXPORT dumbfile_skip(DUMBFILE *f, long n);
193
194 #define DFS_SEEK_SET 0
195 #define DFS_SEEK_CUR 1
196 #define DFS_SEEK_END 2
197
198 int DUMBEXPORT dumbfile_seek(DUMBFILE *f, long n, int origin);
199
200 int32 DUMBEXPORT dumbfile_get_size(DUMBFILE *f);
201
202 int DUMBEXPORT dumbfile_getc(DUMBFILE *f);
Rdb_key_field_iterator(const Rdb_key_def * key_def,Rdb_field_packing * pack_info,Rdb_string_reader * reader,Rdb_string_reader * unp_reader,TABLE * table,bool has_unpack_info,const MY_BITMAP * covered_bitmap,uchar * const buf)203
204 int DUMBEXPORT dumbfile_igetw(DUMBFILE *f);
205 int DUMBEXPORT dumbfile_mgetw(DUMBFILE *f);
206
207 int32 DUMBEXPORT dumbfile_igetl(DUMBFILE *f);
208 int32 DUMBEXPORT dumbfile_mgetl(DUMBFILE *f);
209
210 uint32 DUMBEXPORT dumbfile_cgetul(DUMBFILE *f);
211 sint32 DUMBEXPORT dumbfile_cgetsl(DUMBFILE *f);
212
213 int32 DUMBEXPORT dumbfile_getnc(char *ptr, int32 n, DUMBFILE *f);
214
215 int DUMBEXPORT dumbfile_error(DUMBFILE *f);
216 int DUMBEXPORT dumbfile_close(DUMBFILE *f);
217
218
219 /* stdio File Input Module */
220
221 void DUMBEXPORT dumb_register_stdfiles(void);
222
223 DUMBFILE *DUMBEXPORT dumbfile_open_stdfile(FILE *p);
224
225
get_dst() const226 /* Memory File Input Module */
227
228 DUMBFILE *DUMBEXPORT dumbfile_open_memory(const char *data, int32 size);
229
230
231 /* DUH Management */
232
get_is_null() const233 typedef struct DUH DUH;
get_field() const234
235 #define DUH_SIGNATURE DUMB_ID('D','U','H','!')
236
237 void DUMBEXPORT unload_duh(DUH *duh);
238
has_next()239 DUH *DUMBEXPORT load_duh(const char *filename);
240 DUH *DUMBEXPORT read_duh(DUMBFILE *f);
241
242 int32 DUMBEXPORT duh_get_length(DUH *duh);
243
next()244 const char *DUMBEXPORT duh_get_tag(DUH *duh, const char *key);
245
246 /* Signal Rendering Functions */
247
248 typedef struct DUH_SIGRENDERER DUH_SIGRENDERER;
249
250 DUH_SIGRENDERER *DUMBEXPORT duh_start_sigrenderer(DUH *duh, int sig, int n_channels, int32 pos);
251
252 #ifdef DUMB_DECLARE_DEPRECATED
253 typedef void (*DUH_SIGRENDERER_CALLBACK)(void *data, sample_t **samples, int n_channels, int32 length);
254 /* This is deprecated, but is not marked as such because GCC tends to
255 * complain spuriously when the typedef is used later. See comments below.
256 */
257
258 void duh_sigrenderer_set_callback(
259 DUH_SIGRENDERER *sigrenderer,
260 DUH_SIGRENDERER_CALLBACK callback, void *data
261 ) DUMB_DEPRECATED;
262 /* The 'callback' argument's type has changed for const-correctness. See the
263 * DUH_SIGRENDERER_CALLBACK definition just above. Also note that the samples
264 * in the buffer are now 256 times as large; the normal range is -0x800000 to
265 * 0x7FFFFF. The function has been renamed partly because its functionality
266 * has changed slightly and partly so that its name is more meaningful. The
267 * new one is duh_sigrenderer_set_analyser_callback(), and the typedef for
268 * the function pointer has also changed, from DUH_SIGRENDERER_CALLBACK to
269 * DUH_SIGRENDERER_ANALYSER_CALLBACK. (If you wanted to use this callback to
270 * apply a DSP effect, don't worry; there is a better way of doing this. It
271 * is undocumented, so contact me and I shall try to help. Contact details
272 * are in readme.txt.)
273 */
274
275 typedef void (*DUH_SIGRENDERER_ANALYSER_CALLBACK)(void *data, const sample_t *const *samples, int n_channels, int32 length);
276 /* This is deprecated, but is not marked as such because GCC tends to
277 * complain spuriously when the typedef is used later. See comments below.
278 */
279
280 void duh_sigrenderer_set_analyser_callback(
281 DUH_SIGRENDERER *sigrenderer,
282 DUH_SIGRENDERER_ANALYSER_CALLBACK callback, void *data
283 ) DUMB_DEPRECATED;
284 /* This is deprecated because the meaning of the 'samples' parameter in the
285 * callback needed to change. For stereo applications, the array used to be
286 * indexed with samples[channel][pos]. It is now indexed with
287 * samples[0][pos*2+channel]. Mono sample data are still indexed with
288 * samples[0][pos]. The array is still 2D because samples will probably only
289 * ever be interleaved in twos. In order to fix your code, adapt it to the
290 * new sample layout and then call
291 * duh_sigrenderer_set_sample_analyser_callback below instead of this
292 * function.
293 */
294 #endif
295
296 typedef void (*DUH_SIGRENDERER_SAMPLE_ANALYSER_CALLBACK)(void *data, const sample_t *const *samples, int n_channels, int32 length);
Rdb_key_def(uint indexnr_arg,uint keyno_arg,rocksdb::ColumnFamilyHandle * cf_handle_arg,uint16_t index_dict_version_arg,uchar index_type_arg,uint16_t kv_format_version_arg,bool is_reverse_cf_arg,bool is_per_partition_cf_arg,const char * _name,Rdb_index_stats _stats,uint32 index_flags_bitmap,uint32 ttl_rec_offset,uint64 ttl_duration)297
298 void duh_sigrenderer_set_sample_analyser_callback(
299 DUH_SIGRENDERER *sigrenderer,
300 DUH_SIGRENDERER_SAMPLE_ANALYSER_CALLBACK callback, void *data
301 );
302
303 int DUMBEXPORT duh_sigrenderer_get_n_channels(DUH_SIGRENDERER *sigrenderer);
304 int32 DUMBEXPORT duh_sigrenderer_get_position(DUH_SIGRENDERER *sigrenderer);
305
306 void DUMBEXPORT duh_sigrenderer_set_sigparam(DUH_SIGRENDERER *sigrenderer, unsigned char id, int32 value);
307
308 #ifdef DUMB_DECLARE_DEPRECATED
309 int32 duh_sigrenderer_get_samples(
310 DUH_SIGRENDERER *sigrenderer,
311 float volume, float delta,
312 int32 size, sample_t **samples
313 ) DUMB_DEPRECATED;
314 /* The sample format has changed, so if you were using this function,
315 * you should switch to duh_sigrenderer_generate_samples() and change
316 * how you interpret the samples array. See the comments for
317 * duh_sigrenderer_set_analyser_callback().
318 */
319 #endif
320
321 int32 DUMBEXPORT duh_sigrenderer_generate_samples(
322 DUH_SIGRENDERER *sigrenderer,
323 double volume, double delta,
324 int32 size, sample_t **samples
325 );
326
327 void DUMBEXPORT duh_sigrenderer_get_current_sample(DUH_SIGRENDERER *sigrenderer, float volume, sample_t *samples);
328
329 void DUMBEXPORT duh_end_sigrenderer(DUH_SIGRENDERER *sigrenderer);
330
331
332 /* DUH Rendering Functions */
333
334 int32 DUMBEXPORT duh_render(
335 DUH_SIGRENDERER *sigrenderer,
336 int bits, int unsign,
337 float volume, float delta,
338 int32 size, void *sptr
Rdb_key_def(const Rdb_key_def & k)339 );
340
341 #ifdef DUMB_DECLARE_DEPRECATED
342
343 int32 duh_render_signal(
344 DUH_SIGRENDERER *sigrenderer,
345 float volume, float delta,
346 int32 size, sample_t **samples
347 ) DUMB_DEPRECATED;
348 /* Please use duh_sigrenderer_generate_samples(), and see the
349 * comments for the deprecated duh_sigrenderer_get_samples() too.
350 */
351
352 typedef DUH_SIGRENDERER DUH_RENDERER DUMB_DEPRECATED;
353 /* Please use DUH_SIGRENDERER instead of DUH_RENDERER. */
354
355 DUH_SIGRENDERER *duh_start_renderer(DUH *duh, int n_channels, int32 pos) DUMB_DEPRECATED;
356 /* Please use duh_start_sigrenderer() instead. Pass 0 for 'sig'. */
357
358 int duh_renderer_get_n_channels(DUH_SIGRENDERER *dr) DUMB_DEPRECATED;
359 int32 duh_renderer_get_position(DUH_SIGRENDERER *dr) DUMB_DEPRECATED;
360 /* Please use the duh_sigrenderer_*() equivalents of these two functions. */
361
362 void duh_end_renderer(DUH_SIGRENDERER *dr) DUMB_DEPRECATED;
363 /* Please use duh_end_sigrenderer() instead. */
364
365 DUH_SIGRENDERER *duh_renderer_encapsulate_sigrenderer(DUH_SIGRENDERER *sigrenderer) DUMB_DEPRECATED;
366 DUH_SIGRENDERER *duh_renderer_get_sigrenderer(DUH_SIGRENDERER *dr) DUMB_DEPRECATED;
367 DUH_SIGRENDERER *duh_renderer_decompose_to_sigrenderer(DUH_SIGRENDERER *dr) DUMB_DEPRECATED;
368 /* These functions have become no-ops that just return the parameter.
369 * So, for instance, replace
370 * duh_renderer_encapsulate_sigrenderer(my_sigrenderer)
371 * with
372 * my_sigrenderer
373 */
374
375 #endif
376
377
378 /* Impulse Tracker Support */
379
380 extern int dumb_it_max_to_mix;
381
~Rdb_key_def()382 typedef struct DUMB_IT_SIGDATA DUMB_IT_SIGDATA;
383 typedef struct DUMB_IT_SIGRENDERER DUMB_IT_SIGRENDERER;
384
385 DUMB_IT_SIGDATA *DUMBEXPORT duh_get_it_sigdata(DUH *duh);
386 DUH_SIGRENDERER *DUMBEXPORT duh_encapsulate_it_sigrenderer(DUMB_IT_SIGRENDERER *it_sigrenderer, int n_channels, int32 pos);
387 DUMB_IT_SIGRENDERER *DUMBEXPORT duh_get_it_sigrenderer(DUH_SIGRENDERER *sigrenderer);
388
389 int DUMBEXPORT dumb_it_trim_silent_patterns(DUH * duh);
390
391 typedef int (*dumb_scan_callback)(void *, int, int32);
setup(const TABLE * const tbl,const Rdb_tbl_def * const tbl_def)392 int DUMBEXPORT dumb_it_scan_for_playable_orders(DUMB_IT_SIGDATA *sigdata, dumb_scan_callback callback, void * callback_data);
393
394 DUH_SIGRENDERER *DUMBEXPORT dumb_it_start_at_order(DUH *duh, int n_channels, int startorder);
395
396 enum
397 {
398 DUMB_IT_RAMP_NONE = 0,
399 DUMB_IT_RAMP_ONOFF_ONLY = 1,
400 DUMB_IT_RAMP_FULL = 2
401 };
402
403 void DUMBEXPORT dumb_it_set_ramp_style(DUMB_IT_SIGRENDERER * sigrenderer, int ramp_style);
404
405 void DUMBEXPORT dumb_it_set_loop_callback(DUMB_IT_SIGRENDERER *sigrenderer, int (DUMBCALLBACK *callback)(void *data), void *data);
406 void DUMBEXPORT dumb_it_set_xm_speed_zero_callback(DUMB_IT_SIGRENDERER *sigrenderer, int (DUMBCALLBACK *callback)(void *data), void *data);
407 void DUMBEXPORT dumb_it_set_midi_callback(DUMB_IT_SIGRENDERER *sigrenderer, int (DUMBCALLBACK *callback)(void *data, int channel, unsigned char midi_byte), void *data);
408 void DUMBEXPORT dumb_it_set_global_volume_zero_callback(DUMB_IT_SIGRENDERER *sigrenderer, int (DUMBCALLBACK *callback)(void *data), void *data);
409
410 int DUMBCALLBACK dumb_it_callback_terminate(void *data);
411 int DUMBCALLBACK dumb_it_callback_midi_block(void *data, int channel, unsigned char midi_byte);
412
413 /* dumb_*_mod*: restrict_ |= 1-Don't read 15 sample files / 2-Use old pattern counting method */
414
415 DUH *DUMBEXPORT dumb_load_it(const char *filename);
416 DUH *DUMBEXPORT dumb_load_xm(const char *filename);
417 DUH *DUMBEXPORT dumb_load_s3m(const char *filename);
418 DUH *DUMBEXPORT dumb_load_stm(const char *filename);
419 DUH *DUMBEXPORT dumb_load_mod(const char *filename, int restrict_);
420 DUH *DUMBEXPORT dumb_load_ptm(const char *filename);
421 DUH *DUMBEXPORT dumb_load_669(const char *filename);
422 DUH *DUMBEXPORT dumb_load_psm(const char *filename, int subsong);
423 DUH *DUMBEXPORT dumb_load_old_psm(const char * filename);
424 DUH *DUMBEXPORT dumb_load_mtm(const char *filename);
425 DUH *DUMBEXPORT dumb_load_riff(const char *filename);
426 DUH *DUMBEXPORT dumb_load_asy(const char *filename);
427 DUH *DUMBEXPORT dumb_load_amf(const char *filename);
428 DUH *DUMBEXPORT dumb_load_okt(const char *filename);
429
430 DUH *DUMBEXPORT dumb_read_it(DUMBFILE *f);
431 DUH *DUMBEXPORT dumb_read_xm(DUMBFILE *f);
432 DUH *DUMBEXPORT dumb_read_s3m(DUMBFILE *f);
433 DUH *DUMBEXPORT dumb_read_stm(DUMBFILE *f);
434 DUH *DUMBEXPORT dumb_read_mod(DUMBFILE *f, int restrict_);
435 DUH *DUMBEXPORT dumb_read_ptm(DUMBFILE *f);
436 DUH *DUMBEXPORT dumb_read_669(DUMBFILE *f);
437 DUH *DUMBEXPORT dumb_read_psm(DUMBFILE *f, int subsong);
438 DUH *DUMBEXPORT dumb_read_old_psm(DUMBFILE *f);
439 DUH *DUMBEXPORT dumb_read_mtm(DUMBFILE *f);
440 DUH *DUMBEXPORT dumb_read_riff(DUMBFILE *f);
441 DUH *DUMBEXPORT dumb_read_asy(DUMBFILE *f);
442 DUH *DUMBEXPORT dumb_read_amf(DUMBFILE *f);
443 DUH *DUMBEXPORT dumb_read_okt(DUMBFILE *f);
444
445 DUH *DUMBEXPORT dumb_load_it_quick(const char *filename);
446 DUH *DUMBEXPORT dumb_load_xm_quick(const char *filename);
447 DUH *DUMBEXPORT dumb_load_s3m_quick(const char *filename);
448 DUH *DUMBEXPORT dumb_load_stm_quick(const char *filename);
449 DUH *DUMBEXPORT dumb_load_mod_quick(const char *filename, int restrict_);
450 DUH *DUMBEXPORT dumb_load_ptm_quick(const char *filename);
451 DUH *DUMBEXPORT dumb_load_669_quick(const char *filename);
452 DUH *DUMBEXPORT dumb_load_psm_quick(const char *filename, int subsong);
453 DUH *DUMBEXPORT dumb_load_old_psm_quick(const char * filename);
454 DUH *DUMBEXPORT dumb_load_mtm_quick(const char *filename);
455 DUH *DUMBEXPORT dumb_load_riff_quick(const char *filename);
456 DUH *DUMBEXPORT dumb_load_asy_quick(const char *filename);
457 DUH *DUMBEXPORT dumb_load_amf_quick(const char *filename);
458 DUH *DUMBEXPORT dumb_load_okt_quick(const char *filename);
459
460 DUH *DUMBEXPORT dumb_read_it_quick(DUMBFILE *f);
461 DUH *DUMBEXPORT dumb_read_xm_quick(DUMBFILE *f);
462 DUH *DUMBEXPORT dumb_read_s3m_quick(DUMBFILE *f);
463 DUH *DUMBEXPORT dumb_read_stm_quick(DUMBFILE *f);
464 DUH *DUMBEXPORT dumb_read_mod_quick(DUMBFILE *f, int restrict_);
465 DUH *DUMBEXPORT dumb_read_ptm_quick(DUMBFILE *f);
466 DUH *DUMBEXPORT dumb_read_669_quick(DUMBFILE *f);
467 DUH *DUMBEXPORT dumb_read_psm_quick(DUMBFILE *f, int subsong);
468 DUH *DUMBEXPORT dumb_read_old_psm_quick(DUMBFILE *f);
469 DUH *DUMBEXPORT dumb_read_mtm_quick(DUMBFILE *f);
470 DUH *DUMBEXPORT dumb_read_riff_quick(DUMBFILE *f);
471 DUH *DUMBEXPORT dumb_read_asy_quick(DUMBFILE *f);
472 DUH *DUMBEXPORT dumb_read_amf_quick(DUMBFILE *f);
473 DUH *DUMBEXPORT dumb_read_okt_quick(DUMBFILE *f);
474
475 DUH *DUMBEXPORT dumb_read_any_quick(DUMBFILE *f, int restrict_, int subsong);
476 DUH *DUMBEXPORT dumb_read_any(DUMBFILE *f, int restrict_, int subsong);
477
478 DUH *DUMBEXPORT dumb_load_any_quick(const char *filename, int restrict_, int subsong);
479 DUH *DUMBEXPORT dumb_load_any(const char *filename, int restrict_, int subsong);
480
481 int32 DUMBEXPORT dumb_it_build_checkpoints(DUMB_IT_SIGDATA *sigdata, int startorder);
482 void DUMBEXPORT dumb_it_do_initial_runthrough(DUH *duh);
483
484 int DUMBEXPORT dumb_get_psm_subsong_count(DUMBFILE *f);
485
486 const unsigned char *DUMBEXPORT dumb_it_sd_get_song_message(DUMB_IT_SIGDATA *sd);
487
488 int DUMBEXPORT dumb_it_sd_get_n_orders(DUMB_IT_SIGDATA *sd);
489 int DUMBEXPORT dumb_it_sd_get_n_samples(DUMB_IT_SIGDATA *sd);
490 int DUMBEXPORT dumb_it_sd_get_n_instruments(DUMB_IT_SIGDATA *sd);
491
492 const unsigned char *DUMBEXPORT dumb_it_sd_get_sample_name(DUMB_IT_SIGDATA *sd, int i);
493 const unsigned char *DUMBEXPORT dumb_it_sd_get_sample_filename(DUMB_IT_SIGDATA *sd, int i);
494 const unsigned char *DUMBEXPORT dumb_it_sd_get_instrument_name(DUMB_IT_SIGDATA *sd, int i);
495 const unsigned char *DUMBEXPORT dumb_it_sd_get_instrument_filename(DUMB_IT_SIGDATA *sd, int i);
496
497 int DUMBEXPORT dumb_it_sd_get_initial_global_volume(DUMB_IT_SIGDATA *sd);
498 void DUMBEXPORT dumb_it_sd_set_initial_global_volume(DUMB_IT_SIGDATA *sd, int gv);
499
500 int DUMBEXPORT dumb_it_sd_get_mixing_volume(DUMB_IT_SIGDATA *sd);
501 void DUMBEXPORT dumb_it_sd_set_mixing_volume(DUMB_IT_SIGDATA *sd, int mv);
502
503 int DUMBEXPORT dumb_it_sd_get_initial_speed(DUMB_IT_SIGDATA *sd);
504 void DUMBEXPORT dumb_it_sd_set_initial_speed(DUMB_IT_SIGDATA *sd, int speed);
505
506 int DUMBEXPORT dumb_it_sd_get_initial_tempo(DUMB_IT_SIGDATA *sd);
507 void DUMBEXPORT dumb_it_sd_set_initial_tempo(DUMB_IT_SIGDATA *sd, int tempo);
508
509 int DUMBEXPORT dumb_it_sd_get_initial_channel_volume(DUMB_IT_SIGDATA *sd, int channel);
510 void DUMBEXPORT dumb_it_sd_set_initial_channel_volume(DUMB_IT_SIGDATA *sd, int channel, int volume);
511
512 int DUMBEXPORT dumb_it_sr_get_current_order(DUMB_IT_SIGRENDERER *sr);
513 int DUMBEXPORT dumb_it_sr_get_current_row(DUMB_IT_SIGRENDERER *sr);
514
515 int DUMBEXPORT dumb_it_sr_get_global_volume(DUMB_IT_SIGRENDERER *sr);
516 void DUMBEXPORT dumb_it_sr_set_global_volume(DUMB_IT_SIGRENDERER *sr, int gv);
517
518 int DUMBEXPORT dumb_it_sr_get_tempo(DUMB_IT_SIGRENDERER *sr);
519 void DUMBEXPORT dumb_it_sr_set_tempo(DUMB_IT_SIGRENDERER *sr, int tempo);
520
521 int DUMBEXPORT dumb_it_sr_get_speed(DUMB_IT_SIGRENDERER *sr);
522 void DUMBEXPORT dumb_it_sr_set_speed(DUMB_IT_SIGRENDERER *sr, int speed);
523
524 #define DUMB_IT_N_CHANNELS 64
525 #define DUMB_IT_N_NNA_CHANNELS 192
526 #define DUMB_IT_TOTAL_CHANNELS (DUMB_IT_N_CHANNELS + DUMB_IT_N_NNA_CHANNELS)
527
528 /* Channels passed to any of these functions are 0-based */
529 int DUMBEXPORT dumb_it_sr_get_channel_volume(DUMB_IT_SIGRENDERER *sr, int channel);
530 void DUMBEXPORT dumb_it_sr_set_channel_volume(DUMB_IT_SIGRENDERER *sr, int channel, int volume);
531
532 int DUMBEXPORT dumb_it_sr_get_channel_muted(DUMB_IT_SIGRENDERER *sr, int channel);
533 void DUMBEXPORT dumb_it_sr_set_channel_muted(DUMB_IT_SIGRENDERER *sr, int channel, int muted);
534
535 typedef struct DUMB_IT_CHANNEL_STATE DUMB_IT_CHANNEL_STATE;
536
537 struct DUMB_IT_CHANNEL_STATE
538 {
539 int channel; /* 0-based; meaningful for NNA channels */
540 int sample; /* 1-based; 0 if nothing playing, then other fields undef */
541 int freq; /* in Hz */
542 float volume; /* 1.0 maximum; affected by ALL factors, inc. mixing vol */
543 unsigned char pan; /* 0-64, 100 for surround */
544 signed char subpan; /* use (pan + subpan/256.0f) or ((pan<<8)+subpan) */
545 unsigned char filter_cutoff; /* 0-127 cutoff=127 AND resonance=0 */
546 unsigned char filter_subcutoff; /* 0-255 -> no filters (subcutoff */
547 unsigned char filter_resonance; /* 0-127 always 0 in this case) */
548 /* subcutoff only changes from zero if filter envelopes are in use. The
549 * calculation (filter_cutoff + filter_subcutoff/256.0f) gives a more
550 * accurate filter cutoff measurement as a float. It would often be more
551 * useful to use a scaled int such as ((cutoff<<8) + subcutoff).
552 */
553 };
554
555 /* Values of 64 or more will access NNA channels here. */
556 void DUMBEXPORT dumb_it_sr_get_channel_state(DUMB_IT_SIGRENDERER *sr, int channel, DUMB_IT_CHANNEL_STATE *state);
557
558
559 /* Signal Design Helper Values */
560
561 /* Use pow(DUMB_SEMITONE_BASE, n) to get the 'delta' value to transpose up by
562 * n semitones. To transpose down, use negative n.
563 */
564 #define DUMB_SEMITONE_BASE 1.059463094359295309843105314939748495817
565
566 /* Use pow(DUMB_QUARTERTONE_BASE, n) to get the 'delta' value to transpose up
567 * by n quartertones. To transpose down, use negative n.
568 */
569 #define DUMB_QUARTERTONE_BASE 1.029302236643492074463779317738953977823
570
571 /* Use pow(DUMB_PITCH_BASE, n) to get the 'delta' value to transpose up by n
572 * units. In this case, 256 units represent one semitone; 3072 units
573 * represent one octave. These units are used by the sequence signal (SEQU).
574 */
575 #define DUMB_PITCH_BASE 1.000225659305069791926712241547647863626
576
577
578 /* Signal Design Function Types */
579
580 typedef void sigdata_t;
581 typedef void sigrenderer_t;
582
583 typedef sigdata_t *(*DUH_LOAD_SIGDATA)(DUH *duh, DUMBFILE *file);
584
585 typedef sigrenderer_t *(*DUH_START_SIGRENDERER)(
586 DUH *duh,
587 sigdata_t *sigdata,
588 int n_channels,
589 int32 pos
590 );
591
592 typedef void (*DUH_SIGRENDERER_SET_SIGPARAM)(
593 sigrenderer_t *sigrenderer,
594 unsigned char id, int32 value
595 );
596
597 typedef int32 (*DUH_SIGRENDERER_GENERATE_SAMPLES)(
598 sigrenderer_t *sigrenderer,
599 double volume, double delta,
600 int32 size, sample_t **samples
601 );
extract_ttl_duration(const TABLE * const table_arg,const Rdb_tbl_def * const tbl_def_arg,uint64 * ttl_duration)602
603 typedef void (*DUH_SIGRENDERER_GET_CURRENT_SAMPLE)(
604 sigrenderer_t *sigrenderer,
605 double volume,
606 sample_t *samples
607 );
608
609 typedef void (*DUH_END_SIGRENDERER)(sigrenderer_t *sigrenderer);
610
611 typedef void (*DUH_UNLOAD_SIGDATA)(sigdata_t *sigdata);
612
613
614 /* Signal Design Function Registration */
615
616 typedef struct DUH_SIGTYPE_DESC
617 {
618 int32 type;
619 DUH_LOAD_SIGDATA load_sigdata;
620 DUH_START_SIGRENDERER start_sigrenderer;
621 DUH_SIGRENDERER_SET_SIGPARAM sigrenderer_set_sigparam;
622 DUH_SIGRENDERER_GENERATE_SAMPLES sigrenderer_generate_samples;
623 DUH_SIGRENDERER_GET_CURRENT_SAMPLE sigrenderer_get_current_sample;
624 DUH_END_SIGRENDERER end_sigrenderer;
625 DUH_UNLOAD_SIGDATA unload_sigdata;
626 }
627 DUH_SIGTYPE_DESC;
628
629 void DUMBEXPORT dumb_register_sigtype(DUH_SIGTYPE_DESC *desc);
630
631
632 // Decide where to put these functions; new heading?
633
634 sigdata_t *DUMBEXPORT duh_get_raw_sigdata(DUH *duh, int sig, int32 type);
635
636 DUH_SIGRENDERER *DUMBEXPORT duh_encapsulate_raw_sigrenderer(sigrenderer_t *vsigrenderer, DUH_SIGTYPE_DESC *desc, int n_channels, int32 pos);
637 sigrenderer_t *DUMBEXPORT duh_get_raw_sigrenderer(DUH_SIGRENDERER *sigrenderer, int32 type);
638
639 int DUMBEXPORT duh_add_signal(DUH *duh, DUH_SIGTYPE_DESC *desc, sigdata_t *sigdata);
640
641
642 /* Standard Signal Types */
extract_ttl_col(const TABLE * const table_arg,const Rdb_tbl_def * const tbl_def_arg,std::string * ttl_column,uint * ttl_field_index,bool skip_checks)643
644 //void dumb_register_sigtype_sample(void);
645
646
647 /* Sample Buffer Allocation Helpers */
648
649 #ifdef DUMB_DECLARE_DEPRECATED
650 sample_t **create_sample_buffer(int n_channels, int32 length) DUMB_DEPRECATED;
651 /* DUMB has been changed to interleave stereo samples. Use
652 * allocate_sample_buffer() instead, and see the comments for
653 * duh_sigrenderer_set_analyser_callback().
654 */
655 #endif
656 sample_t **DUMBEXPORT allocate_sample_buffer(int n_channels, int32 length);
657 void DUMBEXPORT destroy_sample_buffer(sample_t **samples);
658
659
660 /* Silencing Helper */
661
662 void DUMBEXPORT dumb_silence(sample_t *samples, int32 length);
663
664
665 /* Click Removal Helpers */
666
667 typedef struct DUMB_CLICK_REMOVER DUMB_CLICK_REMOVER;
668
669 DUMB_CLICK_REMOVER *DUMBEXPORT dumb_create_click_remover(void);
670 void DUMBEXPORT dumb_record_click(DUMB_CLICK_REMOVER *cr, int32 pos, sample_t step);
671 void DUMBEXPORT dumb_remove_clicks(DUMB_CLICK_REMOVER *cr, sample_t *samples, int32 length, int step, double halflife);
672 sample_t DUMBEXPORT dumb_click_remover_get_offset(DUMB_CLICK_REMOVER *cr);
673 void DUMBEXPORT dumb_destroy_click_remover(DUMB_CLICK_REMOVER *cr);
674
675 DUMB_CLICK_REMOVER **DUMBEXPORT dumb_create_click_remover_array(int n);
676 void DUMBEXPORT dumb_record_click_array(int n, DUMB_CLICK_REMOVER **cr, int32 pos, sample_t *step);
677 void DUMBEXPORT dumb_record_click_negative_array(int n, DUMB_CLICK_REMOVER **cr, int32 pos, sample_t *step);
678 void DUMBEXPORT dumb_remove_clicks_array(int n, DUMB_CLICK_REMOVER **cr, sample_t **samples, int32 length, double halflife);
679 void DUMBEXPORT dumb_click_remover_get_offset_array(int n, DUMB_CLICK_REMOVER **cr, sample_t *offset);
680 void DUMBEXPORT dumb_destroy_click_remover_array(int n, DUMB_CLICK_REMOVER **cr);
681
682
683 /* Resampling Helpers */
684
685 #define DUMB_RQ_ALIASING 0
686 #define DUMB_LQ_LINEAR 1
687 #define DUMB_LQ_CUBIC 2
688
689 #define DUMB_RQ_BLEP 3
690 #define DUMB_RQ_LINEAR 4
691 #define DUMB_RQ_BLAM 5
692 #define DUMB_RQ_CUBIC 6
693 #define DUMB_RQ_FIR 7
694 #define DUMB_RQ_N_LEVELS 8
gen_qualifier_for_table(const char * const qualifier,const std::string & partition_name)695
696 /* Subtract quality above by this to convert to resampler.c's quality */
697 #define DUMB_RESAMPLER_BASE 2
698
699 extern int dumb_resampling_quality; /* This specifies the default */
700 void DUMBEXPORT dumb_it_set_resampling_quality(DUMB_IT_SIGRENDERER * sigrenderer, int quality); /* This overrides it */
701
702 typedef struct DUMB_RESAMPLER DUMB_RESAMPLER;
703
704 typedef struct DUMB_VOLUME_RAMP_INFO DUMB_VOLUME_RAMP_INFO;
705
706 typedef void (*DUMB_RESAMPLE_PICKUP)(DUMB_RESAMPLER *resampler, void *data);
707
708 struct DUMB_RESAMPLER
709 {
710 void *src;
711 int32 pos;
712 int subpos;
713 int32 start, end;
714 int dir;
715 DUMB_RESAMPLE_PICKUP pickup;
716 void *pickup_data;
717 int quality;
718 /* Everything below this point is internal: do not use. */
719 union {
720 sample_t x24[3*2];
721 short x16[3*2];
722 signed char x8[3*2];
723 } x;
gen_cf_name_qualifier_for_partition(const std::string & prefix)724 int overshot;
725 double fir_resampler_ratio;
726 void* fir_resampler[2];
727 };
728
729 struct DUMB_VOLUME_RAMP_INFO
730 {
731 float volume;
gen_ttl_duration_qualifier_for_partition(const std::string & prefix)732 float delta;
733 float target;
734 float mix;
735 unsigned char declick_stage;
736 };
737
738 void dumb_reset_resampler(DUMB_RESAMPLER *resampler, sample_t *src, int src_channels, int32 pos, int32 start, int32 end, int quality);
739 DUMB_RESAMPLER *dumb_start_resampler(sample_t *src, int src_channels, int32 pos, int32 start, int32 end, int quality);
gen_ttl_col_qualifier_for_partition(const std::string & prefix)740 //int32 dumb_resample_1_1(DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume, double delta);
741 int32 dumb_resample_1_2(DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, double delta);
742 //int32 dumb_resample_2_1(DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, double delta);
743 int32 dumb_resample_2_2(DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, double delta);
744 //void dumb_resample_get_current_sample_1_1(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume, sample_t *dst);
745 void dumb_resample_get_current_sample_1_2(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
746 //void dumb_resample_get_current_sample_2_1(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
747 void dumb_resample_get_current_sample_2_2(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
parse_comment_for_qualifier(const std::string & comment,const TABLE * const table_arg,const Rdb_tbl_def * const tbl_def_arg,bool * per_part_match_found,const char * const qualifier)748 void dumb_end_resampler(DUMB_RESAMPLER *resampler);
749
750 void dumb_reset_resampler_16(DUMB_RESAMPLER *resampler, short *src, int src_channels, int32 pos, int32 start, int32 end, int quality);
751 DUMB_RESAMPLER *dumb_start_resampler_16(short *src, int src_channels, int32 pos, int32 start, int32 end, int quality);
752 //int32 dumb_resample_16_1_1(DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume, double delta);
753 int32 dumb_resample_16_1_2(DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, double delta);
754 //int32 dumb_resample_16_2_1(DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, double delta);
755 int32 dumb_resample_16_2_2(DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, double delta);
756 //void dumb_resample_get_current_sample_16_1_1(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume, sample_t *dst);
757 void dumb_resample_get_current_sample_16_1_2(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
758 //void dumb_resample_get_current_sample_16_2_1(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
759 void dumb_resample_get_current_sample_16_2_2(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
760 void dumb_end_resampler_16(DUMB_RESAMPLER *resampler);
761
762 void dumb_reset_resampler_8(DUMB_RESAMPLER *resampler, signed char *src, int src_channels, int32 pos, int32 start, int32 end, int quality);
763 DUMB_RESAMPLER *dumb_start_resampler_8(signed char *src, int src_channels, int32 pos, int32 start, int32 end, int quality);
764 //int32 dumb_resample_8_1_1(DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume, double delta);
765 int32 dumb_resample_8_1_2(DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, double delta);
766 //int32 dumb_resample_8_2_1(DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, double delta);
767 int32 dumb_resample_8_2_2(DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, double delta);
768 //void dumb_resample_get_current_sample_8_1_1(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume, sample_t *dst);
769 void dumb_resample_get_current_sample_8_1_2(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
770 //void dumb_resample_get_current_sample_8_2_1(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
771 void dumb_resample_get_current_sample_8_2_2(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
772 void dumb_end_resampler_8(DUMB_RESAMPLER *resampler);
773
774 void dumb_reset_resampler_n(int n, DUMB_RESAMPLER *resampler, void *src, int src_channels, int32 pos, int32 start, int32 end, int quality);
775 DUMB_RESAMPLER *dumb_start_resampler_n(int n, void *src, int src_channels, int32 pos, int32 start, int32 end, int quality);
776 //int32 dumb_resample_n_1_1(int n, DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume, double delta);
777 int32 dumb_resample_n_1_2(int n, DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, double delta);
778 //int32 dumb_resample_n_2_1(int n, DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, double delta);
779 int32 dumb_resample_n_2_2(int n, DUMB_RESAMPLER *resampler, sample_t *dst, int32 dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, double delta);
780 //void dumb_resample_get_current_sample_n_1_1(int n, DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume, sample_t *dst);
781 void dumb_resample_get_current_sample_n_1_2(int n, DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
782 //void dumb_resample_get_current_sample_n_2_1(int n, DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
783 void dumb_resample_get_current_sample_n_2_2(int n, DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
784 void dumb_end_resampler_n(int n, DUMB_RESAMPLER *resampler);
785
786 /* This sets the default panning separation for hard panned formats,
787 or for formats with default panning information. This must be set
788 before using any readers or loaders, and is not really thread safe. */
789
790 extern int dumb_it_default_panning_separation; /* in percent, default 25 */
791
792 /* DUH Construction */
793
794 DUH *make_duh(
795 int32 length,
796 int n_tags,
797 const char *const tag[][2],
798 int n_signals,
799 DUH_SIGTYPE_DESC *desc[],
800 sigdata_t *sigdata[]
801 );
802
803 void DUMBEXPORT duh_set_length(DUH *duh, int32 length);
804
805 #ifdef __cplusplus
806 }
807 #endif
808
809
810 #endif /* DUMB_H */
811