src/fluid_gen.c

00001 /* FluidSynth - A Software Synthesizer
00002  *
00003  * Copyright (C) 2003  Peter Hanappe and others.
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public License
00007  * as published by the Free Software Foundation; either version 2 of
00008  * the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public
00016  * License along with this library; if not, write to the Free
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018  * 02111-1307, USA
00019  */
00020 
00021 
00022 #include "fluid_gen.h"
00023 #include "fluid_chan.h"
00024 
00025 
00026 /* See SFSpec21 $8.1.3 */
00027 fluid_gen_info_t fluid_gen_info[] = {
00028         /* number/name             init  scale         min        max         def */
00029         { GEN_STARTADDROFS,           1,     1,       0.0f,     1e10f,       0.0f },
00030         { GEN_ENDADDROFS,             1,     1,     -1e10f,      0.0f,       0.0f },
00031         { GEN_STARTLOOPADDROFS,       1,     1,     -1e10f,     1e10f,       0.0f },
00032         { GEN_ENDLOOPADDROFS,         1,     1,     -1e10f,     1e10f,       0.0f },
00033         { GEN_STARTADDRCOARSEOFS,     0,     1,       0.0f,     1e10f,       0.0f },
00034         { GEN_MODLFOTOPITCH,          1,     2,  -12000.0f,  12000.0f,       0.0f },
00035         { GEN_VIBLFOTOPITCH,          1,     2,  -12000.0f,  12000.0f,       0.0f },
00036         { GEN_MODENVTOPITCH,          1,     2,  -12000.0f,  12000.0f,       0.0f },
00037         { GEN_FILTERFC,               1,     2,    1500.0f,  13500.0f,   13500.0f },
00038         { GEN_FILTERQ,                1,     1,       0.0f,    960.0f,       0.0f },
00039         { GEN_MODLFOTOFILTERFC,       1,     2,  -12000.0f,  12000.0f,       0.0f },
00040         { GEN_MODENVTOFILTERFC,       1,     2,  -12000.0f,  12000.0f,       0.0f },
00041         { GEN_ENDADDRCOARSEOFS,       0,     1,     -1e10f,      0.0f,       0.0f },
00042         { GEN_MODLFOTOVOL,            1,     1,    -960.0f,    960.0f,       0.0f },
00043         { GEN_UNUSED1,                0,     0,       0.0f,      0.0f,       0.0f },
00044         { GEN_CHORUSSEND,             1,     1,       0.0f,   1000.0f,       0.0f },
00045         { GEN_REVERBSEND,             1,     1,       0.0f,   1000.0f,       0.0f },
00046         { GEN_PAN,                    1,     1,    -500.0f,    500.0f,       0.0f },
00047         { GEN_UNUSED2,                0,     0,       0.0f,      0.0f,       0.0f },
00048         { GEN_UNUSED3,                0,     0,       0.0f,      0.0f,       0.0f },
00049         { GEN_UNUSED4,                0,     0,       0.0f,      0.0f,       0.0f },
00050         { GEN_MODLFODELAY,            1,     2,  -12000.0f,   5000.0f,  -12000.0f },
00051         { GEN_MODLFOFREQ,             1,     4,  -16000.0f,   4500.0f,       0.0f },
00052         { GEN_VIBLFODELAY,            1,     2,  -12000.0f,   5000.0f,  -12000.0f },
00053         { GEN_VIBLFOFREQ,             1,     4,  -16000.0f,   4500.0f,       0.0f },
00054         { GEN_MODENVDELAY,            1,     2,  -12000.0f,   5000.0f,  -12000.0f },
00055         { GEN_MODENVATTACK,           1,     2,  -12000.0f,   8000.0f,  -12000.0f },
00056         { GEN_MODENVHOLD,             1,     2,  -12000.0f,   5000.0f,  -12000.0f },
00057         { GEN_MODENVDECAY,            1,     2,  -12000.0f,   8000.0f,  -12000.0f },
00058         { GEN_MODENVSUSTAIN,          0,     1,       0.0f,   1000.0f,       0.0f },
00059         { GEN_MODENVRELEASE,          1,     2,  -12000.0f,   8000.0f,  -12000.0f },
00060         { GEN_KEYTOMODENVHOLD,        0,     1,   -1200.0f,   1200.0f,       0.0f },
00061         { GEN_KEYTOMODENVDECAY,       0,     1,   -1200.0f,   1200.0f,       0.0f },
00062         { GEN_VOLENVDELAY,            1,     2,  -12000.0f,   5000.0f,  -12000.0f },
00063         { GEN_VOLENVATTACK,           1,     2,  -12000.0f,   8000.0f,  -12000.0f },
00064         { GEN_VOLENVHOLD,             1,     2,  -12000.0f,   5000.0f,  -12000.0f },
00065         { GEN_VOLENVDECAY,            1,     2,  -12000.0f,   8000.0f,  -12000.0f },
00066         { GEN_VOLENVSUSTAIN,          0,     1,       0.0f,   1440.0f,       0.0f },
00067         { GEN_VOLENVRELEASE,          1,     2,  -12000.0f,   8000.0f,  -12000.0f },
00068         { GEN_KEYTOVOLENVHOLD,        0,     1,   -1200.0f,   1200.0f,       0.0f },
00069         { GEN_KEYTOVOLENVDECAY,       0,     1,   -1200.0f,   1200.0f,       0.0f },
00070         { GEN_INSTRUMENT,             0,     0,       0.0f,      0.0f,       0.0f },
00071         { GEN_RESERVED1,              0,     0,       0.0f,      0.0f,       0.0f },
00072         { GEN_KEYRANGE,               0,     0,       0.0f,    127.0f,       0.0f },
00073         { GEN_VELRANGE,               0,     0,       0.0f,    127.0f,       0.0f },
00074         { GEN_STARTLOOPADDRCOARSEOFS, 0,     1,     -1e10f,     1e10f,       0.0f },
00075         { GEN_KEYNUM,                 1,     0,       0.0f,    127.0f,      -1.0f },
00076         { GEN_VELOCITY,               1,     1,       0.0f,    127.0f,      -1.0f },
00077         { GEN_ATTENUATION,            1,     1,       0.0f,   1440.0f,       0.0f },
00078         { GEN_RESERVED2,              0,     0,       0.0f,      0.0f,       0.0f },
00079         { GEN_ENDLOOPADDRCOARSEOFS,   0,     1,     -1e10f,     1e10f,       0.0f },
00080         { GEN_COARSETUNE,             0,     1,    -120.0f,    120.0f,       0.0f },
00081         { GEN_FINETUNE,               0,     1,     -99.0f,     99.0f,       0.0f },
00082         { GEN_SAMPLEID,               0,     0,       0.0f,      0.0f,       0.0f },
00083         { GEN_SAMPLEMODE,             0,     0,       0.0f,      0.0f,       0.0f },
00084         { GEN_RESERVED3,              0,     0,       0.0f,      0.0f,       0.0f },
00085         { GEN_SCALETUNE,              0,     1,       0.0f,   1200.0f,     100.0f },
00086         { GEN_EXCLUSIVECLASS,         0,     0,       0.0f,      0.0f,       0.0f },
00087         { GEN_OVERRIDEROOTKEY,        1,     0,       0.0f,    127.0f,      -1.0f },
00088         { GEN_PITCH,                  1,     0,       0.0f,    127.0f,       0.0f }
00089 };
00090 
00091 
00097 int
00098 fluid_gen_set_default_values(fluid_gen_t* gen)
00099 {
00100         int i;
00101 
00102         for (i = 0; i < GEN_LAST; i++) {
00103                 gen[i].flags = GEN_UNUSED;
00104                 gen[i].mod = 0.0;
00105                 gen[i].nrpn = 0.0;
00106                 gen[i].val = fluid_gen_info[i].def;
00107         }
00108 
00109         return FLUID_OK;
00110 }
00111 
00112 
00113 /* fluid_gen_init
00114  *
00115  * Set an array of generators to their initial value
00116  */
00117 int
00118 fluid_gen_init(fluid_gen_t* gen, fluid_channel_t* channel)
00119 {
00120         int i;
00121 
00122         fluid_gen_set_default_values(gen);
00123 
00124         for (i = 0; i < GEN_LAST; i++) {
00125                 gen[i].nrpn = fluid_channel_get_gen(channel, i);
00126 
00127                 /* This is an extension to the SoundFont standard. More
00128                  * documentation is available at the fluid_synth_set_gen2()
00129                  * function. */
00130                 if (fluid_channel_get_gen_abs(channel, i)) {
00131                         gen[i].flags = GEN_ABS_NRPN;
00132                 }
00133         }
00134 
00135         return FLUID_OK;
00136 }
00137 
00138 fluid_real_t fluid_gen_scale(int gen, float value)
00139 {
00140         return (fluid_gen_info[gen].min
00141                 + value * (fluid_gen_info[gen].max - fluid_gen_info[gen].min));
00142 }
00143 
00144 fluid_real_t fluid_gen_scale_nrpn(int gen, int data)
00145 {
00146         fluid_real_t value = (float) data - 8192.0f;
00147         fluid_clip(value, -8192, 8192);
00148         return value * (float) fluid_gen_info[gen].nrpn_scale;
00149 }

Generated on Sat Nov 17 13:40:23 2007 for libfluidsynth by  doxygen 1.5.3