OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [sound/] [gus_vol.c] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/*
2
 * gus_vol.c - Compute volume for GUS.
3
 */
4
/*
5
 * Copyright (C) by Hannu Savolainen 1993-1996
6
 *
7
 * USS/Lite for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
8
 * Version 2 (June 1991). See the "COPYING" file distributed with this software
9
 * for more info.
10
 */
11
#include <linux/config.h>
12
 
13
#include "sound_config.h"
14
#ifdef CONFIG_GUS
15
#include "gus_linearvol.h"
16
 
17
#define GUS_VOLUME      gus_wave_volume
18
 
19
 
20
extern int      gus_wave_volume;
21
 
22
/*
23
 * Calculate gus volume from note velocity, main volume, expression, and
24
 * intrinsic patch volume given in patch library.  Expression is multiplied
25
 * in, so it emphasizes differences in note velocity, while main volume is
26
 * added in -- I don't know whether this is right, but it seems reasonable to
27
 * me.  (In the previous stage, main volume controller messages were changed
28
 * to expression controller messages, if they were found to be used for
29
 * dynamic volume adjustments, so here, main volume can be assumed to be
30
 * constant throughout a song.)
31
 *
32
 * Intrinsic patch volume is added in, but if over 64 is also multiplied in, so
33
 * we can give a big boost to very weak voices like nylon guitar and the
34
 * basses.  The normal value is 64.  Strings are assigned lower values.
35
 */
36
unsigned short
37
gus_adagio_vol (int vel, int mainv, int xpn, int voicev)
38
{
39
  int             i, m, n, x;
40
 
41
 
42
  /*
43
   * A voice volume of 64 is considered neutral, so adjust the main volume if
44
   * something other than this neutral value was assigned in the patch
45
   * library.
46
   */
47
  x = 256 + 6 * (voicev - 64);
48
 
49
  /*
50
   * Boost expression by voice volume above neutral.
51
   */
52
  if (voicev > 65)
53
    xpn += voicev - 64;
54
  xpn += (voicev - 64) / 2;
55
 
56
  /*
57
   * Combine multiplicative and level components.
58
   */
59
  x = vel * xpn * 6 + (voicev / 4) * x;
60
 
61
#ifdef GUS_VOLUME
62
  /*
63
   * Further adjustment by installation-specific master volume control
64
   * (default 60).
65
   */
66
  x = (x * GUS_VOLUME * GUS_VOLUME) / 10000;
67
#endif
68
 
69
#ifdef GUS_USE_CHN_MAIN_VOLUME
70
  /*
71
   * Experimental support for the channel main volume
72
   */
73
 
74
  mainv = (mainv / 2) + 64;     /* Scale to 64 to 127 */
75
  x = (x * mainv * mainv) / 16384;
76
#endif
77
 
78
  if (x < 2)
79
    return (0);
80
  else if (x >= 65535)
81
    return ((15 << 8) | 255);
82
 
83
  /*
84
   * Convert to GUS's logarithmic form with 4 bit exponent i and 8 bit
85
   * mantissa m.
86
   */
87
  n = x;
88
  i = 7;
89
  if (n < 128)
90
    {
91
      while (i > 0 && n < (1 << i))
92
        i--;
93
    }
94
  else
95
    while (n > 255)
96
      {
97
        n >>= 1;
98
        i++;
99
      }
100
  /*
101
   * Mantissa is part of linear volume not expressed in exponent.  (This is
102
   * not quite like real logs -- I wonder if it's right.)
103
   */
104
  m = x - (1 << i);
105
 
106
  /*
107
   * Adjust mantissa to 8 bits.
108
   */
109
  if (m > 0)
110
    {
111
      if (i > 8)
112
        m >>= i - 8;
113
      else if (i < 8)
114
        m <<= 8 - i;
115
    }
116
 
117
  return ((i << 8) + m);
118
}
119
 
120
/*
121
 * Volume-values are interpreted as linear values. Volume is based on the
122
 * value supplied with SEQ_START_NOTE(), channel main volume (if compiled in)
123
 * and the volume set by the mixer-device (default 60%).
124
 */
125
 
126
unsigned short
127
gus_linear_vol (int vol, int mainvol)
128
{
129
  int             mixer_mainvol;
130
 
131
  if (vol <= 0)
132
    vol = 0;
133
  else if (vol >= 127)
134
    vol = 127;
135
 
136
#ifdef GUS_VOLUME
137
  mixer_mainvol = GUS_VOLUME;
138
#else
139
  mixer_mainvol = 100;
140
#endif
141
 
142
#ifdef GUS_USE_CHN_MAIN_VOLUME
143
  if (mainvol <= 0)
144
    mainvol = 0;
145
  else if (mainvol >= 127)
146
    mainvol = 127;
147
#else
148
  mainvol = 127;
149
#endif
150
 
151
  return gus_linearvol[(((vol * mainvol) / 127) * mixer_mainvol) / 100];
152
}
153
 
154
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.