1/* 2 * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 3 * 4 * 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. 9 * 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. 14 * 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 18 * 19 */ 20 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" 26 27EXPORT_SYMBOL(snd_gf1_atten_table); /* for snd-gus-synth module */ 28 29unsigned short snd_gf1_lvol_to_gvol_raw(unsigned int vol) 30{ 31 unsigned short e, m, tmp; 32 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++; 44 } 45 } 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; 53 } 54 return (e << 8) | m; 55} 56 57 58unsigned short snd_gf1_translate_freq(struct snd_gus_card * gus, unsigned int freq16) 59{ 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); 66 } 67 return ((freq16 << 9) + (gus->gf1.playback_freq >> 1)) / gus->gf1.playback_freq; 68} 69