2 * gus_vol.c - Compute volume for GUS.
6 #include <i386/isa/sound/sound_config.h>
9 #include <i386/isa/sound/gus_linearvol.h>
11 #define GUS_VOLUME gus_wave_volume
14 extern int gus_wave_volume;
15 unsigned short gus_adagio_vol(int vel, int mainv, int xpn, int voicev);
16 unsigned short gus_linear_vol(int vol, int mainvol);
19 * Calculate gus volume from note velocity, main volume, expression, and
20 * intrinsic patch volume given in patch library. Expression is multiplied
21 * in, so it emphasizes differences in note velocity, while main volume is
22 * added in -- I don't know whether this is right, but it seems reasonable to
23 * me. (In the previous stage, main volume controller messages were changed
24 * to expression controller messages, if they were found to be used for
25 * dynamic volume adjustments, so here, main volume can be assumed to be
26 * constant throughout a song.)
28 * Intrinsic patch volume is added in, but if over 64 is also multiplied in, so
29 * we can give a big boost to very weak voices like nylon guitar and the
30 * basses. The normal value is 64. Strings are assigned lower values.
33 gus_adagio_vol(int vel, int mainv, int xpn, int voicev)
38 * A voice volume of 64 is considered neutral, so adjust the main
39 * volume if something other than this neutral value was assigned in
42 x = 256 + 6 * (voicev - 64);
45 * Boost expression by voice volume above neutral.
49 xpn += (voicev - 64) / 2;
52 * Combine multiplicative and level components.
54 x = vel * xpn * 6 + (voicev / 4) * x;
58 * Further adjustment by installation-specific master volume control
61 x = (x * GUS_VOLUME * GUS_VOLUME) / 10000;
64 #ifdef GUS_USE_CHN_MAIN_VOLUME
66 * Experimental support for the channel main volume
69 mainv = (mainv / 2) + 64; /* Scale to 64 to 127 */
70 x = (x * mainv * mainv) / 16384;
76 return ((15 << 8) | 255);
79 * Convert to gus's logarithmic form with 4 bit exponent i and 8 bit
85 while (i > 0 && n < (1 << i))
93 * Mantissa is part of linear volume not expressed in exponent.
94 * (This is not quite like real logs -- I wonder if it's right.)
99 * Adjust mantissa to 8 bits.
107 return ((i << 8) + m);
111 * Volume-values are interpreted as linear values. Volume is based on the
112 * value supplied with SEQ_START_NOTE(), channel main volume (if compiled in)
113 * and the volume set by the mixer-device (default 60%).
117 gus_linear_vol(int vol, int mainvol)
121 RANGE (vol, 0, 127) ;
124 mixer_mainvol = GUS_VOLUME;
129 #ifdef GUS_USE_CHN_MAIN_VOLUME
130 RANGE (mainvol, 0, 127);
135 return gus_linearvol[(((vol * mainvol) / 127) * mixer_mainvol) / 100];