config.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. TiMidity -- Experimental MIDI to WAVE converter
  3. Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. /* This is for use with the SDL library */
  17. #define SDL
  18. #if (defined(WIN32) || defined(_WIN32)) && !defined(__WIN32__)
  19. #define __WIN32__
  20. #endif
  21. #define LITTLE_ENDIAN
  22. #include <stdint.h>
  23. /* When a patch file can't be opened, one of these extensions is
  24. appended to the filename and the open is tried again.
  25. */
  26. #define PATCH_EXT_LIST { ".pat", 0 }
  27. /* Acoustic Grand Piano seems to be the usual default instrument. */
  28. #define DEFAULT_PROGRAM 0
  29. /* 9 here is MIDI channel 10, which is the standard percussion channel.
  30. Some files (notably C:\WINDOWS\CANYON.MID) think that 16 is one too.
  31. On the other hand, some files know that 16 is not a drum channel and
  32. try to play music on it. This is now a runtime option, so this isn't
  33. a critical choice anymore. */
  34. //#define DEFAULT_DRUMCHANNELS ((1<<9) | (1<<15))
  35. #define DEFAULT_DRUMCHANNELS ((1<<9))
  36. /* A somewhat arbitrary frequency range. The low end of this will
  37. sound terrible as no lowpass filtering is performed on most
  38. instruments before resampling. */
  39. #define MIN_OUTPUT_RATE 4000
  40. #define MAX_OUTPUT_RATE 65000
  41. /* In percent. */
  42. #define DEFAULT_AMPLIFICATION 70
  43. /* Default sampling rate, default polyphony, and maximum polyphony.
  44. All but the last can be overridden from the command line. */
  45. #define DEFAULT_RATE 32000
  46. #define DEFAULT_VOICES 32
  47. #define MAX_VOICES 48
  48. /* 1000 here will give a control ratio of 22:1 with 22 kHz output.
  49. Higher CONTROLS_PER_SECOND values allow more accurate rendering
  50. of envelopes and tremolo. The cost is CPU time. */
  51. #define CONTROLS_PER_SECOND 1000
  52. /* Strongly recommended. This option increases CPU usage by half, but
  53. without it sound quality is very poor. */
  54. #define LINEAR_INTERPOLATION
  55. /* This is an experimental kludge that needs to be done right, but if
  56. you've got an 8-bit sound card, or cheap multimedia speakers hooked
  57. to your 16-bit output device, you should definitely give it a try.
  58. Defining LOOKUP_HACK causes table lookups to be used in mixing
  59. instead of multiplication. We convert the sample data to 8 bits at
  60. load time and volumes to logarithmic 7-bit values before looking up
  61. the product, which degrades sound quality noticeably.
  62. Defining LOOKUP_HACK should save ~20% of CPU on an Intel machine.
  63. LOOKUP_INTERPOLATION might give another ~5% */
  64. /* #define LOOKUP_HACK
  65. #define LOOKUP_INTERPOLATION */
  66. /* Make envelopes twice as fast. Saves ~20% CPU time (notes decay
  67. faster) and sounds more like a GUS. There is now a command line
  68. option to toggle this as well. */
  69. #define FAST_DECAY
  70. /* How many bits to use for the fractional part of sample positions.
  71. This affects tonal accuracy. The entire position counter must fit
  72. in 32 bits, so with FRACTION_BITS equal to 12, the maximum size of
  73. a sample is 1048576 samples (2 megabytes in memory). The GUS gets
  74. by with just 9 bits and a little help from its friends...
  75. "The GUS does not SUCK!!!" -- a happy user :) */
  76. #define FRACTION_BITS 12
  77. /* For some reason the sample volume is always set to maximum in all
  78. patch files. Define this for a crude adjustment that may help
  79. equalize instrument volumes. */
  80. #define ADJUST_SAMPLE_VOLUMES
  81. /* The number of samples to use for ramping out a dying note. Affects
  82. click removal. */
  83. #define MAX_DIE_TIME 20
  84. /* On some machines (especially PCs without math coprocessors),
  85. looking up sine values in a table will be significantly faster than
  86. computing them on the fly. Uncomment this to use lookups. */
  87. /* #define LOOKUP_SINE */
  88. /* Shawn McHorse's resampling optimizations. These may not in fact be
  89. faster on your particular machine and compiler. You'll have to run
  90. a benchmark to find out. */
  91. #define PRECALC_LOOPS
  92. /* If calling ldexp() is faster than a floating point multiplication
  93. on your machine/compiler/libm, uncomment this. It doesn't make much
  94. difference either way, but hey -- it was on the TODO list, so it
  95. got done. */
  96. /* #define USE_LDEXP */
  97. /**************************************************************************/
  98. /* Anything below this shouldn't need to be changed unless you're porting
  99. to a new machine with other than 32-bit, big-endian words. */
  100. /**************************************************************************/
  101. /* change FRACTION_BITS above, not these */
  102. #define INTEGER_BITS (32 - FRACTION_BITS)
  103. #define INTEGER_MASK (0xFFFFFFFF << FRACTION_BITS)
  104. #define FRACTION_MASK (~ INTEGER_MASK)
  105. /* This is enforced by some computations that must fit in an int */
  106. #define MAX_CONTROL_RATIO 255
  107. /* Instrument files are little-endian, MIDI files big-endian, so we
  108. need to do some conversions. */
  109. #define XCHG_SHORT(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
  110. # define XCHG_LONG(x) ((((x)&0xFF)<<24) | \
  111. (((x)&0xFF00)<<8) | \
  112. (((x)&0xFF0000)>>8) | \
  113. (((x)>>24)&0xFF))
  114. #ifdef LITTLE_ENDIAN
  115. #define LE_SHORT(x) x
  116. #define LE_LONG(x) x
  117. #define BE_SHORT(x) XCHG_SHORT(x)
  118. #define BE_LONG(x) XCHG_LONG(x)
  119. #else
  120. #define BE_SHORT(x) x
  121. #define BE_LONG(x) x
  122. #define LE_SHORT(x) XCHG_SHORT(x)
  123. #define LE_LONG(x) XCHG_LONG(x)
  124. #endif
  125. #define MAX_AMPLIFICATION 800
  126. /* These affect general volume */
  127. #define GUARD_BITS 3
  128. #define AMP_BITS (15-GUARD_BITS)
  129. #ifdef LOOKUP_HACK
  130. typedef int8_t sample_t;
  131. typedef uint8_t final_volume_t;
  132. # define FINAL_VOLUME(v) (~_l2u[v])
  133. # define MIXUP_SHIFT 5
  134. # define MAX_AMP_VALUE 4095
  135. #else
  136. typedef int16_t sample_t;
  137. typedef int32_t final_volume_t;
  138. # define FINAL_VOLUME(v) (v)
  139. # define MAX_AMP_VALUE ((1<<(AMP_BITS+1))-1)
  140. #endif
  141. #ifdef USE_LDEXP
  142. # define FSCALE(a,b) ldexp((a),(b))
  143. # define FSCALENEG(a,b) ldexp((a),-(b))
  144. #else
  145. # define FSCALE(a,b) (float)((a) * (double)(1<<(b)))
  146. # define FSCALENEG(a,b) (float)((a) * (1.0L / (double)(1<<(b))))
  147. #endif
  148. /* Vibrato and tremolo Choices of the Day */
  149. #define SWEEP_TUNING 38
  150. #define VIBRATO_AMPLITUDE_TUNING 1.0L
  151. #define VIBRATO_RATE_TUNING 38
  152. #define TREMOLO_AMPLITUDE_TUNING 1.0L
  153. #define TREMOLO_RATE_TUNING 38
  154. #define SWEEP_SHIFT 16
  155. #define RATE_SHIFT 5
  156. #define VIBRATO_SAMPLE_INCREMENTS 32
  157. #ifndef PI
  158. const float PI = 3.14159265358979323846f;
  159. #endif
  160. /* The path separator (D.M.) */
  161. //#ifdef __WIN32__
  162. # define PATH_SEP '\\'
  163. # define PATH_STRING "\\"
  164. //#else
  165. //# define PATH_SEP '/'
  166. //# define PATH_STRING "/"
  167. //#endif