2008-04-11 04:59:23 +00:00
|
|
|
/*
|
|
|
|
TiMidity -- Experimental MIDI to WAVE converter
|
|
|
|
Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TIMIDITY_H
|
|
|
|
#define TIMIDITY_H
|
|
|
|
|
|
|
|
#include "doomtype.h"
|
2015-12-29 19:38:08 +00:00
|
|
|
#include "pathexpander.h"
|
2008-04-11 04:59:23 +00:00
|
|
|
|
2008-04-12 21:36:10 +00:00
|
|
|
class FileReader;
|
|
|
|
|
2008-04-11 04:59:23 +00:00
|
|
|
namespace Timidity
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
config.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Acoustic Grand Piano seems to be the usual default instrument. */
|
2008-04-16 05:41:03 +00:00
|
|
|
#define DEFAULT_PROGRAM 0
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
/* 9 here is MIDI channel 10, which is the standard percussion channel.
|
|
|
|
Some files (notably C:\WINDOWS\CANYON.MID) think that 16 is one too.
|
|
|
|
On the other hand, some files know that 16 is not a drum channel and
|
|
|
|
try to play music on it. This is now a runtime option, so this isn't
|
|
|
|
a critical choice anymore. */
|
2008-04-16 05:41:03 +00:00
|
|
|
#define DEFAULT_DRUMCHANNELS (1<<9)
|
|
|
|
/*#define DEFAULT_DRUMCHANNELS ((1<<9) | (1<<15))*/
|
2008-04-11 04:59:23 +00:00
|
|
|
|
2008-04-16 05:41:03 +00:00
|
|
|
#define MAXCHAN 16
|
|
|
|
#define MAXNOTE 128
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
/* 1000 here will give a control ratio of 22:1 with 22 kHz output.
|
|
|
|
Higher CONTROLS_PER_SECOND values allow more accurate rendering
|
|
|
|
of envelopes and tremolo. The cost is CPU time. */
|
2008-04-16 05:41:03 +00:00
|
|
|
#define CONTROLS_PER_SECOND 1000
|
2008-04-11 04:59:23 +00:00
|
|
|
|
2008-04-19 05:57:09 +00:00
|
|
|
/* A scalar applied to the final mix to try and approximate the
|
|
|
|
volume level of FMOD's built-in MIDI player. */
|
2008-05-10 01:35:50 +00:00
|
|
|
#define FINAL_MIX_SCALE 0.5
|
|
|
|
|
2008-04-11 04:59:23 +00:00
|
|
|
/* How many bits to use for the fractional part of sample positions.
|
|
|
|
This affects tonal accuracy. The entire position counter must fit
|
|
|
|
in 32 bits, so with FRACTION_BITS equal to 12, the maximum size of
|
|
|
|
a sample is 1048576 samples (2 megabytes in memory). The GUS gets
|
|
|
|
by with just 9 bits and a little help from its friends...
|
|
|
|
"The GUS does not SUCK!!!" -- a happy user :) */
|
2008-04-16 05:41:03 +00:00
|
|
|
#define FRACTION_BITS 12
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
/* For some reason the sample volume is always set to maximum in all
|
|
|
|
patch files. Define this for a crude adjustment that may help
|
|
|
|
equalize instrument volumes. */
|
2008-04-19 21:36:53 +00:00
|
|
|
//#define ADJUST_SAMPLE_VOLUMES
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
/* The number of samples to use for ramping out a dying note. Affects
|
|
|
|
click removal. */
|
2008-04-16 05:41:03 +00:00
|
|
|
#define MAX_DIE_TIME 20
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Anything below this shouldn't need to be changed unless you're porting
|
|
|
|
to a new machine with other than 32-bit, big-endian words. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
/* change FRACTION_BITS above, not these */
|
2008-04-16 05:41:03 +00:00
|
|
|
#define INTEGER_BITS (32 - FRACTION_BITS)
|
|
|
|
#define INTEGER_MASK (0xFFFFFFFF << FRACTION_BITS)
|
|
|
|
#define FRACTION_MASK (~ INTEGER_MASK)
|
|
|
|
#define MAX_SAMPLE_SIZE (1 << INTEGER_BITS)
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
/* This is enforced by some computations that must fit in an int */
|
2008-04-16 05:41:03 +00:00
|
|
|
#define MAX_CONTROL_RATIO 255
|
2008-04-11 04:59:23 +00:00
|
|
|
|
2008-04-16 05:41:03 +00:00
|
|
|
#define MAX_AMPLIFICATION 800
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
/* The TiMiditiy configuration file */
|
|
|
|
#define CONFIG_FILE "timidity.cfg"
|
|
|
|
|
|
|
|
typedef float sample_t;
|
|
|
|
typedef float final_volume_t;
|
2008-04-16 05:41:03 +00:00
|
|
|
#define FINAL_VOLUME(v) (v)
|
2008-04-11 04:59:23 +00:00
|
|
|
|
2008-04-16 05:41:03 +00:00
|
|
|
#define FSCALE(a,b) ((a) * (float)(1<<(b)))
|
|
|
|
#define FSCALENEG(a,b) ((a) * (1.0L / (float)(1<<(b))))
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
/* Vibrato and tremolo Choices of the Day */
|
2008-04-16 05:41:03 +00:00
|
|
|
#define SWEEP_TUNING 38
|
|
|
|
#define VIBRATO_AMPLITUDE_TUNING 1.0
|
|
|
|
#define VIBRATO_RATE_TUNING 38
|
|
|
|
#define TREMOLO_AMPLITUDE_TUNING 1.0
|
|
|
|
#define TREMOLO_RATE_TUNING 38
|
2008-04-11 04:59:23 +00:00
|
|
|
|
2008-04-16 05:41:03 +00:00
|
|
|
#define SWEEP_SHIFT 16
|
|
|
|
#define RATE_SHIFT 5
|
2008-04-11 04:59:23 +00:00
|
|
|
|
2008-04-16 05:41:03 +00:00
|
|
|
#define VIBRATO_SAMPLE_INCREMENTS 32
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
#ifndef PI
|
|
|
|
#define PI 3.14159265358979323846
|
|
|
|
#endif
|
|
|
|
|
2012-04-23 02:46:25 +00:00
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && (defined(__i386__) || defined(__x86_64__))
|
2008-04-11 04:59:23 +00:00
|
|
|
// [RH] MinGW's pow() function is terribly slow compared to VC8's
|
|
|
|
// (I suppose because it's using an old version from MSVCRT.DLL).
|
|
|
|
// On an Opteron running x86-64 Linux, this also ended up being about
|
|
|
|
// 100 cycles faster than libm's pow(), which is why I'm using this
|
|
|
|
// for GCC in general and not just for MinGW.
|
2012-04-23 02:46:25 +00:00
|
|
|
// [CE] Clang doesn't yet support some inline ASM operations so I disabled it for that instance
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
extern __inline__ double pow_x87_inline(double x,double y)
|
|
|
|
{
|
|
|
|
double result;
|
|
|
|
|
|
|
|
if (y == 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (x == 0)
|
|
|
|
{
|
|
|
|
if (y > 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
union { double fp; long long ip; } infinity;
|
|
|
|
infinity.ip = 0x7FF0000000000000ll;
|
|
|
|
return infinity.fp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__asm__ (
|
|
|
|
"fyl2x\n\t"
|
|
|
|
"fld %%st(0)\n\t"
|
|
|
|
"frndint\n\t"
|
|
|
|
"fxch\n\t"
|
|
|
|
"fsub %%st(1),%%st(0)\n\t"
|
|
|
|
"f2xm1\n\t"
|
|
|
|
"fld1\n\t"
|
|
|
|
"faddp\n\t"
|
|
|
|
"fxch\n\t"
|
|
|
|
"fld1\n\t"
|
|
|
|
"fscale\n\t"
|
|
|
|
"fstp %%st(1)\n\t"
|
|
|
|
"fmulp\n\t"
|
|
|
|
: "=t" (result)
|
|
|
|
: "0" (x), "u" (y)
|
2010-01-23 20:48:24 +00:00
|
|
|
: "st(1)", "st(7)" );
|
2008-04-11 04:59:23 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#define pow pow_x87_inline
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
common.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern void *safe_malloc(size_t count);
|
|
|
|
|
|
|
|
/*
|
|
|
|
controls.h
|
|
|
|
*/
|
|
|
|
|
2008-04-16 05:41:03 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CMSG_INFO,
|
|
|
|
CMSG_WARNING,
|
|
|
|
CMSG_ERROR
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
VERB_NORMAL,
|
|
|
|
VERB_VERBOSE,
|
|
|
|
VERB_NOISY,
|
|
|
|
VERB_DEBUG
|
|
|
|
};
|
2008-04-11 04:59:23 +00:00
|
|
|
|
2008-04-12 05:04:37 +00:00
|
|
|
void cmsg(int type, int verbosity_level, const char *fmt, ...);
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
instrum.h
|
|
|
|
*/
|
|
|
|
|
2008-05-09 03:54:06 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PATCH_16 = (1<<0),
|
|
|
|
PATCH_UNSIGNED = (1<<1),
|
|
|
|
PATCH_LOOPEN = (1<<2),
|
|
|
|
PATCH_BIDIR = (1<<3),
|
|
|
|
PATCH_BACKWARD = (1<<4),
|
|
|
|
PATCH_SUSTAIN = (1<<5),
|
|
|
|
PATCH_NO_SRELEASE = (1<<6),
|
2008-05-10 01:35:50 +00:00
|
|
|
PATCH_FAST_REL = (1<<7),
|
2008-05-09 03:54:06 +00:00
|
|
|
};
|
|
|
|
|
2008-04-11 04:59:23 +00:00
|
|
|
struct Sample
|
|
|
|
{
|
|
|
|
SDWORD
|
|
|
|
loop_start, loop_end, data_length,
|
2008-05-09 03:54:06 +00:00
|
|
|
sample_rate;
|
|
|
|
float
|
|
|
|
low_freq, high_freq, root_freq;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
BYTE rate[6], offset[6];
|
|
|
|
} gf1;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
short delay_vol;
|
|
|
|
short attack_vol;
|
|
|
|
short hold_vol;
|
|
|
|
short decay_vol;
|
|
|
|
short sustain_vol;
|
|
|
|
short release_vol;
|
|
|
|
} sf2;
|
|
|
|
} envelope;
|
2008-04-11 04:59:23 +00:00
|
|
|
sample_t *data;
|
|
|
|
SDWORD
|
|
|
|
tremolo_sweep_increment, tremolo_phase_increment,
|
2008-04-16 05:41:03 +00:00
|
|
|
vibrato_sweep_increment, vibrato_control_ratio;
|
2008-04-11 04:59:23 +00:00
|
|
|
BYTE
|
|
|
|
tremolo_depth, vibrato_depth,
|
2008-05-09 03:54:06 +00:00
|
|
|
low_vel, high_vel,
|
2008-05-10 01:35:50 +00:00
|
|
|
type;
|
|
|
|
WORD
|
|
|
|
modes;
|
2008-05-09 03:54:06 +00:00
|
|
|
SWORD
|
|
|
|
panning;
|
2008-04-11 04:59:23 +00:00
|
|
|
WORD
|
2008-05-09 03:54:06 +00:00
|
|
|
scale_factor, key_group;
|
2008-04-11 04:59:23 +00:00
|
|
|
SWORD
|
2008-04-16 05:41:03 +00:00
|
|
|
scale_note;
|
|
|
|
bool
|
|
|
|
self_nonexclusive;
|
2008-04-19 05:57:09 +00:00
|
|
|
float
|
|
|
|
left_offset, right_offset;
|
2008-04-11 04:59:23 +00:00
|
|
|
|
2008-05-09 03:54:06 +00:00
|
|
|
// SF2 stuff
|
|
|
|
SWORD tune;
|
|
|
|
SBYTE velocity;
|
2008-04-11 04:59:23 +00:00
|
|
|
|
2008-05-09 03:54:06 +00:00
|
|
|
float initial_attenuation;
|
2008-04-11 04:59:23 +00:00
|
|
|
};
|
|
|
|
|
2008-05-09 03:54:06 +00:00
|
|
|
void convert_sample_data(Sample *sample, const void *data);
|
|
|
|
void free_instruments();
|
2008-04-16 05:41:03 +00:00
|
|
|
|
2008-05-09 03:54:06 +00:00
|
|
|
/* Magic file words */
|
|
|
|
|
|
|
|
#define ID_RIFF MAKE_ID('R','I','F','F')
|
|
|
|
#define ID_LIST MAKE_ID('L','I','S','T')
|
|
|
|
#define ID_INFO MAKE_ID('I','N','F','O')
|
|
|
|
#define ID_sfbk MAKE_ID('s','f','b','k')
|
|
|
|
#define ID_sdta MAKE_ID('s','d','t','a')
|
|
|
|
#define ID_pdta MAKE_ID('p','d','t','a')
|
|
|
|
#define ID_ifil MAKE_ID('i','f','i','l')
|
|
|
|
#define ID_iver MAKE_ID('i','v','e','r')
|
|
|
|
#define ID_irom MAKE_ID('i','r','o','m')
|
|
|
|
#define ID_smpl MAKE_ID('s','m','p','l')
|
|
|
|
#define ID_sm24 MAKE_ID('s','m','2','4')
|
|
|
|
#define ID_phdr MAKE_ID('p','h','d','r')
|
|
|
|
#define ID_pbag MAKE_ID('p','b','a','g')
|
|
|
|
#define ID_pmod MAKE_ID('p','m','o','d')
|
|
|
|
#define ID_pgen MAKE_ID('p','g','e','n')
|
|
|
|
#define ID_inst MAKE_ID('i','n','s','t')
|
|
|
|
#define ID_ibag MAKE_ID('i','b','a','g')
|
|
|
|
#define ID_imod MAKE_ID('i','m','o','d')
|
|
|
|
#define ID_igen MAKE_ID('i','g','e','n')
|
|
|
|
#define ID_shdr MAKE_ID('s','h','d','r')
|
|
|
|
|
|
|
|
/* Instrument definitions */
|
2008-04-16 05:41:03 +00:00
|
|
|
|
|
|
|
enum
|
2008-04-11 04:59:23 +00:00
|
|
|
{
|
2008-04-16 05:41:03 +00:00
|
|
|
INST_GUS,
|
2008-05-09 03:54:06 +00:00
|
|
|
INST_DLS,
|
|
|
|
INST_SF2
|
2008-04-11 04:59:23 +00:00
|
|
|
};
|
|
|
|
|
2008-04-16 05:41:03 +00:00
|
|
|
struct Instrument
|
|
|
|
{
|
|
|
|
Instrument();
|
|
|
|
~Instrument();
|
|
|
|
|
|
|
|
int samples;
|
|
|
|
Sample *sample;
|
|
|
|
};
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
struct ToneBankElement
|
|
|
|
{
|
2008-04-16 05:41:03 +00:00
|
|
|
ToneBankElement() :
|
2015-12-29 22:04:26 +00:00
|
|
|
note(0), pan(0), strip_loop(0), strip_envelope(0), strip_tail(0)
|
2008-04-11 04:59:23 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
FString name;
|
2015-12-29 22:04:26 +00:00
|
|
|
int note, pan, fontbank, fontpreset, fontnote;
|
|
|
|
SBYTE strip_loop, strip_envelope, strip_tail;
|
2008-04-11 04:59:23 +00:00
|
|
|
};
|
|
|
|
|
2008-05-09 03:54:06 +00:00
|
|
|
/* A hack to delay instrument loading until after reading the entire MIDI file. */
|
2008-04-16 05:41:03 +00:00
|
|
|
#define MAGIC_LOAD_INSTRUMENT ((Instrument *)(-1))
|
2008-04-11 04:59:23 +00:00
|
|
|
|
2008-04-16 05:41:03 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
MAXPROG = 128,
|
|
|
|
MAXBANK = 128
|
|
|
|
};
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
struct ToneBank
|
|
|
|
{
|
2008-04-16 05:41:03 +00:00
|
|
|
ToneBank();
|
|
|
|
~ToneBank();
|
|
|
|
|
|
|
|
ToneBankElement *tone;
|
|
|
|
Instrument *instrument[MAXPROG];
|
2008-04-11 04:59:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-04-16 05:41:03 +00:00
|
|
|
#define SPECIAL_PROGRAM -1
|
2008-04-11 04:59:23 +00:00
|
|
|
|
2008-05-09 03:54:06 +00:00
|
|
|
/*
|
|
|
|
instrum_font.cpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
class FontFile
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FontFile(FString filename);
|
|
|
|
virtual ~FontFile();
|
|
|
|
|
|
|
|
FString Filename;
|
|
|
|
FontFile *Next;
|
|
|
|
|
|
|
|
virtual Instrument *LoadInstrument(struct Renderer *song, int drum, int bank, int program) = 0;
|
|
|
|
virtual Instrument *LoadInstrumentOrder(struct Renderer *song, int order, int drum, int bank, int program) = 0;
|
|
|
|
virtual void SetOrder(int order, int drum, int bank, int program) = 0;
|
|
|
|
virtual void SetAllOrders(int order) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void font_freeall();
|
|
|
|
FontFile *font_find(const char *filename);
|
|
|
|
void font_add(const char *filename, int load_order);
|
|
|
|
void font_remove(const char *filename);
|
|
|
|
void font_order(int order, int bank, int preset, int keynote);
|
|
|
|
Instrument *load_instrument_font(struct Renderer *song, const char *font, int drum, int bank, int instrument);
|
|
|
|
Instrument *load_instrument_font_order(struct Renderer *song, int order, int drum, int bank, int instrument);
|
|
|
|
|
|
|
|
FontFile *ReadDLS(const char *filename, FileReader *f);
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
mix.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern void mix_voice(struct Renderer *song, float *buf, struct Voice *v, int c);
|
|
|
|
extern int recompute_envelope(struct Voice *v);
|
|
|
|
extern void apply_envelope_to_amp(struct Voice *v);
|
|
|
|
|
|
|
|
/*
|
|
|
|
playmidi.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Midi events */
|
2008-04-16 05:41:03 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ME_NOTEOFF = 0x80,
|
|
|
|
ME_NOTEON = 0x90,
|
|
|
|
ME_KEYPRESSURE = 0xA0,
|
|
|
|
ME_CONTROLCHANGE = 0xB0,
|
|
|
|
ME_PROGRAM = 0xC0,
|
|
|
|
ME_CHANNELPRESSURE = 0xD0,
|
|
|
|
ME_PITCHWHEEL = 0xE0
|
|
|
|
};
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
/* Controllers */
|
2008-04-16 05:41:03 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CTRL_BANK_SELECT = 0,
|
|
|
|
CTRL_DATA_ENTRY = 6,
|
|
|
|
CTRL_VOLUME = 7,
|
|
|
|
CTRL_PAN = 10,
|
|
|
|
CTRL_EXPRESSION = 11,
|
|
|
|
CTRL_SUSTAIN = 64,
|
|
|
|
CTRL_HARMONICCONTENT = 71,
|
|
|
|
CTRL_RELEASETIME = 72,
|
|
|
|
CTRL_ATTACKTIME = 73,
|
|
|
|
CTRL_BRIGHTNESS = 74,
|
|
|
|
CTRL_REVERBERATION = 91,
|
|
|
|
CTRL_CHORUSDEPTH = 93,
|
|
|
|
CTRL_NRPN_LSB = 98,
|
|
|
|
CTRL_NRPN_MSB = 99,
|
|
|
|
CTRL_RPN_LSB = 100,
|
|
|
|
CTRL_RPN_MSB = 101,
|
|
|
|
CTRL_ALL_SOUNDS_OFF = 120,
|
|
|
|
CTRL_RESET_CONTROLLERS = 121,
|
|
|
|
CTRL_ALL_NOTES_OFF = 123
|
|
|
|
};
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
/* RPNs */
|
2008-04-16 05:41:03 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
RPN_PITCH_SENS = 0x0000,
|
|
|
|
RPN_FINE_TUNING = 0x0001,
|
|
|
|
RPN_COARSE_TUNING = 0x0002,
|
|
|
|
RPN_RESET = 0x3fff
|
|
|
|
};
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
struct Channel
|
|
|
|
{
|
|
|
|
int
|
|
|
|
bank, program, sustain, pitchbend,
|
2008-04-24 04:18:49 +00:00
|
|
|
mono, /* one note only on this channel */
|
2008-04-11 04:59:23 +00:00
|
|
|
pitchsens;
|
2008-05-09 03:54:06 +00:00
|
|
|
BYTE
|
2008-04-11 04:59:23 +00:00
|
|
|
volume, expression;
|
2008-05-09 03:54:06 +00:00
|
|
|
SBYTE
|
2008-04-11 04:59:23 +00:00
|
|
|
panning;
|
|
|
|
WORD
|
|
|
|
rpn, nrpn;
|
|
|
|
bool
|
|
|
|
nrpn_mode;
|
|
|
|
float
|
|
|
|
pitchfactor; /* precomputed pitch bend factor to save some fdiv's */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Causes the instrument's default panning to be used. */
|
2008-04-16 05:41:03 +00:00
|
|
|
#define NO_PANNING -1
|
2008-04-11 04:59:23 +00:00
|
|
|
|
2008-05-09 03:54:06 +00:00
|
|
|
struct MinEnvelope
|
|
|
|
{
|
2016-01-13 23:25:24 +00:00
|
|
|
BYTE stage;
|
2008-05-09 03:54:06 +00:00
|
|
|
BYTE bUpdating;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GF1Envelope : public MinEnvelope
|
|
|
|
{
|
|
|
|
int volume, target, increment;
|
|
|
|
int rate[6], offset[6];
|
|
|
|
|
|
|
|
void Init(struct Renderer *song, Voice *v);
|
|
|
|
bool Update(struct Voice *v);
|
|
|
|
bool Recompute(struct Voice *v);
|
|
|
|
void ApplyToAmp(struct Voice *v);
|
|
|
|
void Release(struct Voice *v);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SF2Envelope : public MinEnvelope
|
|
|
|
{
|
|
|
|
float volume;
|
|
|
|
float DelayTime; // timecents
|
|
|
|
float AttackTime; // timecents
|
|
|
|
float HoldTime; // timecents
|
|
|
|
float DecayTime; // timecents
|
|
|
|
float SustainLevel; // -0.1%
|
|
|
|
float ReleaseTime; // timecents
|
|
|
|
float SampleRate;
|
|
|
|
int HoldStart;
|
|
|
|
float RateMul;
|
|
|
|
float RateMul_cB;
|
|
|
|
|
|
|
|
void Init(struct Renderer *song, Voice *v);
|
|
|
|
bool Update(struct Voice *v);
|
|
|
|
void ApplyToAmp(struct Voice *v);
|
|
|
|
void Release(struct Voice *v);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Envelope
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
MinEnvelope env;
|
|
|
|
GF1Envelope gf1;
|
|
|
|
SF2Envelope sf2;
|
|
|
|
};
|
|
|
|
|
|
|
|
BYTE Type;
|
|
|
|
|
|
|
|
void Init(struct Renderer *song, struct Voice *v);
|
|
|
|
bool Update(struct Voice *v)
|
|
|
|
{
|
|
|
|
if (Type == INST_GUS)
|
|
|
|
return gf1.Update(v);
|
|
|
|
return sf2.Update(v);
|
|
|
|
}
|
|
|
|
void ApplyToAmp(struct Voice *v)
|
|
|
|
{
|
|
|
|
if (Type == INST_GUS)
|
|
|
|
return gf1.ApplyToAmp(v);
|
|
|
|
return sf2.ApplyToAmp(v);
|
|
|
|
}
|
|
|
|
void Release(struct Voice *v)
|
|
|
|
{
|
|
|
|
if (Type == INST_GUS)
|
|
|
|
return gf1.Release(v);
|
|
|
|
return sf2.Release(v);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-04-11 04:59:23 +00:00
|
|
|
struct Voice
|
|
|
|
{
|
|
|
|
BYTE
|
2008-04-16 05:41:03 +00:00
|
|
|
status, channel, note, velocity;
|
2008-04-11 04:59:23 +00:00
|
|
|
Sample *sample;
|
|
|
|
float
|
|
|
|
orig_frequency, frequency;
|
|
|
|
int
|
2008-04-16 05:41:03 +00:00
|
|
|
sample_offset, sample_increment,
|
|
|
|
tremolo_sweep, tremolo_sweep_position,
|
|
|
|
tremolo_phase, tremolo_phase_increment,
|
|
|
|
vibrato_sweep, vibrato_sweep_position;
|
2008-04-11 04:59:23 +00:00
|
|
|
|
2008-05-09 03:54:06 +00:00
|
|
|
Envelope eg1, eg2;
|
|
|
|
|
2008-04-11 04:59:23 +00:00
|
|
|
final_volume_t left_mix, right_mix;
|
|
|
|
|
|
|
|
float
|
2008-04-19 05:57:09 +00:00
|
|
|
attenuation, left_offset, right_offset;
|
|
|
|
float
|
|
|
|
tremolo_volume;
|
2008-04-11 04:59:23 +00:00
|
|
|
int
|
|
|
|
vibrato_sample_increment[VIBRATO_SAMPLE_INCREMENTS];
|
|
|
|
int
|
|
|
|
vibrato_phase, vibrato_control_ratio, vibrato_control_counter,
|
2008-05-09 03:54:06 +00:00
|
|
|
control_counter;
|
2008-04-11 04:59:23 +00:00
|
|
|
|
2008-05-09 03:54:06 +00:00
|
|
|
int
|
|
|
|
sample_count;
|
2008-04-11 04:59:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Voice status options: */
|
2008-04-16 05:41:03 +00:00
|
|
|
enum
|
|
|
|
{
|
2008-04-24 04:18:49 +00:00
|
|
|
VOICE_RUNNING = (1<<0),
|
|
|
|
VOICE_SUSTAINING = (1<<1),
|
|
|
|
VOICE_RELEASING = (1<<2),
|
|
|
|
VOICE_STOPPING = (1<<3),
|
|
|
|
|
|
|
|
VOICE_LPE = (1<<4),
|
|
|
|
NOTE_SUSTAIN = (1<<5),
|
2008-04-16 05:41:03 +00:00
|
|
|
};
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
/* Envelope stages: */
|
2008-04-16 05:41:03 +00:00
|
|
|
enum
|
|
|
|
{
|
2008-05-09 03:54:06 +00:00
|
|
|
GF1_ATTACK,
|
|
|
|
GF1_HOLD,
|
|
|
|
GF1_DECAY,
|
|
|
|
GF1_RELEASE,
|
|
|
|
GF1_RELEASEB,
|
|
|
|
GF1_RELEASEC
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SF2_DELAY,
|
|
|
|
SF2_ATTACK,
|
|
|
|
SF2_HOLD,
|
|
|
|
SF2_DECAY,
|
|
|
|
SF2_SUSTAIN,
|
|
|
|
SF2_RELEASE,
|
|
|
|
SF2_FINISHED
|
2008-04-16 05:41:03 +00:00
|
|
|
};
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
#define ISDRUMCHANNEL(c) ((drumchannels & (1<<(c))))
|
|
|
|
|
|
|
|
/*
|
|
|
|
resample.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern sample_t *resample_voice(struct Renderer *song, Voice *v, int *countptr);
|
|
|
|
extern void pre_resample(struct Renderer *song, Sample *sp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
tables.h
|
|
|
|
*/
|
|
|
|
|
2008-05-09 03:54:06 +00:00
|
|
|
const double log_of_2 = 0.69314718055994529;
|
|
|
|
|
2008-04-11 04:59:23 +00:00
|
|
|
#define sine(x) (sin((2*PI/1024.0) * (x)))
|
2008-05-09 03:54:06 +00:00
|
|
|
|
2008-04-11 04:59:23 +00:00
|
|
|
#define note_to_freq(x) (float(8175.7989473096690661233836992789 * pow(2.0, (x) / 12.0)))
|
2008-05-09 03:54:06 +00:00
|
|
|
#define freq_to_note(x) (log((x) / 8175.7989473096690661233836992789) * (12.0 / log_of_2))
|
|
|
|
|
2008-04-19 05:57:09 +00:00
|
|
|
#define calc_gf1_amp(x) (pow(2.0,((x)*16.0 - 16.0))) // Actual GUS equation
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
timidity.h
|
|
|
|
*/
|
|
|
|
struct DLS_Data;
|
2008-04-12 21:36:10 +00:00
|
|
|
int LoadConfig(const char *filename);
|
2012-03-30 05:23:18 +00:00
|
|
|
int LoadDMXGUS();
|
2008-04-11 04:59:23 +00:00
|
|
|
extern int LoadConfig();
|
|
|
|
extern void FreeAll();
|
2015-12-29 19:38:08 +00:00
|
|
|
extern PathExpander pathExpander;
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
extern ToneBank *tonebank[MAXBANK];
|
|
|
|
extern ToneBank *drumset[MAXBANK];
|
|
|
|
|
|
|
|
struct Renderer
|
|
|
|
{
|
|
|
|
float rate;
|
|
|
|
DLS_Data *patches;
|
2008-04-16 05:41:03 +00:00
|
|
|
Instrument *default_instrument;
|
2008-04-11 04:59:23 +00:00
|
|
|
int default_program;
|
|
|
|
int resample_buffer_size;
|
|
|
|
sample_t *resample_buffer;
|
|
|
|
Channel channel[16];
|
2008-04-19 05:57:09 +00:00
|
|
|
Voice *voice;
|
2008-04-11 04:59:23 +00:00
|
|
|
int control_ratio, amp_with_poly;
|
|
|
|
int drumchannels;
|
|
|
|
int adjust_panning_immediately;
|
|
|
|
int voices;
|
|
|
|
int lost_notes, cut_notes;
|
|
|
|
|
2015-12-31 22:03:53 +00:00
|
|
|
Renderer(float sample_rate, const char *args);
|
2008-04-11 04:59:23 +00:00
|
|
|
~Renderer();
|
|
|
|
|
|
|
|
void HandleEvent(int status, int parm1, int parm2);
|
|
|
|
void HandleLongMessage(const BYTE *data, int len);
|
|
|
|
void HandleController(int chan, int ctrl, int val);
|
|
|
|
void ComputeOutput(float *buffer, int num_samples);
|
|
|
|
void MarkInstrument(int bank, int percussion, int instr);
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
int load_missing_instruments();
|
|
|
|
int set_default_instrument(const char *name);
|
|
|
|
int convert_tremolo_sweep(BYTE sweep);
|
|
|
|
int convert_vibrato_sweep(BYTE sweep, int vib_control_ratio);
|
|
|
|
int convert_tremolo_rate(BYTE rate);
|
|
|
|
int convert_vibrato_rate(BYTE rate);
|
|
|
|
|
2008-04-19 05:57:09 +00:00
|
|
|
void recompute_freq(int voice);
|
2008-04-11 04:59:23 +00:00
|
|
|
void recompute_amp(Voice *v);
|
2008-04-19 05:57:09 +00:00
|
|
|
void recompute_pan(Channel *chan);
|
|
|
|
|
2008-04-16 05:41:03 +00:00
|
|
|
void kill_key_group(int voice);
|
|
|
|
float calculate_scaled_frequency(Sample *sample, int note);
|
2008-05-09 03:54:06 +00:00
|
|
|
void start_note(int chan, int note, int vel);
|
|
|
|
bool start_region(int chan, int note, int vel, Sample *sp, float freq);
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
void note_on(int chan, int note, int vel);
|
|
|
|
void note_off(int chan, int note, int vel);
|
|
|
|
void all_notes_off(int chan);
|
|
|
|
void all_sounds_off(int chan);
|
|
|
|
void adjust_pressure(int chan, int note, int amount);
|
|
|
|
void adjust_panning(int chan);
|
|
|
|
void drop_sustain(int chan);
|
|
|
|
void adjust_pitchbend(int chan);
|
|
|
|
void adjust_volume(int chan);
|
|
|
|
|
|
|
|
void reset_voices();
|
|
|
|
void reset_controllers(int chan);
|
|
|
|
void reset_midi();
|
|
|
|
|
2008-05-09 03:54:06 +00:00
|
|
|
int allocate_voice();
|
2008-04-11 04:59:23 +00:00
|
|
|
|
|
|
|
void kill_note(int voice);
|
|
|
|
void finish_note(int voice);
|
|
|
|
|
|
|
|
void DataEntryCoarseRPN(int chan, int rpn, int val);
|
|
|
|
void DataEntryFineRPN(int chan, int rpn, int val);
|
|
|
|
void DataEntryCoarseNRPN(int chan, int nrpn, int val);
|
|
|
|
void DataEntryFineNRPN(int chan, int nrpn, int val);
|
2008-04-19 05:57:09 +00:00
|
|
|
|
2008-05-09 03:54:06 +00:00
|
|
|
static void compute_pan(double panning, int type, float &left_offset, float &right_offset);
|
2008-04-11 04:59:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|