/*
* Routines for Trident 4DWave NX/DX soundcards - Synthesizer
* Copyright (c) by Scott McNab <jedi@tartarus.uwa.edu.au>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <sound/driver.h>
#include <asm/io.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/pci.h>
#include <sound/core.h>
#include <sound/trident.h>
#include <sound/seq_device.h>
MODULE_AUTHOR("Scott McNab <jedi@tartarus.uwa.edu.au>");
MODULE_DESCRIPTION("Routines for Trident 4DWave NX/DX soundcards - Synthesizer");
MODULE_LICENSE("GPL");
/* linear to log pan conversion table (4.2 channel attenuation format) */
static unsigned int pan_table[63] = {
7959, 7733, 7514, 7301, 7093, 6892, 6697, 6507,
6322, 6143, 5968, 5799, 5634, 5475, 5319, 5168,
5022, 4879, 4741, 4606, 4475, 4349, 4225, 4105,
3989, 3876, 3766, 3659, 3555, 3454, 3356, 3261,
3168, 3078, 2991, 2906, 2824, 2744, 2666, 2590,
2517, 2445, 2376, 2308, 2243, 2179, 2117, 2057,
1999, 1942, 1887, 1833, 1781, 1731, 1682, 1634,
1588, 1543, 1499, 1456, 1415, 1375, 1336
};
#define LOG_TABLE_SIZE 386
/* Linear half-attenuation to log conversion table in the format:
* {linear volume, logarithmic attenuation equivalent}, ...
*
* Provides conversion from a linear half-volume value in the range
* [0,8192] to a logarithmic attenuation value in the range 0 to 6.02dB.
* Halving the linear volume is equivalent to an additional 6dB of
* logarithmic attenuation. The algorithm used in log_from_linear()
* therefore uses this table as follows:
*
* - loop and for every time the volume is less than half the maximum
* volume (16384), add another 6dB and halve the maximum value used
* for this comparison.
* - when the volume is greater than half the maximum volume, take
* the difference of the volume to half volume (in the range [0,8192])
* and look up the log_table[] to find the nearest entry.
* - take the logarithic component of this entry and add it to the
* resulting attenuation.
*
* Thus this routine provides a linear->log conversion for a range of
* [0,16384] using only 386 table entries
*
* Note: although this table stores log attenuation in 8.8 format, values
* were only calculated for 6 bits fractional precision, since that is
* the most precision offered by the trident hardware.
*/
static unsigned short log_table[LOG_TABLE_SIZE*2] =
{
4, 0x0604, 19, 0x0600, 34, 0x05fc,
49, 0x05f8, 63, 0x05f4, 78, 0x05f0, 93, 0x05ec, 108, 0x05e8,
123, 0x05e4, 138, 0x05e0, 153, 0x05dc, 168, 0x05d8, 183, 0x05d4,
198, 0x05d0, 213, 0x05cc, 228, 0x05c8, 244, 0x05c4, 259, 0x05c0,
274, 0x05bc, 289, 0x05b8, 304, 0x05b4, 320, 0x05b0, 335, 0x05ac,
350, 0x05a8, 366, 0x05a4, 381, 0x05a0, 397, 0x059c, 412, 0x0598,
428, 0x0594, 443, 0x0590, 459, 0x058c, 474, 0x0588, 490, 0x0584,
506, 0x0580, 521, 0x057c, 537, 0x0578, 553, 0x0574, 568, 0x0570,
584, 0x056c, 600, 0x0568, 616, 0x0564, 632, 0x0560, 647, 0x055c,
663, 0x0558, 679, 0x0554, 695, 0x0550, 711, 0x054c, 727, 0x0548,
743, 0x0544, 759, 0x0540, 776, 0x053c, 792, 0x0538, 808, 0x0534,
824, 0x0530, 840, 0x052c, 857, 0x0528, 873, 0x0524, 889, 0x0520,
906, 0x051c, 922, 0x0518, 938, 0x0514, 955, 0x0510, 971, 0x050c,
988, 0x0508, 1004, 0x0504, 1021, 0x0500, 1037, 0x04fc, 1054, 0x04f8,
1071, 0x04f4, 1087, 0x04f0, 1104, 0x04ec, 1121, 0x04e8, 1138, 0x04e4