亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? opl3.c

?? LINUX1.0源代碼,代碼條理清晰
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*
 * sound/opl3.c
 * 
 * A low level driver for Yamaha YM3812 and OPL-3 -chips
 * 
 * Copyright by Hannu Savolainen 1993
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met: 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer. 2.
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * 
 */

/* Major improvements to the FM handling 30AUG92 by Rob Hooft, */
/* hooft@chem.ruu.nl */

#include "sound_config.h"

#if defined(CONFIGURE_SOUNDCARD) && !defined(EXCLUDE_YM3812)

#include "opl3.h"

#define MAX_VOICE	18
#define OFFS_4OP	11	/* Definitions for the operators OP3 and OP4
				 * begin here */

static int      opl3_enabled = 0;
static int      left_address = 0x388, right_address = 0x388, both_address = 0;

static int      nr_voices = 9;
static int      logical_voices[MAX_VOICE] =
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};

struct voice_info
  {
    unsigned char   keyon_byte;
    long            bender;
    long            bender_range;
    unsigned long   orig_freq;
    unsigned long   current_freq;
    int             mode;
  };

static struct voice_info voices[MAX_VOICE];

static struct sbi_instrument *instrmap;
static struct sbi_instrument *active_instrument[MAX_VOICE] =
{NULL};

static struct synth_info fm_info =
{"AdLib", 0, SYNTH_TYPE_FM, FM_TYPE_ADLIB, 0, 9, 0, SBFM_MAXINSTR, 0};

static int      already_initialized = 0;

static int      opl3_ok = 0;
static int      opl3_busy = 0;
static int      fm_model = 0;	/* 0=no fm, 1=mono, 2=SB Pro 1, 3=SB Pro 2	 */

static int      store_instr (int instr_no, struct sbi_instrument *instr);
static void     freq_to_fnum (int freq, int *block, int *fnum);
static void     opl3_command (int io_addr, unsigned int addr, unsigned int val);
static int      opl3_kill_note (int dev, int voice, int velocity);
static unsigned char connection_mask = 0x00;

void
enable_opl3_mode (int left, int right, int both)
{
  opl3_enabled = 1;
  left_address = left;
  right_address = right;
  both_address = both;
  fm_info.capabilities = SYNTH_CAP_OPL3;
  fm_info.synth_subtype = FM_TYPE_OPL3;
}

static void
enter_4op_mode (void)
{
  int             i;
  static int      voices_4op[MAX_VOICE] =
  {0, 1, 2, 9, 10, 11, 6, 7, 8, 15, 16, 17};

  connection_mask = 0x3f;
  opl3_command (right_address, CONNECTION_SELECT_REGISTER, 0x3f);	/* Select all 4-OP
									 * voices */
  for (i = 0; i < 3; i++)
    physical_voices[i].voice_mode = 4;
  for (i = 3; i < 6; i++)
    physical_voices[i].voice_mode = 0;

  for (i = 9; i < 12; i++)
    physical_voices[i].voice_mode = 4;
  for (i = 12; i < 15; i++)
    physical_voices[i].voice_mode = 0;

  for (i = 0; i < 12; i++)
    logical_voices[i] = voices_4op[i];
  nr_voices = 12;
}

static int
opl3_ioctl (int dev,
	    unsigned int cmd, unsigned int arg)
{
  switch (cmd)
    {

    case SNDCTL_FM_LOAD_INSTR:
      {
	struct sbi_instrument ins;

	IOCTL_FROM_USER ((char *) &ins, (char *) arg, 0, sizeof (ins));

	if (ins.channel < 0 || ins.channel >= SBFM_MAXINSTR)
	  {
	    printk ("FM Error: Invalid instrument number %d\n", ins.channel);
	    return RET_ERROR (EINVAL);
	  }

	pmgr_inform (dev, PM_E_PATCH_LOADED, ins.channel, 0, 0, 0);
	return store_instr (ins.channel, &ins);
      }
      break;

    case SNDCTL_SYNTH_INFO:
      fm_info.nr_voices = (nr_voices == 12) ? 6 : nr_voices;

      IOCTL_TO_USER ((char *) arg, 0, &fm_info, sizeof (fm_info));
      return 0;
      break;

    case SNDCTL_SYNTH_MEMAVL:
      return 0x7fffffff;
      break;

    case SNDCTL_FM_4OP_ENABLE:
      if (opl3_enabled)
	enter_4op_mode ();
      return 0;
      break;

    default:
      return RET_ERROR (EINVAL);
    }

}

int
opl3_detect (int ioaddr)
{
  /*
   * This function returns 1 if the FM chicp is present at the given I/O port
   * The detection algorithm plays with the timer built in the FM chip and
   * looks for a change in the status register.
   * 
   * Note! The timers of the FM chip are not connected to AdLib (and compatible)
   * boards.
   * 
   * Note2! The chip is initialized if detected.
   */

  unsigned char   stat1, stat2;
  int             i;

  if (already_initialized)
    {
      return 0;			/* Do avoid duplicate initializations */
    }

  if (opl3_enabled)
    ioaddr = left_address;

  opl3_command (ioaddr, TIMER_CONTROL_REGISTER, TIMER1_MASK | TIMER2_MASK);	/* Reset timers 1 and 2 */
  opl3_command (ioaddr, TIMER_CONTROL_REGISTER, IRQ_RESET);	/* Reset the IRQ of FM
								 * chicp */

  stat1 = INB (ioaddr);		/* Read status register */

  if ((stat1 & 0xE0) != 0x00)
    {
      return 0;			/* Should be 0x00	 */
    }

  opl3_command (ioaddr, TIMER1_REGISTER, 0xff);	/* Set timer 1 to 0xff */
  opl3_command (ioaddr, TIMER_CONTROL_REGISTER,
		TIMER2_MASK | TIMER1_START);	/* Unmask and start timer 1 */

  /*
   * Now we have to delay at least 80 msec
   */

  for (i = 0; i < 50; i++)
    tenmicrosec ();		/* To be sure */

  stat2 = INB (ioaddr);		/* Read status after timers have expired */

  /* Stop the timers */

  opl3_command (ioaddr, TIMER_CONTROL_REGISTER, TIMER1_MASK | TIMER2_MASK);	/* Reset timers 1 and 2 */
  opl3_command (ioaddr, TIMER_CONTROL_REGISTER, IRQ_RESET);	/* Reset the IRQ of FM
								 * chicp */

  if ((stat2 & 0xE0) != 0xc0)
    {
      return 0;			/* There is no YM3812 */
    }

  /* There is a FM chicp in this address. Now set some default values. */

  for (i = 0; i < 9; i++)
    opl3_command (ioaddr, KEYON_BLOCK + i, 0);	/* Note off */

  opl3_command (ioaddr, TEST_REGISTER, ENABLE_WAVE_SELECT);
  opl3_command (ioaddr, PERCUSSION_REGISTER, 0x00);	/* Melodic mode. */

  return 1;
}

static int
opl3_kill_note (int dev, int voice, int velocity)
{
  struct physical_voice_info *map;

  if (voice < 0 || voice >= nr_voices)
    return 0;

  map = &physical_voices[logical_voices[voice]];

  DEB (printk ("Kill note %d\n", voice));

  if (map->voice_mode == 0)
    return 0;

  opl3_command (map->ioaddr, KEYON_BLOCK + map->voice_num, voices[voice].keyon_byte & ~0x20);

  voices[voice].keyon_byte = 0;
  voices[voice].bender = 0;
  voices[voice].bender_range = 200;	/* 200 cents = 2 semitones */
  voices[voice].orig_freq = 0;
  voices[voice].current_freq = 0;
  voices[voice].mode = 0;

  return 0;
}

#define HIHAT			0
#define CYMBAL			1
#define TOMTOM			2
#define SNARE			3
#define BDRUM			4
#define UNDEFINED		TOMTOM
#define DEFAULT			TOMTOM

static int
store_instr (int instr_no, struct sbi_instrument *instr)
{

  if (instr->key != FM_PATCH && (instr->key != OPL3_PATCH || !opl3_enabled))
    printk ("FM warning: Invalid patch format field (key) 0x%x\n", instr->key);
  memcpy ((char *) &(instrmap[instr_no]), (char *) instr, sizeof (*instr));

  return 0;
}

static int
opl3_set_instr (int dev, int voice, int instr_no)
{
  if (voice < 0 || voice >= nr_voices)
    return 0;

  if (instr_no < 0 || instr_no >= SBFM_MAXINSTR)
    return 0;

  active_instrument[voice] = &instrmap[instr_no];
  return 0;
}

/*
 * The next table looks magical, but it certainly is not. Its values have
 * been calculated as table[i]=8*log(i/64)/log(2) with an obvious exception
 * for i=0. This log-table converts a linear volume-scaling (0..127) to a
 * logarithmic scaling as present in the FM-synthesizer chips. so :    Volume
 * 64 =  0 db = relative volume  0 and:    Volume 32 = -6 db = relative
 * volume -8 it was implemented as a table because it is only 128 bytes and
 * it saves a lot of log() calculations. (RH)
 */
char            fm_volume_table[128] =
{-64, -48, -40, -35, -32, -29, -27, -26,	/* 0 -   7 */
 -24, -23, -21, -20, -19, -18, -18, -17,	/* 8 -  15 */
 -16, -15, -15, -14, -13, -13, -12, -12,	/* 16 -  23 */
 -11, -11, -10, -10, -10, -9, -9, -8,	/* 24 -  31 */
 -8, -8, -7, -7, -7, -6, -6, -6,/* 32 -  39 */
 -5, -5, -5, -5, -4, -4, -4, -4,/* 40 -  47 */
 -3, -3, -3, -3, -2, -2, -2, -2,/* 48 -  55 */
 -2, -1, -1, -1, -1, 0, 0, 0,	/* 56 -  63 */
 0, 0, 0, 1, 1, 1, 1, 1,	/* 64 -  71 */
 1, 2, 2, 2, 2, 2, 2, 2,	/* 72 -  79 */
 3, 3, 3, 3, 3, 3, 3, 4,	/* 80 -  87 */
 4, 4, 4, 4, 4, 4, 4, 5,	/* 88 -  95 */
 5, 5, 5, 5, 5, 5, 5, 5,	/* 96 - 103 */
 6, 6, 6, 6, 6, 6, 6, 6,	/* 104 - 111 */
 6, 7, 7, 7, 7, 7, 7, 7,	/* 112 - 119 */
 7, 7, 7, 8, 8, 8, 8, 8};	/* 120 - 127 */

static void
calc_vol (unsigned char *regbyte, int volume)
{
  int             level = (~*regbyte & 0x3f);

  if (level)
    level += fm_volume_table[volume];

  if (level > 0x3f)
    level = 0x3f;
  if (level < 0)
    level = 0;

  *regbyte = (*regbyte & 0xc0) | (~level & 0x3f);
}

static void
set_voice_volume (int voice, int volume)
{
  unsigned char   vol1, vol2, vol3, vol4;
  struct sbi_instrument *instr;
  struct physical_voice_info *map;

  if (voice < 0 || voice >= nr_voices)
    return;

  map = &physical_voices[logical_voices[voice]];

  instr = active_instrument[voice];

  if (!instr)
    instr = &instrmap[0];

  if (instr->channel < 0)
    return;

  if (voices[voice].mode == 0)
    return;

  if (voices[voice].mode == 2)
    {				/* 2 OP voice */

      vol1 = instr->operators[2];
      vol2 = instr->operators[3];

      if ((instr->operators[10] & 0x01))
	{			/* Additive synthesis	 */
	  calc_vol (&vol1, volume);
	  calc_vol (&vol2, volume);
	}
      else
	{			/* FM synthesis */
	  calc_vol (&vol2, volume);
	}

      opl3_command (map->ioaddr, KSL_LEVEL + map->op[0], vol1);	/* Modulator volume */
      opl3_command (map->ioaddr, KSL_LEVEL + map->op[1], vol2);	/* Carrier volume */
    }
  else
    {				/* 4 OP voice */
      int             connection;

      vol1 = instr->operators[2];
      vol2 = instr->operators[3];
      vol3 = instr->operators[OFFS_4OP + 2];
      vol4 = instr->operators[OFFS_4OP + 3];

      /*
       * The connection method for 4 OP voices is defined by the rightmost
       * bits at the offsets 10 and 10+OFFS_4OP
       */

      connection = ((instr->operators[10] & 0x01) << 1) | (instr->operators[10 + OFFS_4OP] & 0x01);

      switch (connection)
	{
	case 0:
	  calc_vol (&vol4, volume);	/* Just the OP 4 is carrier */
	  break;

	case 1:
	  calc_vol (&vol2, volume);
	  calc_vol (&vol4, volume);
	  break;

	case 2:
	  calc_vol (&vol1, volume);
	  calc_vol (&vol4, volume);
	  break;

	case 3:
	  calc_vol (&vol1, volume);
	  calc_vol (&vol3, volume);
	  calc_vol (&vol4, volume);
	  break;

	default:/* Why ?? */ ;
	}

      opl3_command (map->ioaddr, KSL_LEVEL + map->op[0], vol1);
      opl3_command (map->ioaddr, KSL_LEVEL + map->op[1], vol2);
      opl3_command (map->ioaddr, KSL_LEVEL + map->op[2], vol3);
      opl3_command (map->ioaddr, KSL_LEVEL + map->op[3], vol4);
    }
}

static int
opl3_start_note (int dev, int voice, int note, int volume)
{
  unsigned char   data, fpc;
  int             block, fnum, freq, voice_mode;
  struct sbi_instrument *instr;
  struct physical_voice_info *map;

  if (voice < 0 || voice >= nr_voices)
    return 0;

  map = &physical_voices[logical_voices[voice]];

  if (map->voice_mode == 0)
    return 0;

  if (note == 255)		/* Just change the volume */
    {
      set_voice_volume (voice, volume);
      return 0;
    }

  /* Kill previous note before playing */
  opl3_command (map->ioaddr, KSL_LEVEL + map->op[1], 0xff);	/* Carrier volume to min */
  opl3_command (map->ioaddr, KSL_LEVEL + map->op[0], 0xff);	/* Modulator volume to */

  if (map->voice_mode == 4)
    {
      opl3_command (map->ioaddr, KSL_LEVEL + map->op[2], 0xff);
      opl3_command (map->ioaddr, KSL_LEVEL + map->op[3], 0xff);
    }

  opl3_command (map->ioaddr, KEYON_BLOCK + map->voice_num, 0x00);	/* Note off */

  instr = active_instrument[voice];

  if (!instr)
    instr = &instrmap[0];

  if (instr->channel < 0)
    {
      printk (
	       "OPL3: Initializing voice %d with undefined instrument\n",
	       voice);
      return 0;
    }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久精品一区二区三区av| 欧洲色大大久久| 成人黄色免费短视频| av电影一区二区| 成人福利视频网站| 99视频一区二区| 色婷婷精品大视频在线蜜桃视频| 色婷婷激情综合| 欧美巨大另类极品videosbest| 精品少妇一区二区三区视频免付费| 制服丝袜激情欧洲亚洲| 欧美mv和日韩mv的网站| 国产精品天干天干在观线| 一区二区三区加勒比av| 久久精品999| 北岛玲一区二区三区四区| 555www色欧美视频| 国产欧美一区二区三区鸳鸯浴| 一区二区三区精品视频在线| 蜜桃一区二区三区在线观看| 99久久精品国产网站| 欧美日韩成人高清| 国产亚洲美州欧州综合国| 一区二区三区四区av| 国产精品原创巨作av| 精品美女在线观看| 黑人精品欧美一区二区蜜桃| 91亚洲大成网污www| 国产亚洲欧美日韩日本| 日韩精品一二三四| 精品国产乱码久久久久久老虎 | 久久久久久久精| 日韩一区精品字幕| 欧美电影免费观看完整版| 日本aⅴ免费视频一区二区三区| 在线影视一区二区三区| 亚洲免费在线视频| www.久久精品| 亚洲视频在线观看一区| 欧洲国内综合视频| 日本aⅴ精品一区二区三区| 欧美久久久久久蜜桃| 另类小说欧美激情| 久久免费国产精品| 色婷婷激情久久| 毛片一区二区三区| 国产精品国产三级国产普通话蜜臀| 国产成人免费在线视频| 一区二区不卡在线视频 午夜欧美不卡在| 国产乱子轮精品视频| 亚洲欧美在线aaa| 欧美日韩一卡二卡三卡| 国产在线不卡视频| 一区二区三区四区视频精品免费| 欧美一区二区三区在线视频| 国产成人综合在线观看| 日韩综合小视频| 1024成人网| 日韩一卡二卡三卡| 91黄视频在线| 福利一区二区在线| 国产一区在线不卡| 亚洲图片自拍偷拍| 亚洲欧美综合另类在线卡通| 精品国产制服丝袜高跟| 在线播放中文字幕一区| 91网站最新地址| 老司机午夜精品99久久| 手机精品视频在线观看| 亚洲女子a中天字幕| 国产色一区二区| 制服丝袜av成人在线看| 91久久奴性调教| 国产成人精品亚洲日本在线桃色| 亚洲成人av资源| 亚洲成人在线免费| 日韩精品一卡二卡三卡四卡无卡| 自拍偷在线精品自拍偷无码专区| 欧美一二三区在线| 欧美在线一二三| 在线亚洲精品福利网址导航| 国产老妇另类xxxxx| 日韩电影在线看| 亚洲国产综合色| 全国精品久久少妇| 亚洲午夜一区二区三区| 五月婷婷综合网| 国产精品乱码久久久久久| 欧美激情一区二区三区在线| 久久精品亚洲乱码伦伦中文 | 国产精品亚洲成人| 国产成人鲁色资源国产91色综| 韩国视频一区二区| 风流少妇一区二区| 欧美性猛交一区二区三区精品| 欧美亚洲国产一区二区三区| 欧美色图天堂网| 在线播放一区二区三区| 日韩欧美成人激情| 国产精品色噜噜| 日本欧美肥老太交大片| 久久er99热精品一区二区| 91九色02白丝porn| 精品一区二区三区久久| 国产夫妻精品视频| 丁香婷婷综合色啪| 欧美日韩一二区| 亚洲天堂久久久久久久| 蜜桃视频免费观看一区| 色婷婷一区二区三区四区| 日本韩国欧美在线| 欧美r级电影在线观看| 一区二区欧美视频| 不卡的电影网站| 国产精品久久久久久妇女6080| 五月激情丁香一区二区三区| 日本伦理一区二区| ...xxx性欧美| 欧美午夜精品一区二区蜜桃| 一区二区免费在线| 91精品国产综合久久久久久| 欧美综合天天夜夜久久| 久久综合色综合88| 欧美激情在线一区二区三区| 亚洲欧美综合另类在线卡通| 国产精品77777竹菊影视小说| 日韩欧美高清dvd碟片| 精品一区二区成人精品| 国产99久久久国产精品免费看| 中文字幕免费不卡在线| 宅男噜噜噜66一区二区66| 亚洲国产日产av| 欧美日韩高清一区| 午夜视频在线观看一区| 精品国产髙清在线看国产毛片| 国产成人亚洲综合a∨婷婷| 亚洲一区在线观看免费| 在线播放/欧美激情| 国产91色综合久久免费分享| 亚洲一区二区三区四区不卡| 国产亚洲短视频| 欧美中文字幕一区二区三区| 久久综合综合久久综合| 国产精品久久久一区麻豆最新章节| 欧美日韩在线精品一区二区三区激情 | 日韩一区二区高清| 国产激情一区二区三区桃花岛亚洲| 伊人性伊人情综合网| 亚洲欧美一区二区在线观看| 综合欧美一区二区三区| www国产精品av| 日韩视频免费观看高清完整版| 日韩一级大片在线观看| 欧美三级电影在线观看| 91网站最新网址| 韩国在线一区二区| 99久久综合国产精品| 国产一区日韩二区欧美三区| 香蕉av福利精品导航| 蜜臀精品久久久久久蜜臀| 丝袜脚交一区二区| 国产99久久久精品| 国产成人综合视频| 99综合影院在线| 在线观看国产日韩| 国产女人aaa级久久久级| 777xxx欧美| 国产精品久久久久国产精品日日| 中文字幕一区二区在线播放| 亚洲一区二三区| 亚洲h在线观看| 国产精品一区二区视频| 成人白浆超碰人人人人| 日韩欧美国产三级电影视频| 久久婷婷国产综合国色天香| 亚洲欧美一区二区不卡| 蜜桃精品视频在线| 91在线精品秘密一区二区| 国产成人一级电影| 91精品一区二区三区在线观看| 中文子幕无线码一区tr| 国产精品久久久久久久久免费丝袜 | 91精品婷婷国产综合久久性色 | 国产精品一二三在| 国产黄色精品视频| 精品国产自在久精品国产| 成人免费小视频| 一本大道综合伊人精品热热| 亚洲人吸女人奶水| 99re6这里只有精品视频在线观看| 9191国产精品| 欧美aⅴ一区二区三区视频| 成人ar影院免费观看视频| 欧美私模裸体表演在线观看| 五月激情六月综合| 精品国产一区二区三区久久久蜜月| 午夜精品一区在线观看| 欧美性受极品xxxx喷水| 麻豆国产精品一区二区三区| 欧美日韩成人激情|