timidity.h

Go to the documentation of this file.
00001 /*
00002 
00003     TiMidity -- Experimental MIDI to WAVE converter
00004     Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
00005 
00006          This program is free software; you can redistribute it and/or modify
00007          it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009          (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014          GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 
00020 */
00021 
00022 #ifdef USE_TIMIDITY_MIDI
00023 
00024 #ifndef TIMIDITY_H_INCLUDED
00025 #define TIMIDITY_H_INCLUDED
00026 
00027 #define NS_TIMIDITY Timidity_Pentagram
00028 
00029 #ifdef NS_TIMIDITY
00030 namespace NS_TIMIDITY {
00031 #endif
00032 
00033 struct MidiSong;
00034 
00035 //extern int Timidity_Init(int rate, int format, int channels, int samples);
00036 extern char *Timidity_Error(void);
00037 extern void Timidity_SetVolume(int volume);
00038 extern int Timidity_PlaySome(void *stream, int samples);
00039 extern MidiSong *Timidity_LoadSong(char *midifile);
00040 extern void Timidity_Start(MidiSong *song);
00041 extern int Timidity_Active(void);
00042 extern void Timidity_Stop(void);
00043 extern void Timidity_FreeSong(MidiSong *song);
00044 
00045 
00046 /* Data format encoding bits */
00047 
00048 #define PE_MONO         0x01  /* versus stereo */
00049 #define PE_SIGNED       0x02  /* versus unsigned */
00050 #define PE_16BIT        0x04  /* versus 8-bit */
00051 #define PE_ULAW         0x08  /* versus linear */
00052 #define PE_BYTESWAP     0x10  /* versus the other way */
00053 
00054 int Timidity_Init_Simple(int rate, int samples, sint32 encoding);
00055 void Timidity_DeInit();
00056 extern void Timidity_FinalInit(bool patches[128], bool drums[128]);
00057 extern void Timidity_PlayEvent(unsigned char status, int a, int b);
00058 extern void Timidity_GenerateSamples(void *stream, int samples);
00059 
00060 
00061 /* This is for use with the SDL library */
00062 #define SDL
00063 #if (defined(WIN32) || defined(_WIN32)) && !defined(__WIN32__)
00064 #define __WIN32__
00065 #endif
00066 
00067 
00068 /* When a patch file can't be opened, one of these extensions is
00069    appended to the filename and the open is tried again.
00070  */
00071 #define PATCH_EXT_LIST { ".pat", 0 }
00072 
00073 /* Acoustic Grand Piano seems to be the usual default instrument. */
00074 #define DEFAULT_PROGRAM 0
00075 
00076 /* 9 here is MIDI channel 10, which is the standard percussion channel.
00077    Some files (notably C:\WINDOWS\CANYON.MID) think that 16 is one too. 
00078    On the other hand, some files know that 16 is not a drum channel and
00079    try to play music on it. This is now a runtime option, so this isn't
00080    a critical choice anymore. */
00081 #define DEFAULT_DRUMCHANNELS (1<<9)
00082 
00083 /* A somewhat arbitrary frequency range. The low end of this will
00084    sound terrible as no lowpass filtering is performed on most
00085    instruments before resampling. */
00086 #define MIN_OUTPUT_RATE         4000
00087 #define MAX_OUTPUT_RATE         65000
00088 
00089 /* In percent. */
00090 #define DEFAULT_AMPLIFICATION   70
00091 
00092 /* Default sampling rate, default polyphony, and maximum polyphony.
00093    All but the last can be overridden from the command line. */
00094 #define DEFAULT_RATE    32000
00095 #define DEFAULT_VOICES  32
00096 #define MAX_VOICES      48
00097 
00098 /* 1000 here will give a control ratio of 22:1 with 22 kHz output.
00099    Higher CONTROLS_PER_SECOND values allow more accurate rendering
00100    of envelopes and tremolo. The cost is CPU time. */
00101 #define CONTROLS_PER_SECOND 1000
00102 
00103 /* Strongly recommended. This option increases CPU usage by half, but
00104    without it sound quality is very poor. */
00105 #define LINEAR_INTERPOLATION
00106 
00107 /* This is an experimental kludge that needs to be done right, but if
00108    you've got an 8-bit sound card, or cheap multimedia speakers hooked
00109    to your 16-bit output device, you should definitely give it a try.
00110 
00111    Defining LOOKUP_HACK causes table lookups to be used in mixing
00112    instead of multiplication. We convert the sample data to 8 bits at
00113    load time and volumes to logarithmic 7-bit values before looking up
00114    the product, which degrades sound quality noticeably.
00115 
00116    Defining LOOKUP_HACK should save ~20% of CPU on an Intel machine.
00117    LOOKUP_INTERPOLATION might give another ~5% */
00118 /* #define LOOKUP_HACK
00119    #define LOOKUP_INTERPOLATION */
00120 
00121 /* Make envelopes twice as fast. Saves ~20% CPU time (notes decay
00122    faster) and sounds more like a GUS. There is now a command line
00123    option to toggle this as well. */
00124 //#define FAST_DECAY
00125 
00126 /* How many bits to use for the fractional part of sample positions.
00127    This affects tonal accuracy. The entire position counter must fit
00128    in 32 bits, so with FRACTION_BITS equal to 12, the maximum size of
00129    a sample is 1048576 samples (2 megabytes in memory). The GUS gets
00130    by with just 9 bits and a little help from its friends...
00131    "The GUS does not SUCK!!!" -- a happy user :) */
00132 #define FRACTION_BITS 12
00133 
00134 /* For some reason the sample volume is always set to maximum in all
00135    patch files. Define this for a crude adjustment that may help
00136    equalize instrument volumes. */
00137 #define ADJUST_SAMPLE_VOLUMES
00138 
00139 /* The number of samples to use for ramping out a dying note. Affects
00140    click removal. */
00141 #define MAX_DIE_TIME 20
00142 
00143 /* On some machines (especially PCs without math coprocessors),
00144    looking up sine values in a table will be significantly faster than
00145    computing them on the fly. Uncomment this to use lookups. */
00146 /* #define LOOKUP_SINE */
00147 
00148 /* Shawn McHorse's resampling optimizations. These may not in fact be
00149    faster on your particular machine and compiler. You'll have to run
00150    a benchmark to find out. */
00151 #define PRECALC_LOOPS
00152 
00153 /* If calling ldexp() is faster than a floating point multiplication
00154    on your machine/compiler/libm, uncomment this. It doesn't make much
00155    difference either way, but hey -- it was on the TODO list, so it
00156    got done. */
00157 /* #define USE_LDEXP */
00158 
00159 /**************************************************************************/
00160 /* Anything below this shouldn't need to be changed unless you're porting
00161    to a new machine with other than 32-bit, big-endian words. */
00162 /**************************************************************************/
00163 
00164 /* change FRACTION_BITS above, not these */
00165 #define INTEGER_BITS (32 - FRACTION_BITS)
00166 #define INTEGER_MASK (0xFFFFFFFF << FRACTION_BITS)
00167 #define FRACTION_MASK (~ INTEGER_MASK)
00168 
00169 /* This is enforced by some computations that must fit in an int */
00170 #define MAX_CONTROL_RATIO 255
00171 
00172 /* Byte order, defined in <machine/endian.h> for FreeBSD and DEC OSF/1 */
00173 #ifdef DEC
00174 #include <machine/endian.h>
00175 #endif
00176 
00177 #ifdef linux
00178 /*
00179  * Byte order is defined in <bytesex.h> as __BYTE_ORDER, that need to
00180  * be checked against __LITTLE_ENDIAN and __BIG_ENDIAN defined in <endian.h>
00181  * <endian.h> includes automagically <bytesex.h>
00182  * for Linux.
00183  */
00184 #include <endian.h>
00185 
00186 /*
00187  * We undef the two things to start with a clean situation
00188  * (oddly enough, <endian.h> defines under certain conditions
00189  * the two things below, as __LITTLE_ENDIAN and __BIG_ENDIAN, that
00190  * are useless for our plans)
00191  */
00192 #undef LITTLE_ENDIAN
00193 #undef BIG_ENDIAN
00194 
00195 # if __BYTE_ORDER == __LITTLE_ENDIAN
00196 #  define LITTLE_ENDIAN
00197 # elif __BYTE_ORDER == __BIG_ENDIAN
00198 #  define BIG_ENDIAN
00199 # else
00200 # error No byte sex defined
00201 # endif
00202 #endif /* linux */
00203 
00204 /* Win32 on Intel machines */
00205 #ifdef __WIN32__
00206 #  define LITTLE_ENDIAN
00207 #endif
00208 
00209 #ifdef i386
00210 #define LITTLE_ENDIAN
00211 #endif
00212 
00213 /* Instrument files are little-endian, MIDI files big-endian, so we
00214    need to do some conversions. */
00215 
00216 #define XCHG_SHORT(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
00217 # define XCHG_LONG(x) ((((x)&0xFF)<<24) | \
00218                       (((x)&0xFF00)<<8) | \
00219                       (((x)&0xFF0000)>>8) | \
00220                       (((x)>>24)&0xFF))
00221 
00222 #ifdef LITTLE_ENDIAN
00223 #define LE_SHORT(x) x
00224 #define LE_LONG(x) x
00225 #define BE_SHORT(x) XCHG_SHORT(x)
00226 #define BE_LONG(x) XCHG_LONG(x)
00227 #else
00228 #define BE_SHORT(x) x
00229 #define BE_LONG(x) x
00230 #define LE_SHORT(x) XCHG_SHORT(x)
00231 #define LE_LONG(x) XCHG_LONG(x)
00232 #endif
00233 
00234 #define MAX_AMPLIFICATION 800
00235 
00236 /* You could specify a complete path, e.g. "/etc/timidity.cfg", and
00237    then specify the library directory in the configuration file. */
00238 #define CONFIG_FILE     "timidity.cfg"
00239 #ifndef DEFAULT_TIMIDITY_PATH
00240 #ifdef __WIN32__
00241 #define DEFAULT_TIMIDITY_PATH   "\\TIMIDITY"
00242 #else
00243 #define DEFAULT_TIMIDITY_PATH   "/usr/share/timidity"
00244 #endif
00245 #endif
00246 
00247 /* These affect general volume */
00248 #define GUARD_BITS 3
00249 #define AMP_BITS (15-GUARD_BITS)
00250 
00251 #ifdef LOOKUP_HACK
00252    typedef sint8 sample_t;
00253    typedef uint8 final_volume_t;
00254 #  define FINAL_VOLUME(v) (~_l2u[v])
00255 #  define MIXUP_SHIFT 5
00256 #  define MAX_AMP_VALUE 4095
00257 #else
00258    typedef sint16 sample_t;
00259    typedef sint32 final_volume_t;
00260 #  define FINAL_VOLUME(v) (v)
00261 #  define MAX_AMP_VALUE ((1<<(AMP_BITS+1))-1)
00262 #endif
00263 
00264 #ifdef USE_LDEXP
00265 #  define FSCALE(a,b) ldexp((a),(b))
00266 #  define FSCALENEG(a,b) ldexp((a),-(b))
00267 #else
00268 #  define FSCALE(a,b) (float)((a) * (double)(1<<(b)))
00269 #  define FSCALENEG(a,b) (float)((a) * (1.0L / (double)(1<<(b))))
00270 #endif
00271 
00272 /* Vibrato and tremolo Choices of the Day */
00273 #define SWEEP_TUNING 38
00274 #define VIBRATO_AMPLITUDE_TUNING 1.0L
00275 #define VIBRATO_RATE_TUNING 38
00276 #define TREMOLO_AMPLITUDE_TUNING 1.0L
00277 #define TREMOLO_RATE_TUNING 38
00278 
00279 #define SWEEP_SHIFT 16
00280 #define RATE_SHIFT 5
00281 
00282 #define VIBRATO_SAMPLE_INCREMENTS 32
00283 
00284 #ifndef PI
00285   #define PI 3.14159265358979323846
00286 #endif
00287 
00288 /* The path separator (D.M.) */
00289 #ifdef __WIN32__
00290 #  define PATH_SEP '\\'
00291 #  define PATH_STRING "\\"
00292 #else
00293 #  define PATH_SEP '/'
00294 #  define PATH_STRING "/"
00295 #endif
00296 
00297 #ifdef NS_TIMIDITY
00298 };
00299 #endif
00300 
00301 #endif
00302 
00303 #endif //USE_TIMIDITY_MIDI

Generated on Fri Jul 27 22:27:43 2007 for pentagram by  doxygen 1.4.7