⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dmasound_core.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *  linux/drivers/sound/dmasound/dmasound_core.c * * *  OSS/Free compatible Atari TT/Falcon and Amiga DMA sound driver for *  Linux/m68k *  Extended to support Power Macintosh for Linux/ppc by Paul Mackerras * *  (c) 1995 by Michael Schlueter & Michael Marte * *  Michael Schlueter (michael@duck.syd.de) did the basic structure of the VFS *  interface and the u-law to signed byte conversion. * *  Michael Marte (marte@informatik.uni-muenchen.de) did the sound queue, *  /dev/mixer, /dev/sndstat and complemented the VFS interface. He would like *  to thank: *    - Michael Schlueter for initial ideas and documentation on the MFP and *	the DMA sound hardware. *    - Therapy? for their CD 'Troublegum' which really made me rock. * *  /dev/sndstat is based on code by Hannu Savolainen, the author of the *  VoxWare family of drivers. * *  This file is subject to the terms and conditions of the GNU General Public *  License.  See the file COPYING in the main directory of this archive *  for more details. * *  History: * *	1995/8/25	First release * *	1995/9/02	Roman Hodek: *			  - Fixed atari_stram_alloc() call, the timer *			    programming and several race conditions *	1995/9/14	Roman Hodek: *			  - After some discussion with Michael Schlueter, *			    revised the interrupt disabling *			  - Slightly speeded up U8->S8 translation by using *			    long operations where possible *			  - Added 4:3 interpolation for /dev/audio * *	1995/9/20	Torsten Scherer: *			  - Fixed a bug in sq_write and changed /dev/audio *			    converting to play at 12517Hz instead of 6258Hz. * *	1995/9/23	Torsten Scherer: *			  - Changed sq_interrupt() and sq_play() to pre-program *			    the DMA for another frame while there's still one *			    running. This allows the IRQ response to be *			    arbitrarily delayed and playing will still continue. * *	1995/10/14	Guenther Kelleter, Torsten Scherer: *			  - Better support for Falcon audio (the Falcon doesn't *			    raise an IRQ at the end of a frame, but at the *			    beginning instead!). uses 'if (codec_dma)' in lots *			    of places to simply switch between Falcon and TT *			    code. * *	1995/11/06	Torsten Scherer: *			  - Started introducing a hardware abstraction scheme *			    (may perhaps also serve for Amigas?) *			  - Can now play samples at almost all frequencies by *			    means of a more generalized expand routine *			  - Takes a good deal of care to cut data only at *			    sample sizes *			  - Buffer size is now a kernel runtime option *			  - Implemented fsync() & several minor improvements *			Guenther Kelleter: *			  - Useful hints and bug fixes *			  - Cross-checked it for Falcons * *	1996/3/9	Geert Uytterhoeven: *			  - Support added for Amiga, A-law, 16-bit little *			    endian. *			  - Unification to drivers/sound/dmasound.c. * *	1996/4/6	Martin Mitchell: *			  - Updated to 1.3 kernel. * *	1996/6/13       Topi Kanerva: *			  - Fixed things that were broken (mainly the amiga *			    14-bit routines) *			  - /dev/sndstat shows now the real hardware frequency *			  - The lowpass filter is disabled by default now * *	1996/9/25	Geert Uytterhoeven: *			  - Modularization * *	1998/6/10	Andreas Schwab: *			  - Converted to use sound_core * *	1999/12/28	Richard Zidlicky: *			  - Added support for Q40 * *	2000/2/27	Geert Uytterhoeven: *			  - Clean up and split the code into 4 parts: *			      o dmasound_core: machine-independent code *			      o dmasound_atari: Atari TT and Falcon support *			      o dmasound_awacs: Apple PowerMac support *			      o dmasound_paula: Amiga support * *	2000/3/25	Geert Uytterhoeven: *			  - Integration of dmasound_q40 *			  - Small clean ups */#include <linux/module.h>#include <linux/malloc.h>#include <linux/sound.h>#include <linux/init.h>#include <linux/soundcard.h>#include <linux/smp_lock.h>#include <asm/uaccess.h>#include "dmasound.h"    /*     *  Declarations     */int dmasound_catchRadius = 0;static unsigned int numWriteBufs = 4;static unsigned int writeBufSize = 32;	/* in KB! */#ifdef HAS_RECORDstatic unsigned int numReadBufs = 4;static unsigned int readBufSize = 32;	/* in KB! */#endifMODULE_PARM(dmasound_catchRadius, "i");MODULE_PARM(numWriteBufs, "i");MODULE_PARM(writeBufSize, "i");MODULE_PARM(numReadBufs, "i");MODULE_PARM(readBufSize, "i");#ifdef MODULEstatic int sq_unit = -1;static int mixer_unit = -1;static int state_unit = -1;static int irq_installed = 0;#endif /* MODULE */    /*     *  Conversion tables     */#ifdef HAS_8BIT_TABLES/* 8 bit mu-law */char dmasound_ulaw2dma8[] = {	-126,	-122,	-118,	-114,	-110,	-106,	-102,	-98,	-94,	-90,	-86,	-82,	-78,	-74,	-70,	-66,	-63,	-61,	-59,	-57,	-55,	-53,	-51,	-49,	-47,	-45,	-43,	-41,	-39,	-37,	-35,	-33,	-31,	-30,	-29,	-28,	-27,	-26,	-25,	-24,	-23,	-22,	-21,	-20,	-19,	-18,	-17,	-16,	-16,	-15,	-15,	-14,	-14,	-13,	-13,	-12,	-12,	-11,	-11,	-10,	-10,	-9,	-9,	-8,	-8,	-8,	-7,	-7,	-7,	-7,	-6,	-6,	-6,	-6,	-5,	-5,	-5,	-5,	-4,	-4,	-4,	-4,	-4,	-4,	-3,	-3,	-3,	-3,	-3,	-3,	-3,	-3,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	0,	125,	121,	117,	113,	109,	105,	101,	97,	93,	89,	85,	81,	77,	73,	69,	65,	62,	60,	58,	56,	54,	52,	50,	48,	46,	44,	42,	40,	38,	36,	34,	32,	30,	29,	28,	27,	26,	25,	24,	23,	22,	21,	20,	19,	18,	17,	16,	15,	15,	14,	14,	13,	13,	12,	12,	11,	11,	10,	10,	9,	9,	8,	8,	7,	7,	7,	6,	6,	6,	6,	5,	5,	5,	5,	4,	4,	4,	4,	3,	3,	3,	3,	3,	3,	2,	2,	2,	2,	2,	2,	2,	2,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0};/* 8 bit A-law */char dmasound_alaw2dma8[] = {	-22,	-21,	-24,	-23,	-18,	-17,	-20,	-19,	-30,	-29,	-32,	-31,	-26,	-25,	-28,	-27,	-11,	-11,	-12,	-12,	-9,	-9,	-10,	-10,	-15,	-15,	-16,	-16,	-13,	-13,	-14,	-14,	-86,	-82,	-94,	-90,	-70,	-66,	-78,	-74,	-118,	-114,	-126,	-122,	-102,	-98,	-110,	-106,	-43,	-41,	-47,	-45,	-35,	-33,	-39,	-37,	-59,	-57,	-63,	-61,	-51,	-49,	-55,	-53,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-2,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-6,	-6,	-6,	-6,	-5,	-5,	-5,	-5,	-8,	-8,	-8,	-8,	-7,	-7,	-7,	-7,	-3,	-3,	-3,	-3,	-3,	-3,	-3,	-3,	-4,	-4,	-4,	-4,	-4,	-4,	-4,	-4,	21,	20,	23,	22,	17,	16,	19,	18,	29,	28,	31,	30,	25,	24,	27,	26,	10,	10,	11,	11,	8,	8,	9,	9,	14,	14,	15,	15,	12,	12,	13,	13,	86,	82,	94,	90,	70,	66,	78,	74,	118,	114,	126,	122,	102,	98,	110,	106,	43,	41,	47,	45,	35,	33,	39,	37,	59,	57,	63,	61,	51,	49,	55,	53,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	5,	5,	5,	5,	4,	4,	4,	4,	7,	7,	7,	7,	6,	6,	6,	6,	2,	2,	2,	2,	2,	2,	2,	2,	3,	3,	3,	3,	3,	3,	3,	3};#endif /* HAS_8BIT_TABLES */#ifdef HAS_16BIT_TABLES/* 16 bit mu-law */short dmasound_ulaw2dma16[] = {	-32124,	-31100,	-30076,	-29052,	-28028,	-27004,	-25980,	-24956,	-23932,	-22908,	-21884,	-20860,	-19836,	-18812,	-17788,	-16764,	-15996,	-15484,	-14972,	-14460,	-13948,	-13436,	-12924,	-12412,	-11900,	-11388,	-10876,	-10364,	-9852,	-9340,	-8828,	-8316,	-7932,	-7676,	-7420,	-7164,	-6908,	-6652,	-6396,	-6140,	-5884,	-5628,	-5372,	-5116,	-4860,	-4604,	-4348,	-4092,	-3900,	-3772,	-3644,	-3516,	-3388,	-3260,	-3132,	-3004,	-2876,	-2748,	-2620,	-2492,	-2364,	-2236,	-2108,	-1980,	-1884,	-1820,	-1756,	-1692,	-1628,	-1564,	-1500,	-1436,	-1372,	-1308,	-1244,	-1180,	-1116,	-1052,	-988,	-924,	-876,	-844,	-812,	-780,	-748,	-716,	-684,	-652,	-620,	-588,	-556,	-524,	-492,	-460,	-428,	-396,	-372,	-356,	-340,	-324,	-308,	-292,	-276,	-260,	-244,	-228,	-212,	-196,	-180,	-164,	-148,	-132,	-120,	-112,	-104,	-96,	-88,	-80,	-72,	-64,	-56,	-48,	-40,	-32,	-24,	-16,	-8,	0,	32124,	31100,	30076,	29052,	28028,	27004,	25980,	24956,	23932,	22908,	21884,	20860,	19836,	18812,	17788,	16764,	15996,	15484,	14972,	14460,	13948,	13436,	12924,	12412,	11900,	11388,	10876,	10364,	9852,	9340,	8828,	8316,	7932,	7676,	7420,	7164,	6908,	6652,	6396,	6140,	5884,	5628,	5372,	5116,	4860,	4604,	4348,	4092,	3900,	3772,	3644,	3516,	3388,	3260,	3132,	3004,	2876,	2748,	2620,	2492,	2364,	2236,	2108,	1980,	1884,	1820,	1756,	1692,	1628,	1564,	1500,	1436,	1372,	1308,	1244,	1180,	1116,	1052,	988,	924,	876,	844,	812,	780,	748,	716,	684,	652,	620,	588,	556,	524,	492,	460,	428,	396,	372,	356,	340,	324,	308,	292,	276,	260,	244,	228,	212,	196,	180,	164,	148,	132,	120,	112,	104,	96,	88,	80,	72,	64,	56,	48,	40,	32,	24,	16,	8,	0,};/* 16 bit A-law */short dmasound_alaw2dma16[] = {	-5504,	-5248,	-6016,	-5760,	-4480,	-4224,	-4992,	-4736,	-7552,	-7296,	-8064,	-7808,	-6528,	-6272,	-7040,	-6784,	-2752,	-2624,	-3008,	-2880,	-2240,	-2112,	-2496,	-2368,	-3776,	-3648,	-4032,	-3904,	-3264,	-3136,	-3520,	-3392,	-22016,	-20992,	-24064,	-23040,	-17920,	-16896,	-19968,	-18944,	-30208,	-29184,	-32256,	-31232,	-26112,	-25088,	-28160,	-27136,	-11008,	-10496,	-12032,	-11520,	-8960,	-8448,	-9984,	-9472,	-15104,	-14592,	-16128,	-15616,	-13056,	-12544,	-14080,	-13568,	-344,	-328,	-376,	-360,	-280,	-264,	-312,	-296,	-472,	-456,	-504,	-488,	-408,	-392,	-440,	-424,	-88,	-72,	-120,	-104,	-24,	-8,	-56,	-40,	-216,	-200,	-248,	-232,	-152,	-136,	-184,	-168,	-1376,	-1312,	-1504,	-1440,	-1120,	-1056,	-1248,	-1184,	-1888,	-1824,	-2016,	-1952,	-1632,	-1568,	-1760,	-1696,	-688,	-656,	-752,	-720,	-560,	-528,	-624,	-592,	-944,	-912,	-1008,	-976,	-816,	-784,	-880,	-848,	5504,	5248,	6016,	5760,	4480,	4224,	4992,	4736,	7552,	7296,	8064,	7808,	6528,	6272,	7040,	6784,	2752,	2624,	3008,	2880,	2240,	2112,	2496,	2368,	3776,	3648,	4032,	3904,	3264,	3136,	3520,	3392,	22016,	20992,	24064,	23040,	17920,	16896,	19968,	18944,	30208,	29184,	32256,	31232,	26112,	25088,	28160,	27136,	11008,	10496,	12032,	11520,	8960,	8448,	9984,	9472,	15104,	14592,	16128,	15616,	13056,	12544,	14080,	13568,	344,	328,	376,	360,	280,	264,	312,	296,	472,	456,	504,	488,	408,	392,	440,	424,	88,	72,	120,	104,	24,	8,	56,	40,	216,	200,	248,	232,	152,	136,	184,	168,	1376,	1312,	1504,	1440,	1120,	1056,	1248,	1184,	1888,	1824,	2016,	1952,	1632,	1568,	1760,	1696,	688,	656,	752,	720,	560,	528,	624,	592,	944,	912,	1008,	976,	816,	784,	880,	848,};#endif /* HAS_16BIT_TABLES */#ifdef HAS_14BIT_TABLES    /*     *  Unused for now. Where are the MSB parts anyway??     *//* 14 bit mu-law (LSB) */char dmasound_ulaw2dma14l[] = {	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	33,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	49,	17,	49,	17,	49,	17,	49,	17,	49,	17,	49,	17,	49,	17,	49,	17,	41,	57,	9,	25,	41,	57,	9,	25,	41,	57,	9,	25,	41,	57,	9,	25,	37,	45,	53,	61,	5,	13,	21,	29,	37,	45,	53,	61,	5,	13,	21,	29,	35,	39,	43,	47,	51,	55,	59,	63,	3,	7,	11,	15,	19,	23,	27,	31,	34,	36,	38,	40,	42,	44,	46,	48,	50,	52,	54,	56,	58,	60,	62,	0,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	31,	63,	63,	63,	63,	63,	63,	63,	63,	63,	63,	63,	63,	63,	63,	63,	63,	15,	47,	15,	47,	15,	47,	15,	47,	15,	47,	15,	47,	15,	47,	15,	47,	23,	7,	55,	39,	23,	7,	55,	39,	23,	7,	55,	39,	23,	7,	55,	39,	27,	19,	11,	3,	59,	51,	43,	35,	27,	19,	11,	3,	59,	51,	43,	35,	29,	25,	21,	17,	13,	9,	5,	1,	61,	57,	53,	49,	45,	41,	37,	33,	30,	28,	26,	24,	22,	20,	18,	16,	14,	12,	10,	8,	6,	4,	2,	0};/* 14 bit A-law (LSB) */char dmasound_alaw2dma14l[] = {	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	16,	48,	16,	48,	16,	48,	16,	48,	16,	48,	16,	48,	16,	48,	16,	48,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	42,	46,	34,	38,	58,	62,	50,	54,	10,	14,	2,	6,	26,	30,	18,	22,	42,	46,	34,	38,	58,	62,	50,	54,	10,	14,	2,	6,	26,	30,	18,	22,	40,	56,	8,	24,	40,	56,	8,	24,	40,	56,	8,	24,	40,	56,	8,	24,	20,	28,	4,	12,	52,	60,	36,	44,	20,	28,	4,	12,	52,	60,	36,	44,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	32,	48,	16,	48,	16,	48,	16,	48,	16,	48,	16,	48,	16,	48,	16,	48,	16,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	22,	18,	30,	26,	6,	2,	14,	10,	54,	50,	62,	58,	38,	34,	46,	42,	22,	18,	30,	26,	6,	2,	14,	10,	54,	50,	62,	58,	38,	34,	46,	42,	24,	8,	56,	40,	24,	8,	56,	40,	24,	8,	56,	40,	24,	8,	56,	40,	44,	36,	60,	52,	12,	4,	28,	20,	44,	36,	60,	52,	12,	4,	28,	20};#endif /* HAS_14BIT_TABLES */    /*     *  Common stuff     */static long long sound_lseek(struct file *file, long long offset, int orig){	return -ESPIPE;}    /*     *  Mid level stuff     */struct sound_settings dmasound;static inline void sound_silence(void){	/* update hardware settings one more */	dmasound.mach.init();	dmasound.mach.silence();}static inline void sound_init(void){	dmasound.mach.init();}static inline int sound_set_format(int format){	return dmasound.mach.setFormat(format);}static int sound_set_speed(int speed){	if (speed < 0)		return dmasound.soft.speed;	dmasound.soft.speed = speed;	dmasound.mach.init();	if (dmasound.minDev == SND_DEV_DSP)		dmasound.dsp.speed = dmasound.soft.speed;	return dmasound.soft.speed;}static int sound_set_stereo(int stereo){	if (stereo < 0)		return dmasound.soft.stereo;	stereo = !!stereo;    /* should be 0 or 1 now */	dmasound.soft.stereo = stereo;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -