summaryrefslogtreecommitdiff
path: root/apps/codecs/dumb/include/dumb.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/dumb/include/dumb.h')
-rw-r--r--apps/codecs/dumb/include/dumb.h563
1 files changed, 563 insertions, 0 deletions
diff --git a/apps/codecs/dumb/include/dumb.h b/apps/codecs/dumb/include/dumb.h
new file mode 100644
index 0000000000..3d6d6f940d
--- /dev/null
+++ b/apps/codecs/dumb/include/dumb.h
@@ -0,0 +1,563 @@
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 * \__/
18 */
19
20#ifndef DUMB_H
21#define DUMB_H
22
23
24#include <stdlib.h>
25#include <stdio.h>
26
27
28#ifdef __cplusplus
29 extern "C" {
30#endif
31
32
33#define DUMB_MAJOR_VERSION 0
34#define DUMB_MINOR_VERSION 9
35#define DUMB_REVISION_VERSION 2
36
37#define DUMB_VERSION (DUMB_MAJOR_VERSION*10000 + DUMB_MINOR_VERSION*100 + DUMB_REVISION_VERSION)
38
39#define DUMB_VERSION_STR "0.9.2"
40
41#define DUMB_NAME "DUMB v"DUMB_VERSION_STR
42
43#define DUMB_YEAR 2003
44#define DUMB_MONTH 4
45#define DUMB_DAY 2
46
47#define DUMB_YEAR_STR2 "03"
48#define DUMB_YEAR_STR4 "2003"
49#define DUMB_MONTH_STR1 "4"
50#define DUMB_DAY_STR1 "2"
51
52#if DUMB_MONTH < 10
53#define DUMB_MONTH_STR2 "0"DUMB_MONTH_STR1
54#else
55#define DUMB_MONTH_STR2 DUMB_MONTH_STR1
56#endif
57
58#if DUMB_DAY < 10
59#define DUMB_DAY_STR2 "0"DUMB_DAY_STR1
60#else
61#define DUMB_DAY_STR2 DUMB_DAY_STR1
62#endif
63
64
65/* WARNING: The month and day were inadvertently swapped in the v0.8 release.
66 * Please do not compare this constant against any date in 2002. In
67 * any case, DUMB_VERSION is probably more useful for this purpose.
68 */
69#define DUMB_DATE (DUMB_YEAR*10000 + DUMB_MONTH*100 + DUMB_DAY)
70
71#define DUMB_DATE_STR DUMB_DAY_STR1"."DUMB_MONTH_STR1"."DUMB_YEAR_STR4
72
73
74#undef MIN
75#undef MAX
76#undef MID
77
78#define MIN(x,y) (((x) < (y)) ? (x) : (y))
79#define MAX(x,y) (((x) > (y)) ? (x) : (y))
80#define MID(x,y,z) MAX((x), MIN((y), (z)))
81
82#undef ABS
83#define ABS(x) (((x) >= 0) ? (x) : (-(x)))
84
85
86#ifdef DEBUGMODE
87
88#ifndef ASSERT
89#include <assert.h>
90#define ASSERT(n) assert(n)
91#endif
92#ifndef TRACE
93// it would be nice if this did actually trace ...
94#define TRACE 1 ? (void)0 : (void)printf
95#endif
96
97#else
98
99#ifndef ASSERT
100#define ASSERT(n)
101#endif
102#ifndef TRACE
103#define TRACE 1 ? (void)0 : (void)printf
104#endif
105
106#endif
107
108
109#define DUMB_ID(a,b,c,d) (((unsigned int)(a) << 24) | \
110 ((unsigned int)(b) << 16) | \
111 ((unsigned int)(c) << 8) | \
112 ((unsigned int)(d) ))
113
114
115
116#ifndef LONG_LONG
117#ifdef __GNUC__
118#define LONG_LONG long long
119#elif defined _MSC_VER
120#define LONG_LONG __int64
121#else
122#error 64-bit integer type unknown
123#endif
124#endif
125
126#if __GNUC__ * 100 + __GNUC_MINOR__ >= 301 /* GCC 3.1+ */
127#ifndef DUMB_DECLARE_DEPRECATED
128#define DUMB_DECLARE_DEPRECATED
129#endif
130#define DUMB_DEPRECATED __attribute__((__deprecated__))
131#else
132#define DUMB_DEPRECATED
133#endif
134
135
136/* Basic Sample Type. Normal range is -0x800000 to 0x7FFFFF. */
137
138typedef int sample_t;
139
140
141/* Library Clean-up Management */
142
143int dumb_atexit(void (*proc)(void));
144
145void dumb_exit(void);
146
147
148/* File Input Functions */
149
150typedef struct DUMBFILE_SYSTEM
151{
152 void *(*open)(const char *filename);
153 int (*skip)(void *f, long n);
154 int (*getc)(void *f);
155 long (*getnc)(char *ptr, long n, void *f);
156 void (*close)(void *f);
157}
158DUMBFILE_SYSTEM;
159
160typedef struct DUMBFILE DUMBFILE;
161
162void register_dumbfile_system(DUMBFILE_SYSTEM *dfs);
163
164DUMBFILE *dumbfile_open(const char *filename);
165DUMBFILE *dumbfile_open_ex(void *file, DUMBFILE_SYSTEM *dfs);
166
167long dumbfile_pos(DUMBFILE *f);
168int dumbfile_skip(DUMBFILE *f, long n);
169
170int dumbfile_getc(DUMBFILE *f);
171
172int dumbfile_igetw(DUMBFILE *f);
173int dumbfile_mgetw(DUMBFILE *f);
174
175long dumbfile_igetl(DUMBFILE *f);
176long dumbfile_mgetl(DUMBFILE *f);
177
178unsigned long dumbfile_cgetul(DUMBFILE *f);
179signed long dumbfile_cgetsl(DUMBFILE *f);
180
181long dumbfile_getnc(char *ptr, long n, DUMBFILE *f);
182
183int dumbfile_error(DUMBFILE *f);
184int dumbfile_close(DUMBFILE *f);
185
186
187/* stdio File Input Module */
188
189/*void dumb_register_stdfiles(void);
190
191DUMBFILE *dumbfile_open_stdfile(int fd);*/
192
193
194/* Memory File Input Module */
195
196DUMBFILE *dumbfile_open_memory(const char *data, long size);
197
198
199/* DUH Management */
200
201typedef struct DUH DUH;
202
203#define DUH_SIGNATURE DUMB_ID('D','U','H','!')
204
205void unload_duh(DUH *duh);
206
207DUH *load_duh(const char *filename);
208DUH *read_duh(DUMBFILE *f);
209
210long duh_get_length(DUH *duh);
211
212
213/* Signal Rendering Functions */
214
215typedef struct DUH_SIGRENDERER DUH_SIGRENDERER;
216
217DUH_SIGRENDERER *duh_start_sigrenderer(DUH *duh, int sig, int n_channels, long pos);
218
219#ifdef DUMB_DECLARE_DEPRECATED
220typedef void (*DUH_SIGRENDERER_CALLBACK)(void *data, sample_t **samples, int n_channels, long length);
221/* This is deprecated, but is not marked as such because GCC tends to
222 * complain spuriously when the typedef is used later. See comments below.
223 */
224
225void duh_sigrenderer_set_callback(
226 DUH_SIGRENDERER *sigrenderer,
227 DUH_SIGRENDERER_CALLBACK callback, void *data
228) DUMB_DEPRECATED;
229/* The 'callback' argument's type has changed for const-correctness. See the
230 * DUH_SIGRENDERER_CALLBACK definition just above. Also note that the samples
231 * in the buffer are now 256 times as large; the normal range is -0x800000 to
232 * 0x7FFFFF. The function has been renamed partly because its functionality
233 * has changed slightly and partly so that its name is more meaningful. The
234 * new one is duh_sigrenderer_set_analyser_callback(), and the typedef for
235 * the function pointer has also changed, from DUH_SIGRENDERER_CALLBACK to
236 * DUH_SIGRENDERER_ANALYSER_CALLBACK. (If you wanted to use this callback to
237 * apply a DSP effect, don't worry; there is a better way of doing this. It
238 * is undocumented, so contact me and I shall try to help. Contact details
239 * are in readme.txt.)
240 */
241#endif
242
243typedef void (*DUH_SIGRENDERER_ANALYSER_CALLBACK)(void *data, const sample_t *const *samples, int n_channels, long length);
244
245void duh_sigrenderer_set_analyser_callback(
246 DUH_SIGRENDERER *sigrenderer,
247 DUH_SIGRENDERER_ANALYSER_CALLBACK callback, void *data
248);
249
250int duh_sigrenderer_get_n_channels(DUH_SIGRENDERER *sigrenderer);
251long duh_sigrenderer_get_position(DUH_SIGRENDERER *sigrenderer);
252
253void duh_sigrenderer_set_sigparam(DUH_SIGRENDERER *sigrenderer, unsigned char id, long value);
254
255long duh_sigrenderer_get_samples(
256 DUH_SIGRENDERER *sigrenderer,
257 float volume, float delta,
258 long size, sample_t **samples
259);
260
261void duh_sigrenderer_get_current_sample(DUH_SIGRENDERER *sigrenderer, float volume, sample_t *samples);
262
263void duh_end_sigrenderer(DUH_SIGRENDERER *sigrenderer);
264
265
266/* DUH Rendering Functions */
267
268long duh_render(
269 DUH_SIGRENDERER *sigrenderer,
270 int bits, int unsign,
271 float volume, float delta,
272 long size, void *sptr
273);
274
275#ifdef DUMB_DECLARE_DEPRECATED
276
277long duh_render_signal(
278 DUH_SIGRENDERER *sigrenderer,
279 float volume, float delta,
280 long size, sample_t **samples
281) DUMB_DEPRECATED;
282/* Please use duh_sigrenderer_get_samples(). Arguments and functionality are
283 * identical.
284 */
285
286typedef DUH_SIGRENDERER DUH_RENDERER DUMB_DEPRECATED;
287/* Please use DUH_SIGRENDERER instead of DUH_RENDERER. */
288
289DUH_SIGRENDERER *duh_start_renderer(DUH *duh, int n_channels, long pos) DUMB_DEPRECATED;
290/* Please use duh_start_sigrenderer() instead. Pass 0 for 'sig'. */
291
292int duh_renderer_get_n_channels(DUH_SIGRENDERER *dr) DUMB_DEPRECATED;
293long duh_renderer_get_position(DUH_SIGRENDERER *dr) DUMB_DEPRECATED;
294/* Please use the duh_sigrenderer_*() equivalents of these two functions. */
295
296void duh_end_renderer(DUH_SIGRENDERER *dr) DUMB_DEPRECATED;
297/* Please use duh_end_sigrenderer() instead. */
298
299DUH_SIGRENDERER *duh_renderer_encapsulate_sigrenderer(DUH_SIGRENDERER *sigrenderer) DUMB_DEPRECATED;
300DUH_SIGRENDERER *duh_renderer_get_sigrenderer(DUH_SIGRENDERER *dr) DUMB_DEPRECATED;
301DUH_SIGRENDERER *duh_renderer_decompose_to_sigrenderer(DUH_SIGRENDERER *dr) DUMB_DEPRECATED;
302/* These functions have become no-ops that just return the parameter.
303 * So, for instance, replace
304 * duh_renderer_encapsulate_sigrenderer(my_sigrenderer)
305 * with
306 * my_sigrenderer
307 */
308
309#endif
310
311
312/* Impulse Tracker Support */
313
314extern int dumb_it_max_to_mix;
315
316typedef struct DUMB_IT_SIGDATA DUMB_IT_SIGDATA;
317typedef struct DUMB_IT_SIGRENDERER DUMB_IT_SIGRENDERER;
318
319DUMB_IT_SIGDATA *duh_get_it_sigdata(DUH *duh);
320DUH_SIGRENDERER *duh_encapsulate_it_sigrenderer(DUMB_IT_SIGRENDERER *it_sigrenderer, int n_channels, long pos);
321DUMB_IT_SIGRENDERER *duh_get_it_sigrenderer(DUH_SIGRENDERER *sigrenderer);
322
323DUH_SIGRENDERER *dumb_it_start_at_order(DUH *duh, int n_channels, int startorder);
324
325void dumb_it_set_loop_callback(DUMB_IT_SIGRENDERER *sigrenderer, int (*callback)(void *data), void *data);
326void dumb_it_set_xm_speed_zero_callback(DUMB_IT_SIGRENDERER *sigrenderer, int (*callback)(void *data), void *data);
327void dumb_it_set_midi_callback(DUMB_IT_SIGRENDERER *sigrenderer, int (*callback)(void *data, int channel, unsigned char byte), void *data);
328
329int dumb_it_callback_terminate(void *data);
330int dumb_it_callback_midi_block(void *data, int channel, unsigned char byte);
331
332DUH *dumb_load_it(const char *filename);
333DUH *dumb_load_xm(const char *filename);
334DUH *dumb_load_s3m(const char *filename);
335DUH *dumb_load_mod(const char *filename);
336
337DUH *dumb_read_it(DUMBFILE *f);
338DUH *dumb_read_xm(DUMBFILE *f);
339DUH *dumb_read_s3m(DUMBFILE *f);
340DUH *dumb_read_mod(DUMBFILE *f);
341
342int dumb_it_sd_get_n_orders(DUMB_IT_SIGDATA *sd);
343
344int dumb_it_sd_get_initial_global_volume(DUMB_IT_SIGDATA *sd);
345void dumb_it_sd_set_initial_global_volume(DUMB_IT_SIGDATA *sd, int gv);
346
347int dumb_it_sd_get_mixing_volume(DUMB_IT_SIGDATA *sd);
348void dumb_it_sd_set_mixing_volume(DUMB_IT_SIGDATA *sd, int mv);
349
350int dumb_it_sd_get_initial_speed(DUMB_IT_SIGDATA *sd);
351void dumb_it_sd_set_initial_speed(DUMB_IT_SIGDATA *sd, int speed);
352
353int dumb_it_sd_get_initial_tempo(DUMB_IT_SIGDATA *sd);
354void dumb_it_sd_set_initial_tempo(DUMB_IT_SIGDATA *sd, int tempo);
355
356int dumb_it_sd_get_initial_channel_volume(DUMB_IT_SIGDATA *sd, int channel);
357void dumb_it_sd_set_initial_channel_volume(DUMB_IT_SIGDATA *sd, int channel, int volume);
358
359int dumb_it_sr_get_current_order(DUMB_IT_SIGRENDERER *sr);
360int dumb_it_sr_get_current_row(DUMB_IT_SIGRENDERER *sr);
361
362int dumb_it_sr_get_global_volume(DUMB_IT_SIGRENDERER *sr);
363void dumb_it_sr_set_global_volume(DUMB_IT_SIGRENDERER *sr, int gv);
364
365int dumb_it_sr_get_tempo(DUMB_IT_SIGRENDERER *sr);
366void dumb_it_sr_set_tempo(DUMB_IT_SIGRENDERER *sr, int tempo);
367
368int dumb_it_sr_get_speed(DUMB_IT_SIGRENDERER *sr);
369void dumb_it_sr_set_speed(DUMB_IT_SIGRENDERER *sr, int speed);
370
371#define DUMB_IT_N_CHANNELS 64
372#define DUMB_IT_N_NNA_CHANNELS 192
373#define DUMB_IT_TOTAL_CHANNELS (DUMB_IT_N_CHANNELS + DUMB_IT_N_NNA_CHANNELS)
374
375/* Channels passed to any of these functions are 0-based */
376int dumb_it_sr_get_channel_volume(DUMB_IT_SIGRENDERER *sr, int channel);
377void dumb_it_sr_set_channel_volume(DUMB_IT_SIGRENDERER *sr, int channel, int volume);
378
379typedef struct DUMB_IT_CHANNEL_STATE DUMB_IT_CHANNEL_STATE;
380
381struct DUMB_IT_CHANNEL_STATE
382{
383 int channel; /* 0-based; meaningful for NNA channels */
384 int sample; /* 1-based; 0 if nothing playing, then other fields undef */
385 int freq; /* in Hz */
386 float volume; /* 1.0 maximum; affected by ALL factors, inc. mixing vol */
387 unsigned char pan; /* 0-64, 100 for surround */
388 signed char subpan; /* use (pan + subpan/256.0f) or ((pan<<8)+subpan) */
389 unsigned char filter_cutoff; /* 0-127 cutoff=127 AND resonance=0 */
390 unsigned char filter_subcutoff; /* 0-255 -> no filters (subcutoff */
391 unsigned char filter_resonance; /* 0-127 always 0 in this case) */
392 /* subcutoff only changes from zero if filter envelopes are in use. The
393 * calculation (filter_cutoff + filter_subcutoff/256.0f) gives a more
394 * accurate filter cutoff measurement as a float. It would often be more
395 * useful to use a scaled int such as ((cutoff<<8) + subcutoff).
396 */
397};
398
399/* Values of 64 or more will access NNA channels here. */
400void dumb_it_sr_get_channel_state(DUMB_IT_SIGRENDERER *sr, int channel, DUMB_IT_CHANNEL_STATE *state);
401
402
403/* Signal Design Helper Values */
404
405/* Use pow(DUMB_SEMITONE_BASE, n) to get the 'delta' value to transpose up by
406 * n semitones. To transpose down, use negative n.
407 */
408#define DUMB_SEMITONE_BASE 1.059463094359295309843105314939748495817
409
410/* Use pow(DUMB_QUARTERTONE_BASE, n) to get the 'delta' value to transpose up
411 * by n quartertones. To transpose down, use negative n.
412 */
413#define DUMB_QUARTERTONE_BASE 1.029302236643492074463779317738953977823
414
415/* Use pow(DUMB_PITCH_BASE, n) to get the 'delta' value to transpose up by n
416 * units. In this case, 256 units represent one semitone; 3072 units
417 * represent one octave. These units are used by the sequence signal (SEQU).
418 */
419#define DUMB_PITCH_BASE 1.000225659305069791926712241547647863626
420
421
422/* Signal Design Function Types */
423
424typedef void sigdata_t;
425typedef void sigrenderer_t;
426
427typedef sigdata_t *(*DUH_LOAD_SIGDATA)(DUH *duh, DUMBFILE *file);
428
429typedef sigrenderer_t *(*DUH_START_SIGRENDERER)(
430 DUH *duh,
431 sigdata_t *sigdata,
432 int n_channels,
433 long pos
434);
435
436typedef void (*DUH_SIGRENDERER_SET_SIGPARAM)(
437 sigrenderer_t *sigrenderer,
438 unsigned char id, long value
439);
440
441typedef long (*DUH_SIGRENDERER_GET_SAMPLES)(
442 sigrenderer_t *sigrenderer,
443 float volume, float delta,
444 long size, sample_t **samples
445);
446
447typedef void (*DUH_SIGRENDERER_GET_CURRENT_SAMPLE)(
448 sigrenderer_t *sigrenderer,
449 float volume,
450 sample_t *samples
451);
452
453typedef void (*DUH_END_SIGRENDERER)(sigrenderer_t *sigrenderer);
454
455typedef void (*DUH_UNLOAD_SIGDATA)(sigdata_t *sigdata);
456
457
458/* Signal Design Function Registration */
459
460typedef struct DUH_SIGTYPE_DESC
461{
462 long type;
463 DUH_LOAD_SIGDATA load_sigdata;
464 DUH_START_SIGRENDERER start_sigrenderer;
465 DUH_SIGRENDERER_SET_SIGPARAM sigrenderer_set_sigparam;
466 DUH_SIGRENDERER_GET_SAMPLES sigrenderer_get_samples;
467 DUH_SIGRENDERER_GET_CURRENT_SAMPLE sigrenderer_get_current_sample;
468 DUH_END_SIGRENDERER end_sigrenderer;
469 DUH_UNLOAD_SIGDATA unload_sigdata;
470}
471DUH_SIGTYPE_DESC;
472
473void dumb_register_sigtype(DUH_SIGTYPE_DESC *desc);
474
475
476// Decide where to put these functions; new heading?
477
478sigdata_t *duh_get_raw_sigdata(DUH *duh, int sig, long type);
479
480DUH_SIGRENDERER *duh_encapsulate_raw_sigrenderer(sigrenderer_t *vsigrenderer, DUH_SIGTYPE_DESC *desc, int n_channels, long pos);
481sigrenderer_t *duh_get_raw_sigrenderer(DUH_SIGRENDERER *sigrenderer, long type);
482
483
484/* Sample Buffer Allocation Helpers */
485
486sample_t **create_sample_buffer(int n_channels, long length);
487void destroy_sample_buffer(sample_t **samples);
488
489
490/* Silencing Helper */
491
492void dumb_silence(sample_t *samples, long length);
493
494
495/* Click Removal Helpers */
496
497typedef struct DUMB_CLICK_REMOVER DUMB_CLICK_REMOVER;
498
499DUMB_CLICK_REMOVER *dumb_create_click_remover(void);
500void dumb_record_click(DUMB_CLICK_REMOVER *cr, long pos, sample_t step);
501void dumb_remove_clicks(DUMB_CLICK_REMOVER *cr, sample_t *samples, long length, float halflife);
502sample_t dumb_click_remover_get_offset(DUMB_CLICK_REMOVER *cr);
503void dumb_destroy_click_remover(DUMB_CLICK_REMOVER *cr);
504
505DUMB_CLICK_REMOVER **dumb_create_click_remover_array(int n);
506void dumb_record_click_array(int n, DUMB_CLICK_REMOVER **cr, long pos, sample_t *step);
507void dumb_record_click_negative_array(int n, DUMB_CLICK_REMOVER **cr, long pos, sample_t *step);
508void dumb_remove_clicks_array(int n, DUMB_CLICK_REMOVER **cr, sample_t **samples, long length, float halflife);
509void dumb_click_remover_get_offset_array(int n, DUMB_CLICK_REMOVER **cr, sample_t *offset);
510void dumb_destroy_click_remover_array(int n, DUMB_CLICK_REMOVER **cr);
511
512
513/* Resampling Helpers */
514
515#define DUMB_RQ_ALIASING 0
516#define DUMB_RQ_LINEAR 1
517#define DUMB_RQ_CUBIC 2
518#define DUMB_RQ_N_LEVELS 3
519extern int dumb_resampling_quality;
520
521typedef struct DUMB_RESAMPLER DUMB_RESAMPLER;
522
523typedef void (*DUMB_RESAMPLE_PICKUP)(DUMB_RESAMPLER *resampler, void *data);
524
525struct DUMB_RESAMPLER
526{
527 sample_t *src;
528 long pos;
529 int subpos;
530 long start, end;
531 int dir;
532 DUMB_RESAMPLE_PICKUP pickup;
533 void *pickup_data;
534 int min_quality;
535 int max_quality;
536 /* Everything below this point is internal: do not use. */
537 sample_t x[3];
538 int overshot;
539};
540
541void dumb_reset_resampler(DUMB_RESAMPLER *resampler, sample_t *src, long pos, long start, long end);
542DUMB_RESAMPLER *dumb_start_resampler(sample_t *src, long pos, long start, long end);
543long dumb_resample(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, float volume, float delta);
544sample_t dumb_resample_get_current_sample(DUMB_RESAMPLER *resampler, float volume);
545void dumb_end_resampler(DUMB_RESAMPLER *resampler);
546
547
548/* DUH Construction */
549
550DUH *make_duh(
551 long length,
552 int n_signals,
553 DUH_SIGTYPE_DESC *desc[],
554 sigdata_t *sigdata[]
555);
556
557
558#ifdef __cplusplus
559 }
560#endif
561
562
563#endif /* DUMB_H */