1 /*
2     TiMidity++ -- MIDI to WAVE converter and player
3     Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
4     Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
5 
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20 
21 /*
22  * Historical issues: This file once was a huge header file, but now is
23  * devided into some smaller ones.  Please do not add things to this
24  * header, but consider put them on other files.
25  */
26 
27 #ifndef TIMIDITY_H_INCLUDED
28 #define TIMIDITY_H_INCLUDED 1
29 
30 /*
31    Table of contents:
32    (1) Flags and definitions to customize timidity
33    (3) inportant definitions not to customize
34    (2) #includes -- include other headers
35  */
36 
37 /*****************************************************************************\
38  section 1: some customize issues
39 \*****************************************************************************/
40 
41 
42 /* You could specify a complete path, e.g. "/etc/timidity.cfg", and
43    then specify the library directory in the configuration file. */
44 /* #define CONFIG_FILE "/etc/timidity.cfg" */
45 #ifndef CONFIG_FILE
46 #  ifdef DEFAULT_PATH
47 #    define CONFIG_FILE DEFAULT_PATH "/timidity.cfg"
48 #  else
49 #    define CONFIG_FILE PKGDATADIR "/timidity.cfg"
50 #  endif /* DEFAULT_PATH */
51 #endif /* CONFIG_FILE */
52 
53 
54 /* Filename extension, followed by command to run decompressor so that
55    output is written to stdout. Terminate the list with a 0.
56 
57    Any file with a name ending in one of these strings will be run
58    through the corresponding decompressor. If you don't like this
59    behavior, you can undefine DECOMPRESSOR_LIST to disable automatic
60    decompression entirely. */
61 
62 #define DECOMPRESSOR_LIST { \
63 			      ".gz",  "gunzip -c %s", \
64 			      ".xz",  "xzcat %s", \
65 			      ".lzma", "lzcat %s", \
66 			      ".bz2", "bunzip2 -c %s", \
67 			      ".Z",   "zcat %s", \
68 			      ".zip", "unzip -p %s", \
69 			      ".lha", "lha -pq %s", \
70 			      ".lzh", "lha -pq %s", \
71 			      ".shn", "shorten -x %s -", \
72 			     0 }
73 
74 
75 /* Define GUS/patch converter. */
76 #define PATCH_CONVERTERS { \
77 			     ".wav", "wav2pat %s", \
78 			     0 }
79 
80 /* When a patch file can't be opened, one of these extensions is
81    appended to the filename and the open is tried again.
82 
83    This is ignored for Windows, which uses only ".pat" (see the bottom
84    of this file if you need to change this.) */
85 #define PATCH_EXT_LIST { \
86 			   ".pat", \
87 			   ".shn", ".pat.shn", \
88 			   ".gz", ".pat.gz", \
89 			   ".bz2", ".pat.bz2", \
90 			   0 }
91 
92 
93 /* Acoustic Grand Piano seems to be the usual default instrument. */
94 #define DEFAULT_PROGRAM 0
95 
96 
97 /* Specify drum channels (terminated with -1).
98    10 is the standard percussion channel.
99    Some files (notably C:\WINDOWS\CANYON.MID) think that 16 is one too.
100    On the other hand, some files know that 16 is not a drum channel and
101    try to play music on it. This is now a runtime option, so this isn't
102    a critical choice anymore. */
103 #define DEFAULT_DRUMCHANNELS {10, -1}
104 /* #define DEFAULT_DRUMCHANNELS {10, 16, -1} */
105 
106 /* type of floating point number */
107 typedef double FLOAT_T;
108 /* typedef float FLOAT_T; */
109 
110 
111 /* A somewhat arbitrary frequency range. The low end of this will
112    sound terrible as no lowpass filtering is performed on most
113    instruments before resampling. */
114 #define MIN_OUTPUT_RATE 	4000
115 #define MAX_OUTPUT_RATE 	400000
116 
117 
118 /* Master volume in percent. */
119 #define DEFAULT_AMPLIFICATION 	70
120 
121 
122 /* Default sampling rate, default polyphony, and maximum polyphony.
123    All but the last can be overridden from the command line. */
124 #ifndef DEFAULT_RATE
125 #define DEFAULT_RATE	44100
126 #endif /* DEFAULT_RATE */
127 
128 #define DEFAULT_VOICES	256
129 
130 
131 /* The size of the internal buffer is 2^AUDIO_BUFFER_BITS samples.
132    This determines maximum number of samples ever computed in a row.
133 
134    For Linux and FreeBSD users:
135 
136    This also specifies the size of the buffer fragment.  A smaller
137    fragment gives a faster response in interactive mode -- 10 or 11 is
138    probably a good number. Unfortunately some sound cards emit a click
139    when switching DMA buffers. If this happens to you, try increasing
140    this number to reduce the frequency of the clicks.
141 
142    For other systems:
143 
144    You should probably use a larger number for improved performance.
145 
146 */
147 #define AUDIO_BUFFER_BITS 12	/* Maxmum audio buffer size (2^bits) */
148 
149 
150 /* 1000 here will give a control ratio of 22:1 with 22 kHz output.
151    Higher CONTROLS_PER_SECOND values allow more accurate rendering
152    of envelopes and tremolo. The cost is CPU time. */
153 #define CONTROLS_PER_SECOND 1000
154 
155 
156 /* Default resamplation algorighm.  Define as resample_XXX, where XXX is
157    the algorithm name.  The following algorighms are available:
158    cspline, gauss, newton, linear, none. */
159 #ifndef DEFAULT_RESAMPLATION
160 #define DEFAULT_RESAMPLATION resample_gauss
161 #endif
162 
163 /* Don't allow users to choose the resamplation algorithm. */
164 /* #define FIXED_RESAMPLATION */
165 
166 
167 /* Defining USE_DSP_EFFECT to refine chorus, delay, EQ and insertion effect.
168    This is definitely worth the slight increase in CPU usage. */
169 #define USE_DSP_EFFECT
170 
171 
172 /* This is an experimental kludge that needs to be done right, but if
173    you've got an 8-bit sound card, or cheap multimedia speakers hooked
174    to your 16-bit output device, you should definitely give it a try.
175 
176    Defining LOOKUP_HACK causes table lookups to be used in mixing
177    instead of multiplication. We convert the sample data to 8 bits at
178    load time and volumes to logarithmic 7-bit values before looking up
179    the product, which degrades sound quality noticeably.
180 
181    Defining LOOKUP_HACK should save ~20% of CPU on an Intel machine.
182    LOOKUP_INTERPOLATION might give another ~5% */
183 /* #define LOOKUP_HACK */
184 /* #define LOOKUP_INTERPOLATION */
185 
186 /* Greatly reduces popping due to large volume/pan changes.
187  * This is definitely worth the slight increase in CPU usage. */
188 #define SMOOTH_MIXING
189 
190 /* Make envelopes twice as fast. Saves ~20% CPU time (notes decay
191    faster) and sounds more like a GUS. There is now a command line
192    option to toggle this as well. */
193 /* #define FAST_DECAY */
194 
195 
196 /* How many bits to use for the fractional part of sample positions.
197    This affects tonal accuracy. The entire position counter must fit
198    in 32 bits, so with FRACTION_BITS equal to 12, the maximum size of
199    a sample is 1048576 samples (2 megabytes in memory). The GUS gets
200    by with just 9 bits and a little help from its friends...
201    "The GUS does not SUCK!!!" -- a happy user :) */
202 #define FRACTION_BITS 12
203 
204 
205 /* For some reason the sample volume is always set to maximum in all
206    patch files. Define this for a crude adjustment that may help
207    equalize instrument volumes. */
208 #define ADJUST_SAMPLE_VOLUMES
209 
210 
211 /* If you have root access, you can define DANGEROUS_RENICE and chmod
212    timidity setuid root to have it automatically raise its priority
213    when run -- this may make it possible to play MIDI files in the
214    background while running other CPU-intensive jobs. Of course no
215    amount of renicing will help if the CPU time simply isn't there.
216 
217    The root privileges are used and dropped at the beginning of main()
218    in timidity.c -- please check the code to your satisfaction before
219    using this option. (And please check sections 11 and 12 in the
220    GNU General Public License (under GNU Emacs, hit ^H^W) ;) */
221 /* #define DANGEROUS_RENICE -15 */
222 
223 
224 /* The number of samples to use for ramping out a dying note. Affects
225    click removal. */
226 #define MAX_DIE_TIME 20
227 
228 
229 /* On some machines (especially PCs without math coprocessors),
230    looking up sine values in a table will be significantly faster than
231    computing them on the fly. Uncomment this to use lookups. */
232 #define LOOKUP_SINE
233 
234 
235 /* Shawn McHorse's resampling optimizations. These may not in fact be
236    faster on your particular machine and compiler. You'll have to run
237    a benchmark to find out. */
238 #define PRECALC_LOOPS
239 
240 
241 /* If calling ldexp() is faster than a floating point multiplication
242    on your machine/compiler/libm, uncomment this. It doesn't make much
243    difference either way, but hey -- it was on the TODO list, so it
244    got done. */
245 /* #define USE_LDEXP */
246 
247 
248 /* Define the pre-resampling cache size.
249  * This value is default. You can change the cache saze with
250  * command line option.
251  */
252 #define DEFAULT_CACHE_DATA_SIZE (2*1024*1024)
253 
254 
255 #ifdef SUPPORT_SOCKET
256 /* Please define your mail domain address. */
257 #ifndef MAIL_DOMAIN
258 #define MAIL_DOMAIN "@localhost"
259 #endif /* MAIL_DOMAIN */
260 
261 /* Please define your mail name if you are at Windows.
262  * Otherwise (maybe unix), undefine this macro
263  */
264 /* #define MAIL_NAME "somebody" */
265 #endif /* SUPPORT_SOCKET */
266 
267 
268 /* Where do you want to put temporary file into ?
269  * If you are in UNIX, you can undefine this macro. If TMPDIR macro is
270  * undefined, the value is used in environment variable `TMPDIR'.
271  * If both macro and environment variable is not set, the directory is
272  * set to /tmp.
273  */
274 /* #define TMPDIR "/var/tmp" */
275 
276 
277 /* To use GS drumpart setting. */
278 #define GS_DRUMPART
279 
280 /**** Japanese section ****/
281 /* To use Japanese kanji code. */
282 #define JAPANESE
283 
284 /* Select output text code:
285  * "AUTO"	- Auto conversion by `LANG' environment variable (UNIX only)
286  * "ASCII"	- Convert unreadable characters to '.'(0x2e)
287  * "NOCNV"	- No conversion
288  * "EUC"	- EUC
289  * "JIS"	- JIS
290  * "SJIS"	- shift JIS
291  */
292 
293 #ifndef JAPANESE
294 /* Not japanese (Select "ASCII" or "NOCNV") */
295 #define OUTPUT_TEXT_CODE "ASCII"
296 #else
297 /* Japanese */
298 #ifndef __W32__
299 /* UNIX (Select "AUTO" or "ASCII" or "NOCNV" or "EUC" or "JIS" or "SJIS") */
300 #define OUTPUT_TEXT_CODE "AUTO"
301 #else
302 /* Windows (Select "ASCII" or "NOCNV" or "SJIS") */
303 #define OUTPUT_TEXT_CODE "SJIS"
304 #endif
305 #endif
306 
307 
308 /* Undefine if you don't use modulation wheel MIDI controls.
309  * There is a command line option to enable/disable this mode.
310  */
311 #define MODULATION_WHEEL_ALLOW
312 
313 
314 /* Undefine if you don't use portamento MIDI controls.
315  * There is a command line option to enable/disable this mode.
316  */
317 #define PORTAMENTO_ALLOW
318 
319 
320 /* Undefine if you don't use NRPN vibrato MIDI controls
321  * There is a command line option to enable/disable this mode.
322  */
323 #define NRPN_VIBRATO_ALLOW
324 
325 
326 /* Define if you want to use reverb / freeverb controls in defaults.
327  * This mode needs high CPU power.
328  * There is a command line option to enable/disable this mode.
329  */
330 /* #define REVERB_CONTROL_ALLOW */
331 #define FREEVERB_CONTROL_ALLOW
332 
333 
334 /* Define if you want to use chorus controls in defaults.
335  * This mode needs high CPU power.
336  * There is a command line option to enable/disable this mode.
337  */
338 #define CHORUS_CONTROL_ALLOW
339 
340 
341 /* Define if you want to use surround chorus in defaults.
342  * This mode needs high CPU power.
343  * There is a command line option to enable/disable this mode.
344  */
345 /* #define SURROUND_CHORUS_ALLOW */
346 
347 
348 /* Define if you want to use channel pressure.
349  * Channel pressure effect is different in sequencers.
350  * There is a command line option to enable/disable this mode.
351  */
352 /* #define GM_CHANNEL_PRESSURE_ALLOW */
353 
354 
355 /* Define if you want to use voice chamberlin / moog LPF.
356  * This mode needs high CPU power.
357  * There is a command line option to enable/disable this mode.
358  */
359 #define VOICE_CHAMBERLIN_LPF_ALLOW
360 /* #define VOICE_MOOG_LPF_ALLOW */
361 
362 
363 /* Define if you want to use modulation envelope.
364  * This mode needs high CPU power.
365  * There is a command line option to enable/disable this mode.
366  */
367 /* #define MODULATION_ENVELOPE_ALLOW */
368 
369 
370 /* Define if you want to trace text meta event at playing.
371  * There is a command line option to enable/disable this mode.
372  */
373 /* #define ALWAYS_TRACE_TEXT_META_EVENT */
374 
375 
376 /* Define if you want to allow overlapped voice.
377  * There is a command line option to enable/disable this mode.
378  */
379 #define OVERLAP_VOICE_ALLOW
380 
381 
382 /* Define if you want to allow temperament control.
383  * There is a command line option to enable/disable this mode.
384  */
385 #define TEMPER_CONTROL_ALLOW
386 
387 
388 
389 /*****************************************************************************\
390  section 2: some important definitions
391 \*****************************************************************************/
392 /*
393   Anything below this shouldn't need to be changed unless you're porting
394    to a new machine with other than 32-bit, big-endian words.
395  */
396 
397 /* change FRACTION_BITS above, not these */
398 #define INTEGER_BITS (32 - FRACTION_BITS)
399 #define INTEGER_MASK (0xFFFFFFFF << FRACTION_BITS)
400 #define FRACTION_MASK (~ INTEGER_MASK)
401 
402 /* This is enforced by some computations that must fit in an int */
403 #define MAX_CONTROL_RATIO 255
404 
405 /* Audio buffer size has to be a power of two to allow DMA buffer
406    fragments under the VoxWare (Linux & FreeBSD) audio driver */
407 #define AUDIO_BUFFER_SIZE (1<<AUDIO_BUFFER_BITS)
408 
409 /* These affect general volume */
410 #define GUARD_BITS 3
411 #define AMP_BITS (15-GUARD_BITS)
412 
413 #define MAX_AMPLIFICATION 800
414 #define MAX_CHANNELS 32
415 /*#define MAX_CHANNELS 256*/
416 #define MAXMIDIPORT 16
417 
418 /* Vibrato and tremolo Choices of the Day */
419 #define SWEEP_TUNING 38
420 #define VIBRATO_AMPLITUDE_TUNING 1.0L
421 #define VIBRATO_RATE_TUNING 38
422 #define TREMOLO_AMPLITUDE_TUNING 1.0L
423 #define TREMOLO_RATE_TUNING 38
424 
425 #define SWEEP_SHIFT 16
426 #define RATE_SHIFT 5
427 
428 #define VIBRATO_SAMPLE_INCREMENTS 32
429 
430 #define MODULATION_WHEEL_RATE (1.0/6.0)
431 /* #define MODULATION_WHEEL_RATE (midi_time_ratio/8.0) */
432 /* #define MODULATION_WHEEL_RATE (current_play_tempo/500000.0/32.0) */
433 
434 #define VIBRATO_DEPTH_TUNING (1.0/4.0)
435 
436 /* you cannot but use safe_malloc(). */
437 #define HAVE_SAFE_MALLOC 1
438 /* malloc's limit */
439 #define MAX_SAFE_MALLOC_SIZE (1<<23) /* 8M */
440 
441 #define DEFAULT_SOUNDFONT_ORDER 0
442 
443 
444 /*****************************************************************************\
445  section 3: include other headers
446 \*****************************************************************************/
447 
448 #ifdef HAVE_CONFIG_H
449 #  include "config.h"
450 #endif /* HAVE_CONFIG_H */
451 
452 #include <stdio.h>
453 
454 #ifdef HAVE_ERRNO_H
455 #include <errno.h>
456 #else
457 extern int errno;
458 #endif /* HAVE_ERRNO_H */
459 
460 #ifdef HAVE_MACHINE_ENDIAN_H
461 #include <machine/endian.h> /* for __byte_swap_*() */
462 #endif /* HAVE_MACHINE_ENDIAN_H */
463 
464 #ifdef HAVE_SYS_TYPES_H
465 #include <sys/types.h>
466 #endif /* HAVE_SYS_TYPES_H */
467 
468 #include "sysdep.h"
469 #include "support.h"
470 #include "optcode.h"
471 
472 #endif /* TIMIDITY_H_INCLUDED */
473