1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
/*================================================================
* SBK --> SF2 Conversion
*
* Copyright (C) 1996-1999 Takashi Iwai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*================================================================*/
#include <stdio.h>
#include <math.h>
#include "sffile.h"
#include "sfitem.h"
#include "awe_parm.h"
/*----------------------------------------------------------------
* prototypes
*----------------------------------------------------------------*/
static int sbk_cutoff(int gen, int val);
static int sbk_filterQ(int gen, int val);
static int sbk_tenpct(int gen, int val);
static int sbk_panpos(int gen, int val);
static int sbk_atten(int gen, int val);
static int sbk_scale(int gen, int val);
static int sbk_time(int gen, int val);
static int sbk_tm_key(int gen, int val);
static int sbk_freq(int gen, int val);
static int sbk_pshift(int gen, int val);
static int sbk_cshift(int gen, int val);
static int sbk_tremolo(int gen, int val);
static int sbk_volsust(int gen, int val);
static int sbk_modsust(int gen, int val);
/*----------------------------------------------------------------
* convertor function table
*----------------------------------------------------------------*/
static SBKConv sbk_convertors[T_EOT] = {
NULL, NULL, NULL, NULL, NULL,
sbk_cutoff, sbk_filterQ, sbk_tenpct, sbk_panpos, sbk_atten, sbk_scale,
sbk_time, sbk_tm_key, sbk_freq, sbk_pshift, sbk_cshift,
sbk_tremolo, sbk_modsust, sbk_volsust,
};
/*----------------------------------------------------------------
* sbk --> sf2 conversion
*----------------------------------------------------------------*/
int sbk_to_sf2(int oper, int amount)
{
LayerItem *item = &layer_items[oper];
if (item->type < 0 || item->type >= T_EOT) {
fprintf(stderr, "illegal gen item type %d\n", item->type);
return amount;
}
if (sbk_convertors[item->type])
return sbk_convertors[item->type](oper, amount);
return amount;
}
/*----------------------------------------------------------------
* conversion rules for each type
*----------------------------------------------------------------*/
/* initial cutoff */
static int sbk_cutoff(int gen, int val)
{
if (val == 127)
return 14400;
else
return 59 * val + 4366;
/*return 50 * val + 4721;*/
}
/* initial resonance */
static int sbk_filterQ(int gen, int val)
{
return val * 3 / 2;
}
/* chorus/reverb */
static int sbk_tenpct(int gen, int val)
{
return val * 1000 / 256;
}
/* pan position */
static int sbk_panpos(int gen, int val)
{
return val * 1000 / 127 - 500;
}
/* initial attenuation */
static int sbk_atten(int gen, int val)
{
if (val == 0)
return 1000;
return (int)(-200.0 * log10((double)val / 127.0) * 10);
}
/* scale tuning */
static int sbk_scale(int gen, int val)
{
return (val ? 50 : 100);
}
/* env/lfo time parameter */
static int sbk_time(int gen, int val)
{
return awe_msec_to_timecent(val);
}
/* time change per key */
static int sbk_tm_key(int gen, int val)
{
return (int)(val * 5.55);
}
/* lfo frequency */
static int sbk_freq(int gen, int val)
{
if (val == 0) {
if (gen == SF_freqLfo1) return -725;
else /* SF_freqLfo2*/ return -15600;
}
/*return (int)(3986.0 * log10((double)val) - 7925.0);*/
return (int)(1200 * log10((double)val) / log10(2.0) - 7925.0);
}
/* lfo/env pitch shift */
static int sbk_pshift(int gen, int val)
{
return (1200 * val / 64 + 1) / 2;
}
/* lfo/env cutoff freq shift */
static int sbk_cshift(int gen, int val)
{
if (gen == SF_lfo1ToFilterFc)
return (1200 * 3 * val) / 64;
else
return (1200 * 6 * val) / 64;
}
/* lfo volume shift */
static int sbk_tremolo(int gen, int val)
{
return (120 * val) / 64;
}
/* mod env sustain */
static int sbk_modsust(int gen, int val)
{
if (val < 96)
return 1000 * (96 - val) / 96;
else
return 0;
}
/* vol env sustain */
static int sbk_volsust(int gen, int val)
{
if (val < 96)
return (2000 - 21 * val) / 2;
else
return 0;
}
|