21 #include <linux/time.h>
22 #include <linux/export.h>
25 #define __GUS_TABLES_ALLOC__
32 unsigned short e,
m,
tmp;
39 while (e > 0 && tmp < (1 << e))
60 unsigned int snd_gf1_gvol_to_lvol_raw(
unsigned short gf1_vol)
68 m = (
unsigned char) gf1_vol;
71 return rvol | (m << (e - 8));
72 return rvol | (m >> (8 -
e));
75 unsigned int snd_gf1_calc_ramp_rate(
struct snd_gus_card * gus,
80 static unsigned char vol_rates[19] =
82 23, 24, 26, 28, 29, 31, 32, 34,
83 36, 37, 39, 40, 42, 44, 45, 47,
95 value = gus->
gf1.enh_mode ?
97 vol_rates[gus->
gf1.active_voices - 14];
98 for (i = 0; i < 3; i++) {
109 increment = (value + (value >> 1)) / us;
110 return (range << 6) | (increment & 0x3f);
120 if (freq16 & 0xf8000000) {
121 freq16 = ~0xf8000000;
124 return ((freq16 << 9) + (gus->
gf1.playback_freq >> 1)) / gus->
gf1.playback_freq;
129 short snd_gf1_compute_vibrato(
short cents,
unsigned short fc_register)
131 static short vibrato_table[] =
133 0, 0, 32, 592, 61, 1175, 93, 1808,
134 124, 2433, 152, 3007, 182, 3632, 213, 4290,
139 short *vi1, *vi2, pcents,
v1;
141 pcents = cents < 0 ? -cents : cents;
142 for (vi1 = vibrato_table, vi2 = vi1 + 2; pcents > *vi2; vi1 = vi2, vi2 += 2);
153 depth = (((
int) (*(vi2 + 1) - *vi1) * (pcents - *vi1) / (*vi2 - *vi1)) +
v1) * fc_register >> 14;
158 return cents < 0 ? -(
short) depth : (
short) depth;
161 unsigned short snd_gf1_compute_pitchbend(
unsigned short pitchbend,
unsigned short sens)
163 static long log_table[] = {1024, 1085, 1149, 1218, 1290, 1367, 1448, 1534, 1625, 1722, 1825, 1933};
164 int wheel, sensitivity;
165 unsigned int mantissa,
f1,
f2;
166 unsigned short semitones, f1_index, f2_index, f1_power, f2_power;
172 wheel = (
int) pitchbend - 8192;
173 sensitivity = ((
int) sens * wheel) / 128;
174 if (sensitivity < 0) {
176 sensitivity = -sensitivity;
178 semitones = (
unsigned int) (sensitivity >> 13);
179 mantissa = sensitivity % 8192;
180 f1_index = semitones % 12;
181 f2_index = (semitones + 1) % 12;
182 f1_power = semitones / 12;
183 f2_power = (semitones + 1) / 12;
184 f1 = log_table[f1_index] << f1_power;
185 f2 = log_table[f2_index] << f2_power;
186 bend = (
int) ((((f2 - f1) * mantissa) >> 13) +
f1);
188 bend = 1048576
L / bend;
192 unsigned short snd_gf1_compute_freq(
unsigned int freq,
194 unsigned short mix_rate)
199 while (freq >= 4194304L) {
203 fc = (freq << 10) / rate;
208 fc = (fc * 44100
UL) / mix_rate;
215 return (
unsigned short)
fc;