RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / sound / isa / gus / gus_volume.c
blob46a1f5ff9a6c25e91d7d2b73953d730f3645749c
1 /*
2 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/time.h>
22 #include <sound/core.h>
23 #include <sound/gus.h>
24 #define __GUS_TABLES_ALLOC__
25 #include "gus_tables.h"
27 EXPORT_SYMBOL(snd_gf1_atten_table); /* for snd-gus-synth module */
29 unsigned short snd_gf1_lvol_to_gvol_raw(unsigned int vol)
31 unsigned short e, m, tmp;
33 if (vol > 65535)
34 vol = 65535;
35 tmp = vol;
36 e = 7;
37 if (tmp < 128) {
38 while (e > 0 && tmp < (1 << e))
39 e--;
40 } else {
41 while (tmp > 255) {
42 tmp >>= 1;
43 e++;
46 m = vol - (1 << e);
47 if (m > 0) {
48 if (e > 8)
49 m >>= e - 8;
50 else if (e < 8)
51 m <<= 8 - e;
52 m &= 255;
54 return (e << 8) | m;
58 unsigned short snd_gf1_translate_freq(struct snd_gus_card * gus, unsigned int freq16)
60 freq16 >>= 3;
61 if (freq16 < 50)
62 freq16 = 50;
63 if (freq16 & 0xf8000000) {
64 freq16 = ~0xf8000000;
65 snd_printk(KERN_ERR "snd_gf1_translate_freq: overflow - freq = 0x%x\n", freq16);
67 return ((freq16 << 9) + (gus->gf1.playback_freq >> 1)) / gus->gf1.playback_freq;