2 * gus_vol.c - Compute volume for GUS.
6 * $DragonFly: src/sys/dev/sound/isa/i386/gus/Attic/gus_vol.c,v 1.2 2003/08/07 21:17:12 dillon Exp $
8 #include <i386/isa/sound/sound_config.h>
11 #include "gus_linearvol.h"
13 #define GUS_VOLUME gus_wave_volume
16 extern int gus_wave_volume;
17 unsigned short gus_adagio_vol(int vel, int mainv, int xpn, int voicev);
18 unsigned short gus_linear_vol(int vol, int mainvol);
21 * Calculate gus volume from note velocity, main volume, expression, and
22 * intrinsic patch volume given in patch library. Expression is multiplied
23 * in, so it emphasizes differences in note velocity, while main volume is
24 * added in -- I don't know whether this is right, but it seems reasonable to
25 * me. (In the previous stage, main volume controller messages were changed
26 * to expression controller messages, if they were found to be used for
27 * dynamic volume adjustments, so here, main volume can be assumed to be
28 * constant throughout a song.)
30 * Intrinsic patch volume is added in, but if over 64 is also multiplied in, so
31 * we can give a big boost to very weak voices like nylon guitar and the
32 * basses. The normal value is 64. Strings are assigned lower values.
35 gus_adagio_vol(int vel, int mainv, int xpn, int voicev)
40 * A voice volume of 64 is considered neutral, so adjust the main
41 * volume if something other than this neutral value was assigned in
44 x = 256 + 6 * (voicev - 64);
47 * Boost expression by voice volume above neutral.
51 xpn += (voicev - 64) / 2;
54 * Combine multiplicative and level components.
56 x = vel * xpn * 6 + (voicev / 4) * x;
60 * Further adjustment by installation-specific master volume control
63 x = (x * GUS_VOLUME * GUS_VOLUME) / 10000;
66 #ifdef GUS_USE_CHN_MAIN_VOLUME
68 * Experimental support for the channel main volume
71 mainv = (mainv / 2) + 64; /* Scale to 64 to 127 */
72 x = (x * mainv * mainv) / 16384;
78 return ((15 << 8) | 255);
81 * Convert to gus's logarithmic form with 4 bit exponent i and 8 bit
87 while (i > 0 && n < (1 << i))
95 * Mantissa is part of linear volume not expressed in exponent.
96 * (This is not quite like real logs -- I wonder if it's right.)
101 * Adjust mantissa to 8 bits.
109 return ((i << 8) + m);
113 * Volume-values are interpreted as linear values. Volume is based on the
114 * value supplied with SEQ_START_NOTE(), channel main volume (if compiled in)
115 * and the volume set by the mixer-device (default 60%).
119 gus_linear_vol(int vol, int mainvol)
123 RANGE (vol, 0, 127) ;
126 mixer_mainvol = GUS_VOLUME;
131 #ifdef GUS_USE_CHN_MAIN_VOLUME
132 RANGE (mainvol, 0, 127);
137 return gus_linearvol[(((vol * mainvol) / 127) * mixer_mainvol) / 100];