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

📄 sb_audio.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * sound/sb_audio.c * * Audio routines for Sound Blaster compatible cards. * * * Copyright (C) by Hannu Savolainen 1993-1997 * * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL) * Version 2 (June 1991). See the "COPYING" file distributed with this software * for more info. * * Changes *	Alan Cox	:	Formatting and clean ups * * Status *	Mostly working. Weird uart bug causing irq storms * * Daniel J. Rodriksson: Changes to make sb16 work full duplex. *                       Maybe other 16 bit cards in this code could behave *                       the same. */#include "sound_config.h"#include "sb_mixer.h"#include "sb.h"#include "sb_ess.h"int sb_audio_open(int dev, int mode){	sb_devc *devc = audio_devs[dev]->devc;	unsigned long flags;	if (devc == NULL)	{		  printk(KERN_ERR "Sound Blaster: incomplete initialization.\n");		  return -ENXIO;	}	if (devc->caps & SB_NO_RECORDING && mode & OPEN_READ)	{		if (mode == OPEN_READ)			return -EPERM;	}	save_flags(flags);	cli();	if (devc->opened)	{		  restore_flags(flags);		  return -EBUSY;	}	if (devc->dma16 != -1 && devc->dma16 != devc->dma8 && !devc->duplex)	{		if (sound_open_dma(devc->dma16, "Sound Blaster 16 bit"))		{			restore_flags(flags);			return -EBUSY;		}	}	devc->opened = mode;	restore_flags(flags);	devc->irq_mode = IMODE_NONE;	devc->irq_mode_16 = IMODE_NONE;	devc->fullduplex = devc->duplex &&		((mode & OPEN_READ) && (mode & OPEN_WRITE));	sb_dsp_reset(devc);	/* At first glance this check isn't enough, some ESS chips might not 	 * have a RECLEV. However if they don't common_mixer_set will refuse 	 * cause devc->iomap has no register mapping for RECLEV	 */	if (devc->model == MDL_ESS) ess_mixer_reload (devc, SOUND_MIXER_RECLEV);	/* The ALS007 seems to require that the DSP be removed from the output */	/* in order for recording to be activated properly.  This is done by   */	/* setting the appropriate bits of the output control register 4ch to  */	/* zero.  This code assumes that the output control registers are not  */	/* used anywhere else and therefore the DSP bits are *always* ON for   */	/* output and OFF for sampling.                                        */	if (devc->submodel == SUBMDL_ALS007) 	{		if (mode & OPEN_READ) 			sb_setmixer(devc,ALS007_OUTPUT_CTRL2,				sb_getmixer(devc,ALS007_OUTPUT_CTRL2) & 0xf9);		else			sb_setmixer(devc,ALS007_OUTPUT_CTRL2,				sb_getmixer(devc,ALS007_OUTPUT_CTRL2) | 0x06);	}	return 0;}void sb_audio_close(int dev){	sb_devc *devc = audio_devs[dev]->devc;	/* fix things if mmap turned off fullduplex */	if(devc->duplex	   && !devc->fullduplex	   && (devc->opened & OPEN_READ) && (devc->opened & OPEN_WRITE))	{		struct dma_buffparms *dmap_temp;		dmap_temp = audio_devs[dev]->dmap_out;		audio_devs[dev]->dmap_out = audio_devs[dev]->dmap_in;		audio_devs[dev]->dmap_in = dmap_temp;	}	audio_devs[dev]->dmap_out->dma = devc->dma8;	audio_devs[dev]->dmap_in->dma = ( devc->duplex ) ?		devc->dma16 : devc->dma8;	if (devc->dma16 != -1 && devc->dma16 != devc->dma8 && !devc->duplex)		sound_close_dma(devc->dma16);	/* For ALS007, turn DSP output back on if closing the device for read */		if ((devc->submodel == SUBMDL_ALS007) && (devc->opened & OPEN_READ)) 	{		sb_setmixer(devc,ALS007_OUTPUT_CTRL2,			sb_getmixer(devc,ALS007_OUTPUT_CTRL2) | 0x06);	}	devc->opened = 0;}static void sb_set_output_parms(int dev, unsigned long buf, int nr_bytes,		    int intrflag){	sb_devc *devc = audio_devs[dev]->devc;	if (!devc->fullduplex || devc->bits == AFMT_S16_LE)	{		devc->trg_buf = buf;		devc->trg_bytes = nr_bytes;		devc->trg_intrflag = intrflag;		devc->irq_mode = IMODE_OUTPUT;	}	else	{		devc->trg_buf_16 = buf;		devc->trg_bytes_16 = nr_bytes;		devc->trg_intrflag_16 = intrflag;		devc->irq_mode_16 = IMODE_OUTPUT;	}}static void sb_set_input_parms(int dev, unsigned long buf, int count, int intrflag){	sb_devc *devc = audio_devs[dev]->devc;	if (!devc->fullduplex || devc->bits != AFMT_S16_LE)	{		devc->trg_buf = buf;		devc->trg_bytes = count;		devc->trg_intrflag = intrflag;		devc->irq_mode = IMODE_INPUT;	}	else	{		devc->trg_buf_16 = buf;		devc->trg_bytes_16 = count;		devc->trg_intrflag_16 = intrflag;		devc->irq_mode_16 = IMODE_INPUT;	}}/* * SB1.x compatible routines  */static void sb1_audio_output_block(int dev, unsigned long buf, int nr_bytes, int intrflag){	unsigned long flags;	int count = nr_bytes;	sb_devc *devc = audio_devs[dev]->devc;	/* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */	if (audio_devs[dev]->dmap_out->dma > 3)		count >>= 1;	count--;	devc->irq_mode = IMODE_OUTPUT;	save_flags(flags);	cli();	if (sb_dsp_command(devc, 0x14))		/* 8 bit DAC using DMA */	{		sb_dsp_command(devc, (unsigned char) (count & 0xff));		sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));	}	else		printk(KERN_WARNING "Sound Blaster:  unable to start DAC.\n");	restore_flags(flags);	devc->intr_active = 1;}static void sb1_audio_start_input(int dev, unsigned long buf, int nr_bytes, int intrflag){	unsigned long flags;	int count = nr_bytes;	sb_devc *devc = audio_devs[dev]->devc;	/*	 * Start a DMA input to the buffer pointed by dmaqtail	 */	/* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */	if (audio_devs[dev]->dmap_out->dma > 3)		count >>= 1;	count--;	devc->irq_mode = IMODE_INPUT;	save_flags(flags);	cli();	if (sb_dsp_command(devc, 0x24))		/* 8 bit ADC using DMA */	{		sb_dsp_command(devc, (unsigned char) (count & 0xff));		sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));	}	else		printk(KERN_ERR "Sound Blaster:  unable to start ADC.\n");	restore_flags(flags);	devc->intr_active = 1;}static void sb1_audio_trigger(int dev, int bits){	sb_devc *devc = audio_devs[dev]->devc;	bits &= devc->irq_mode;	if (!bits)		sb_dsp_command(devc, 0xd0);	/* Halt DMA */	else	{		switch (devc->irq_mode)		{			case IMODE_INPUT:				sb1_audio_start_input(dev, devc->trg_buf, devc->trg_bytes,						devc->trg_intrflag);				break;			case IMODE_OUTPUT:				sb1_audio_output_block(dev, devc->trg_buf, devc->trg_bytes,						devc->trg_intrflag);				break;		}	}	devc->trigger_bits = bits;}static int sb1_audio_prepare_for_input(int dev, int bsize, int bcount){	sb_devc *devc = audio_devs[dev]->devc;	unsigned long flags;	save_flags(flags);	cli();	if (sb_dsp_command(devc, 0x40))		sb_dsp_command(devc, devc->tconst);	sb_dsp_command(devc, DSP_CMD_SPKOFF);	restore_flags(flags);	devc->trigger_bits = 0;	return 0;}static int sb1_audio_prepare_for_output(int dev, int bsize, int bcount){	sb_devc *devc = audio_devs[dev]->devc;	unsigned long flags;	save_flags(flags);	cli();	if (sb_dsp_command(devc, 0x40))		sb_dsp_command(devc, devc->tconst);	sb_dsp_command(devc, DSP_CMD_SPKON);	restore_flags(flags);	devc->trigger_bits = 0;	return 0;}static int sb1_audio_set_speed(int dev, int speed){	int max_speed = 23000;	sb_devc *devc = audio_devs[dev]->devc;	int tmp;	if (devc->opened & OPEN_READ)		max_speed = 13000;	if (speed > 0)	{		if (speed < 4000)			speed = 4000;		if (speed > max_speed)			speed = max_speed;		devc->tconst = (256 - ((1000000 + speed / 2) / speed)) & 0xff;		tmp = 256 - devc->tconst;		speed = (1000000 + tmp / 2) / tmp;		devc->speed = speed;	}	return devc->speed;}static short sb1_audio_set_channels(int dev, short channels){	sb_devc *devc = audio_devs[dev]->devc;	return devc->channels = 1;}static unsigned int sb1_audio_set_bits(int dev, unsigned int bits){	sb_devc        *devc = audio_devs[dev]->devc;	return devc->bits = 8;}static void sb1_audio_halt_xfer(int dev){	unsigned long flags;	sb_devc *devc = audio_devs[dev]->devc;	save_flags(flags);	cli();	sb_dsp_reset(devc);	restore_flags(flags);}/* * SB 2.0 and SB 2.01 compatible routines */static void sb20_audio_output_block(int dev, unsigned long buf, int nr_bytes,			int intrflag){	unsigned long flags;	int count = nr_bytes;	sb_devc *devc = audio_devs[dev]->devc;	unsigned char cmd;	/* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */	if (audio_devs[dev]->dmap_out->dma > 3)		count >>= 1;	count--;	devc->irq_mode = IMODE_OUTPUT;	save_flags(flags);	cli();	if (sb_dsp_command(devc, 0x48))		/* DSP Block size */	{		sb_dsp_command(devc, (unsigned char) (count & 0xff));		sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));		if (devc->speed * devc->channels <= 23000)			cmd = 0x1c;	/* 8 bit PCM output */		else			cmd = 0x90;	/* 8 bit high speed PCM output (SB2.01/Pro) */		if (!sb_dsp_command(devc, cmd))			printk(KERN_ERR "Sound Blaster:  unable to start DAC.\n");	}	else		printk(KERN_ERR "Sound Blaster: unable to start DAC.\n");	restore_flags(flags);	devc->intr_active = 1;}static void sb20_audio_start_input(int dev, unsigned long buf, int nr_bytes, int intrflag){	unsigned long flags;	int count = nr_bytes;	sb_devc *devc = audio_devs[dev]->devc;	unsigned char cmd;	/*	 * Start a DMA input to the buffer pointed by dmaqtail	 */	/* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */	if (audio_devs[dev]->dmap_out->dma > 3)		count >>= 1;	count--;	devc->irq_mode = IMODE_INPUT;	save_flags(flags);	cli();	if (sb_dsp_command(devc, 0x48))		/* DSP Block size */	{		sb_dsp_command(devc, (unsigned char) (count & 0xff));		sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));		if (devc->speed * devc->channels <= (devc->major == 3 ? 23000 : 13000))			cmd = 0x2c;	/* 8 bit PCM input */		else			cmd = 0x98;	/* 8 bit high speed PCM input (SB2.01/Pro) */		if (!sb_dsp_command(devc, cmd))			printk(KERN_ERR "Sound Blaster:  unable to start ADC.\n");	}	else		printk(KERN_ERR "Sound Blaster:  unable to start ADC.\n");	restore_flags(flags);	devc->intr_active = 1;}static void sb20_audio_trigger(int dev, int bits){	sb_devc *devc = audio_devs[dev]->devc;	bits &= devc->irq_mode;	if (!bits)		sb_dsp_command(devc, 0xd0);	/* Halt DMA */	else	{		switch (devc->irq_mode)		{			case IMODE_INPUT:				sb20_audio_start_input(dev, devc->trg_buf, devc->trg_bytes,						devc->trg_intrflag);				break;			case IMODE_OUTPUT:				sb20_audio_output_block(dev, devc->trg_buf, devc->trg_bytes,						devc->trg_intrflag);			    break;		}	}	devc->trigger_bits = bits;}/* * SB2.01 specific speed setup */static int sb201_audio_set_speed(int dev, int speed){	sb_devc *devc = audio_devs[dev]->devc;	int tmp;	int s = speed * devc->channels;	if (speed > 0)	{		if (speed < 4000)			speed = 4000;		if (speed > 44100)			speed = 44100;		if (devc->opened & OPEN_READ && speed > 15000)			speed = 15000;		devc->tconst = (256 - ((1000000 + s / 2) / s)) & 0xff;		tmp = 256 - devc->tconst;		speed = ((1000000 + tmp / 2) / tmp) / devc->channels;		devc->speed = speed;	}	return devc->speed;}/* * SB Pro specific routines */static int sbpro_audio_prepare_for_input(int dev, int bsize, int bcount){				/* For SB Pro and Jazz16 */	sb_devc *devc = audio_devs[dev]->devc;	unsigned long flags;	unsigned char bits = 0;	if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)		audio_devs[dev]->dmap_out->dma = audio_devs[dev]->dmap_in->dma =			devc->bits == 16 ? devc->dma16 : devc->dma8;	if (devc->model == MDL_JAZZ || devc->model == MDL_SMW)		if (devc->bits == AFMT_S16_LE)			bits = 0x04;	/* 16 bit mode */	save_flags(flags);	cli();	if (sb_dsp_command(devc, 0x40))		sb_dsp_command(devc, devc->tconst);	sb_dsp_command(devc, DSP_CMD_SPKOFF);	if (devc->channels == 1)		sb_dsp_command(devc, 0xa0 | bits);	/* Mono input */	else		sb_dsp_command(devc, 0xa8 | bits);	/* Stereo input */	restore_flags(flags);	devc->trigger_bits = 0;	return 0;}static int sbpro_audio_prepare_for_output(int dev, int bsize, int bcount){				/* For SB Pro and Jazz16 */	sb_devc *devc = audio_devs[dev]->devc;	unsigned long flags;	unsigned char tmp;	unsigned char bits = 0;	if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)		audio_devs[dev]->dmap_out->dma = audio_devs[dev]->dmap_in->dma = devc->bits == 16 ? devc->dma16 : devc->dma8;	if (devc->model == MDL_SBPRO)		sb_mixer_set_stereo(devc, devc->channels == 2);	save_flags(flags);	cli();	if (sb_dsp_command(devc, 0x40))		sb_dsp_command(devc, devc->tconst);	sb_dsp_command(devc, DSP_CMD_SPKON);	if (devc->model == MDL_JAZZ || devc->model == MDL_SMW)	{		if (devc->bits == AFMT_S16_LE)			bits = 0x04;	/* 16 bit mode */		if (devc->channels == 1)			sb_dsp_command(devc, 0xa0 | bits);	/* Mono output */		else			sb_dsp_command(devc, 0xa8 | bits);	/* Stereo output */	}	else	{		tmp = sb_getmixer(devc, 0x0e);		if (devc->channels == 1)			tmp &= ~0x02;		else			tmp |= 0x02;		sb_setmixer(devc, 0x0e, tmp);	}	restore_flags(flags);	devc->trigger_bits = 0;	return 0;}static int sbpro_audio_set_speed(int dev, int speed){	sb_devc *devc = audio_devs[dev]->devc;	if (speed > 0)	{		if (speed < 4000)			speed = 4000;		if (speed > 44100)

⌨️ 快捷键说明

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