~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kmidi/config.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        $Id: config.h,v 1.51 2001/06/06 18:56:02 mueller Exp $
 
3
 
 
4
    TiMidity -- Experimental MIDI to WAVE converter
 
5
    Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
 
6
 
 
7
    This program is free software; you can redistribute it and/or modify
 
8
    it under the terms of the GNU General Public License as published by
 
9
    the Free Software Foundation; either version 2 of the License, or
 
10
    (at your option) any later version.
 
11
 
 
12
    This program is distributed in the hope that it will be useful,
 
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
    GNU General Public License for more details.
 
16
 
 
17
    You should have received a copy of the GNU General Public License
 
18
    along with this program; if not, write to the Free Software
 
19
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
20
*/
 
21
 
 
22
#ifdef ADAGIO
 
23
#include "adagio.h"
 
24
#include "allphase.h"
 
25
#endif /* ADAGIO */
 
26
 
 
27
#ifdef KMIDI
 
28
        #include "../config.h"
 
29
#else
 
30
        #include "../../config.h"
 
31
        /* if above referenced file does not exist, use something like:
 
32
        #define HAVE_STRING_H
 
33
        #define HAVE_SLANG_H
 
34
        #define HAVE_USLEEP
 
35
        */
 
36
#endif
 
37
 
 
38
#ifndef HAVE_STRING_H
 
39
#define NO_STRING_H
 
40
#endif
 
41
 
 
42
#ifndef TIMID_DIR
 
43
#ifdef DEFAULT_PATH
 
44
#define TIMID_DIR  DEFAULT_PATH
 
45
#else
 
46
#define TIMID_DIR  "/usr/local/lib/timidity"
 
47
#endif
 
48
#endif
 
49
 
 
50
/* Enable extensions taken from TiMidity++ */
 
51
#define tplus
 
52
 
 
53
/* Enable Nicolas Witczak's effects processing */
 
54
#define CHANNEL_EFFECT
 
55
 
 
56
/* Filename extension, followed by command to run decompressor so that
 
57
   output is written to stdout. Terminate the list with a 0. 
 
58
 
 
59
   Any file with a name ending in one of these strings will be run
 
60
   through the corresponding decompressor. If you don't like this
 
61
   behavior, you can undefine DECOMPRESSOR_LIST to disable automatic
 
62
   decompression entirely. 
 
63
 
 
64
   This is currently ignored for Win32. */
 
65
#define DECOMPRESSOR_LIST { \
 
66
                              ".gz", "gunzip -c %s", \
 
67
                              ".bz2", "bzip2 -cd %s", \
 
68
                              ".Z", "zcat %s", \
 
69
                              ".zip", "unzip -p %s", \
 
70
                              ".lha", "lha -pq %s", \
 
71
                              ".lzh", "lha -pq %s", \
 
72
                              ".shn", "shorten -x %s -", \
 
73
                              ".wav", "wav2pat %s", \
 
74
                             0 }
 
75
 
 
76
/* When a patch file can't be opened, one of these extensions is
 
77
   appended to the filename and the open is tried again.
 
78
 
 
79
   This is ignored for Win32, which uses only ".pat" (see the bottom
 
80
   of this file if you need to change this.) */
 
81
#define PATCH_EXT_LIST { \
 
82
                           ".pat", \
 
83
                           ".shn", ".pat.shn", \
 
84
                           ".gz", ".pat.gz", \
 
85
                           0 }
 
86
 
 
87
/* Acoustic Grand Piano seems to be the usual default instrument. */
 
88
#define DEFAULT_PROGRAM 0
 
89
 
 
90
/* 9 here is MIDI channel 10, which is the standard percussion channel.
 
91
   Some files (notably C:\WINDOWS\CANYON.MID) think that 16 is one too. 
 
92
   On the other hand, some files know that 16 is not a drum channel and
 
93
   try to play music on it. This is now a runtime option, so this isn't
 
94
   a critical choice anymore. */
 
95
#define DEFAULT_DRUMCHANNELS (1<<9)
 
96
/*#define DEFAULT_DRUMCHANNELS ((1<<9) | (1<<15))*/
 
97
 
 
98
/* type of floating point number */
 
99
typedef double FLOAT_T;
 
100
/* typedef float FLOAT_T; */
 
101
 
 
102
/* A somewhat arbitrary frequency range. The low end of this will
 
103
   sound terrible as no lowpass filtering is performed on most
 
104
   instruments before resampling. */
 
105
#define MIN_OUTPUT_RATE         4000
 
106
#define MAX_OUTPUT_RATE         65000
 
107
 
 
108
/* In percent. */
 
109
#ifndef DEFAULT_AMPLIFICATION
 
110
#define DEFAULT_AMPLIFICATION   70
 
111
#endif
 
112
 
 
113
/* Default sampling rate, default polyphony, and maximum polyphony.
 
114
   All but the last can be overridden from the command line. */
 
115
#ifndef DEFAULT_RATE
 
116
/*#define DEFAULT_RATE  32000*/
 
117
#define DEFAULT_RATE    44100
 
118
#endif
 
119
 
 
120
#ifndef DEFAULT_VOICES
 
121
#ifdef ADAGIO
 
122
#define DEFAULT_VOICES  DEFAULT_DSPVOICES
 
123
#else
 
124
#define DEFAULT_VOICES  64
 
125
#endif
 
126
#endif
 
127
 
 
128
#ifndef MAX_VOICES
 
129
#ifdef ADAGIO
 
130
/* Should check this.  MAX_DSPVOICES should be the
 
131
   number of Timidity "channels", but the maximum number
 
132
   of polyphonic voices playing simultaneously should be
 
133
   larger.  Now the two maxima are treated the same.
 
134
*/
 
135
#define MAX_VOICES      MAX_DSPVOICES
 
136
#else
 
137
#define MAX_VOICES      128
 
138
#endif
 
139
#endif
 
140
 
 
141
/* The size of the internal buffer is 2^AUDIO_BUFFER_BITS samples.
 
142
   This determines maximum number of samples ever computed in a row.
 
143
 
 
144
   For Linux, FreeBSD and BSD/OS users:
 
145
   
 
146
   This also specifies the size of the buffer fragment.  A smaller
 
147
   fragment gives a faster response in interactive mode -- 10 or 11 is
 
148
   probably a good number. Unfortunately some sound cards emit a click
 
149
   when switching DMA buffers. If this happens to you, try increasing
 
150
   this number to reduce the frequency of the clicks.
 
151
 
 
152
   For other systems:
 
153
   
 
154
   You should probably use a larger number for improved performance.
 
155
 
 
156
*/
 
157
#ifdef __WIN32__
 
158
#define AUDIO_BUFFER_BITS 12
 
159
#else
 
160
/** #define AUDIO_BUFFER_BITS 11 **/
 
161
#define AUDIO_BUFFER_BITS 10
 
162
#endif
 
163
 
 
164
/* 1000 here will give a control ratio of 22:1 with 22 kHz output.
 
165
   Higher CONTROLS_PER_SECOND values allow more accurate rendering
 
166
   of envelopes and tremolo. The cost is CPU time. */
 
167
/*#define CONTROLS_PER_SECOND 1000*/
 
168
#define CONTROLS_PER_SECOND 2000
 
169
 
 
170
/* Make envelopes twice as fast. Saves ~20% CPU time (notes decay
 
171
   faster) and sounds more like a GUS. There is now a command line
 
172
   option to toggle this as well. */
 
173
/*#define FAST_DECAY*/
 
174
 
 
175
/* How many bits to use for the fractional part of sample positions.
 
176
   This affects tonal accuracy. The entire position counter must fit
 
177
   in 32 bits, so with FRACTION_BITS equal to 12, the maximum size of
 
178
   a sample is 1048576 samples (2 megabytes in memory). The GUS gets
 
179
   by with just 9 bits and a little help from its friends...
 
180
   "The GUS does not SUCK!!!" -- a happy user :) */
 
181
/* #define FRACTION_BITS 12 */
 
182
#define FRACTION_BITS 13
 
183
 
 
184
/* For some reason the sample volume is always set to maximum in all
 
185
   patch files. Define this for a crude adjustment that may help
 
186
   equalize instrument volumes. */
 
187
#define ADJUST_SAMPLE_VOLUMES
 
188
 
 
189
/* If you have root access, you can define DANGEROUS_RENICE and chmod
 
190
   timidity setuid root to have it automatically raise its priority
 
191
   when run -- this may make it possible to play MIDI files in the
 
192
   background while running other CPU-intensive jobs. Of course no
 
193
   amount of renicing will help if the CPU time simply isn't there.
 
194
 
 
195
   The root privileges are used and dropped at the beginning of main()
 
196
   in timidity.c -- please check the code to your satisfaction before
 
197
   using this option. (And please check sections 11 and 12 in the
 
198
   GNU General Public License (under GNU Emacs, hit ^H^W) ;) */
 
199
/* #define DANGEROUS_RENICE -15 */
 
200
 
 
201
/* The number of samples to use for ramping out a dying note. Affects
 
202
   click removal. */
 
203
#define MAX_DIE_TIME 20
 
204
 
 
205
/* On some machines (especially PCs without math coprocessors),
 
206
   looking up sine values in a table will be significantly faster than
 
207
   computing them on the fly. Uncomment this to use lookups. */
 
208
/* #define LOOKUP_SINE */
 
209
 
 
210
/* If calling ldexp() is faster than a floating point multiplication
 
211
   on your machine/compiler/libm, uncomment this. It doesn't make much
 
212
   difference either way, but hey -- it was on the TODO list, so it
 
213
   got done. */
 
214
/* #define USE_LDEXP */
 
215
 
 
216
/**************************************************************************/
 
217
/* Anything below this shouldn't need to be changed unless you're porting
 
218
   to a new machine with other than 32-bit, big-endian words. */
 
219
/**************************************************************************/
 
220
 
 
221
/* change FRACTION_BITS above, not these */
 
222
#define INTEGER_BITS (32 - FRACTION_BITS)
 
223
#define INTEGER_MASK (0xFFFFFFFF << FRACTION_BITS)
 
224
#define FRACTION_MASK (~ INTEGER_MASK)
 
225
 
 
226
/* This is enforced by some computations that must fit in an int */
 
227
#define MAX_CONTROL_RATIO 255
 
228
 
 
229
/* Audio buffer size has to be a power of two to allow DMA buffer
 
230
   fragments under the VoxWare (Linux & FreeBSD & BSD/OS) audio driver */
 
231
#define AUDIO_BUFFER_SIZE (1<<AUDIO_BUFFER_BITS)
 
232
#define BB_SIZE (AUDIO_BUFFER_SIZE*512)
 
233
 
 
234
#if SIZEOF_LONG == 4
 
235
        typedef unsigned long uint32;
 
236
        typedef long int32; 
 
237
#elif SIZEOF_LONG == 8
 
238
        typedef unsigned int uint32;
 
239
        typedef int int32; 
 
240
#else
 
241
        #error "We don't know where to find a 32 of our bits!!"
 
242
#endif
 
243
typedef unsigned short uint16;
 
244
typedef short int16;
 
245
typedef unsigned char uint8;
 
246
typedef char int8;
 
247
 
 
248
/* Instrument files are little-endian, MIDI files big-endian, so we
 
249
   need to do some conversions. */
 
250
 
 
251
#ifdef WORDS_BIGENDIAN
 
252
        #define MIDI_BIG_ENDIAN
 
253
#else
 
254
        #define MIDI_LITTLE_ENDIAN
 
255
#endif
 
256
 
 
257
#ifdef __FreeBSD__
 
258
        #include <osreldate.h>
 
259
        #include <machine/endian.h>
 
260
        /* The macros have changed recently */
 
261
        /* And a better idea would be to attempt the various asm 
 
262
        optimizations ourselves IMO, but hey, this is free */
 
263
        #if __FreeBSD_version <= 500000
 
264
                #define XCHG_SHORT(x) __byte_swap_word(x)
 
265
                #define XCHG_LONG(x) __byte_swap_long(x)
 
266
        #else
 
267
                #define XCHG_SHORT(x) __uint8_swap_uint16(x)
 
268
                #define XCHG_LONG(x) __uint8_swap_uint32(x)
 
269
        #endif
 
270
#else
 
271
        #define XCHG_SHORT(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
 
272
        #ifdef __i486__
 
273
                #define XCHG_LONG(x) \
 
274
                        ({ int32 __value; \
 
275
                        asm ("bswap %1; movl %1,%0" : "=g" (__value) : "r" (x)); \
 
276
                        __value; })
 
277
        #else
 
278
                #define XCHG_LONG(x) ((((x)&0xFF)<<24) | \
 
279
                        (((x)&0xFF00)<<8) | \
 
280
                        (((x)&0xFF0000)>>8) | \
 
281
                        (((x)>>24)&0xFF))
 
282
        #endif
 
283
#endif
 
284
 
 
285
#ifdef MIDI_LITTLE_ENDIAN
 
286
        #define LE_SHORT(x) x
 
287
        #define LE_LONG(x) x
 
288
        #define BE_SHORT(x) XCHG_SHORT(x)
 
289
        #define BE_LONG(x) XCHG_LONG(x)
 
290
#else /* MIDI_BIG_ENDIAN */
 
291
        #define LE_SHORT(x) XCHG_SHORT(x)
 
292
        #define LE_LONG(x) XCHG_LONG(x)
 
293
        #define BE_SHORT(x) x
 
294
        #define BE_LONG(x) x
 
295
#endif
 
296
 
 
297
#define MAX_AMPLIFICATION 800
 
298
 
 
299
/* You could specify a complete path, e.g. "/etc/timidity.cfg", and
 
300
   then specify the library directory in the configuration file. */
 
301
#ifdef ADAGIO
 
302
#define CONFIG_FILE     TIMID_DIR "/timidity.cfg"
 
303
#else
 
304
#ifndef CONFIG_FILE
 
305
#define CONFIG_FILE DEFAULT_PATH "/timidity.cfg"
 
306
#endif
 
307
#endif
 
308
 
 
309
/* These affect general volume */
 
310
#define GUARD_BITS 3
 
311
#define AMP_BITS (15-GUARD_BITS)
 
312
 
 
313
#ifdef LOOKUP_HACK
 
314
   typedef int8 sample_t;
 
315
   typedef uint8 final_volume_t;
 
316
#  define FINAL_VOLUME(v) (~_l2u[v])
 
317
#  define MIXUP_SHIFT 5
 
318
#  define MAX_AMP_VALUE 4095
 
319
#else
 
320
   typedef int16 sample_t;
 
321
   typedef int32 final_volume_t;
 
322
#  define FINAL_VOLUME(v) (v)
 
323
#  define MAX_AMP_VALUE ((1<<(AMP_BITS+1))-1)
 
324
#endif
 
325
 
 
326
#ifdef tplus
 
327
/* #define MIN_AMP_VALUE (MAX_AMP_VALUE >> 9) */
 
328
#define MIN_AMP_VALUE (MAX_AMP_VALUE >> 10)
 
329
#endif
 
330
 
 
331
#ifdef USE_LDEXP
 
332
#  define FRSCALE(a,b) ldexp((double)(a),(b))
 
333
#  define FRSCALENEG(a,b) ldexp((double)(a),-(b))
 
334
#else
 
335
#  define FRSCALE(a,b) ((a) * (double)(1<<(b)))
 
336
#  define FRSCALENEG(a,b) ((a) * (1.0L / (double)(1<<(b))))
 
337
#endif
 
338
 
 
339
/* Vibrato and tremolo Choices of the Day */
 
340
#define SWEEP_TUNING 38
 
341
#define VIBRATO_AMPLITUDE_TUNING 1.0L
 
342
#define VIBRATO_RATE_TUNING 38
 
343
#define TREMOLO_AMPLITUDE_TUNING 1.0L
 
344
#define TREMOLO_RATE_TUNING 38
 
345
 
 
346
#define SWEEP_SHIFT 16
 
347
#define RATE_SHIFT 5
 
348
 
 
349
#define VIBRATO_SAMPLE_INCREMENTS 32
 
350
 
 
351
 
 
352
#ifdef tplus
 
353
#define MODULATION_WHEEL_RATE (1.0/6.0)
 
354
#define VIBRATO_DEPTH_TUNING (1.0/4.0)
 
355
#endif
 
356
 
 
357
#if defined(hpux) || defined(__hpux)
 
358
  extern char *sys_errlist[];
 
359
  #define PI 3.14159265358979323846
 
360
#endif
 
361
 
 
362
#ifdef sun
 
363
  #ifdef HAVE_SYS_STDTYPES_H
 
364
    #include <sys/stdtypes.h>
 
365
  #endif
 
366
  #include <errno.h>
 
367
  extern char *sys_errlist[];
 
368
  extern int opterr;
 
369
  extern int optind;
 
370
  extern int optopt;
 
371
  extern char *optarg;
 
372
  #define PI 3.14159265358979323846
 
373
  #define rindex(s,c) strrchr(s,c)
 
374
#endif
 
375
 
 
376
#ifdef _UNIXWARE
 
377
extern char *sys_errlist[];
 
378
#include <values.h>
 
379
#define PI M_PI
 
380
#include <sys/filio.h>
 
381
#endif
 
382
 
 
383
#ifdef __WIN32__
 
384
#  include <math.h>
 
385
#  define PI M_PI
 
386
#  undef DECOMPRESSOR_LIST
 
387
#  undef PATCH_EXT_LIST
 
388
#  define PATCH_EXT_LIST { ".pat", 0 }
 
389
#endif
 
390
 
 
391
/* The path separator (D.M.) */
 
392
#ifdef __WIN32__
 
393
#  define PATH_SEP '\\'
 
394
#  define PATH_STRING "\\"
 
395
#else
 
396
#  define PATH_SEP '/'
 
397
#  define PATH_STRING "/"
 
398
#endif
 
399
 
 
400
#ifdef __osf__
 
401
  #include <errno.h>
 
402
  #define PI 3.14159265358979323846
 
403
#endif
 
404
 
 
405
#if defined (__FreeBSD__) || defined(__bsdi__) 
 
406
#include <math.h>
 
407
#ifndef PI
 
408
#define PI M_PI
 
409
#endif
 
410
#endif
 
411
 
 
412
#ifdef _SCO_DS
 
413
#include <math.h>
 
414
#ifndef PI
 
415
#define PI M_PI
 
416
#endif
 
417
#endif