aboutsummaryrefslogtreecommitdiff
path: root/sys/i386/isa/sound/gus_vol.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/i386/isa/sound/gus_vol.c')
-rw-r--r--sys/i386/isa/sound/gus_vol.c63
1 files changed, 49 insertions, 14 deletions
diff --git a/sys/i386/isa/sound/gus_vol.c b/sys/i386/isa/sound/gus_vol.c
index 6e56d546cea5..055a1170e9fb 100644
--- a/sys/i386/isa/sound/gus_vol.c
+++ b/sys/i386/isa/sound/gus_vol.c
@@ -1,17 +1,18 @@
-/*
+/*
* gus_vol.c - Compute volume for GUS.
- *
+ *
* Greg Lee 1993.
*/
#include "sound_config.h"
#ifndef EXCLUDE_GUS
+#include "gus_linearvol.h"
#define GUS_VOLUME gus_wave_volume
extern int gus_wave_volume;
-/*
+/*
* Calculate gus volume from note velocity, main volume, expression, and
* intrinsic patch volume given in patch library. Expression is multiplied
* in, so it emphasizes differences in note velocity, while main volume is
@@ -20,7 +21,7 @@ extern int gus_wave_volume;
* to expression controller messages, if they were found to be used for
* dynamic volume adjustments, so here, main volume can be assumed to be
* constant throughout a song.)
- *
+ *
* Intrinsic patch volume is added in, but if over 64 is also multiplied in, so
* we can give a big boost to very weak voices like nylon guitar and the
* basses. The normal value is 64. Strings are assigned lower values.
@@ -31,27 +32,27 @@ gus_adagio_vol (int vel, int mainv, int xpn, int voicev)
int i, m, n, x;
- /*
+ /*
* A voice volume of 64 is considered neutral, so adjust the main volume if
* something other than this neutral value was assigned in the patch
* library.
*/
x = 256 + 6 * (voicev - 64);
- /*
- * Boost expression by voice volume above neutral.
+ /*
+ * Boost expression by voice volume above neutral.
*/
if (voicev > 65)
xpn += voicev - 64;
xpn += (voicev - 64) / 2;
- /*
- * Combine multiplicative and level components.
+ /*
+ * Combine multiplicative and level components.
*/
x = vel * xpn * 6 + (voicev / 4) * x;
#ifdef GUS_VOLUME
- /*
+ /*
* Further adjustment by installation-specific master volume control
* (default 60).
*/
@@ -72,7 +73,7 @@ gus_adagio_vol (int vel, int mainv, int xpn, int voicev)
else if (x >= 65535)
return ((15 << 8) | 255);
- /*
+ /*
* Convert to gus's logarithmic form with 4 bit exponent i and 8 bit
* mantissa m.
*/
@@ -89,14 +90,14 @@ gus_adagio_vol (int vel, int mainv, int xpn, int voicev)
n >>= 1;
i++;
}
- /*
+ /*
* Mantissa is part of linear volume not expressed in exponent. (This is
* not quite like real logs -- I wonder if it's right.)
*/
m = x - (1 << i);
- /*
- * Adjust mantissa to 8 bits.
+ /*
+ * Adjust mantissa to 8 bits.
*/
if (m > 0)
{
@@ -109,4 +110,38 @@ gus_adagio_vol (int vel, int mainv, int xpn, int voicev)
return ((i << 8) + m);
}
+/*
+ * Volume-values are interpreted as linear values. Volume is based on the
+ * value supplied with SEQ_START_NOTE(), channel main volume (if compiled in)
+ * and the volume set by the mixer-device (default 60%).
+ */
+
+unsigned short
+gus_linear_vol (int vol, int mainvol)
+{
+ int mixer_mainvol;
+
+ if (vol <= 0)
+ vol = 0;
+ else if (vol >= 127)
+ vol = 127;
+
+#ifdef GUS_VOLUME
+ mixer_mainvol = GUS_VOLUME;
+#else
+ mixer_mainvol = 100;
+#endif
+
+#ifdef GUS_USE_CHN_MAIN_VOLUME
+ if (mainvol <= 0)
+ mainvol = 0;
+ else if (mainvol >= 127)
+ mainvol = 127;
+#else
+ mainvol = 128;
+#endif
+
+ return gus_linearvol[(((vol * mainvol) / 128) * mixer_mainvol) / 100];
+}
+
#endif