gus_simple.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /*
  2. * Routines for Gravis UltraSound soundcards - Simple instrument handlers
  3. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <sound/driver.h>
  22. #include <linux/time.h>
  23. #include <sound/core.h>
  24. #include <sound/gus.h>
  25. #include "gus_tables.h"
  26. /*
  27. *
  28. */
  29. static void interrupt_wave(struct snd_gus_card *gus, struct snd_gus_voice *voice);
  30. static void interrupt_volume(struct snd_gus_card *gus, struct snd_gus_voice *voice);
  31. static void interrupt_effect(struct snd_gus_card *gus, struct snd_gus_voice *voice);
  32. static void sample_start(struct snd_gus_card *gus, struct snd_gus_voice *voice, snd_seq_position_t position);
  33. static void sample_stop(struct snd_gus_card *gus, struct snd_gus_voice *voice, int mode);
  34. static void sample_freq(struct snd_gus_card *gus, struct snd_gus_voice *voice, snd_seq_frequency_t freq);
  35. static void sample_volume(struct snd_gus_card *card, struct snd_gus_voice *voice, struct snd_seq_ev_volume *volume);
  36. static void sample_loop(struct snd_gus_card *card, struct snd_gus_voice *voice, struct snd_seq_ev_loop *loop);
  37. static void sample_pos(struct snd_gus_card *card, struct snd_gus_voice *voice, snd_seq_position_t position);
  38. static void sample_private1(struct snd_gus_card *card, struct snd_gus_voice *voice, unsigned char *data);
  39. static struct snd_gus_sample_ops sample_ops = {
  40. sample_start,
  41. sample_stop,
  42. sample_freq,
  43. sample_volume,
  44. sample_loop,
  45. sample_pos,
  46. sample_private1
  47. };
  48. #if 0
  49. static void note_stop(struct snd_gus_card *gus, struct snd_gus_voice *voice, int wait);
  50. static void note_wait(struct snd_gus_card *gus, struct snd_gus_voice *voice);
  51. static void note_off(struct snd_gus_card *gus, struct snd_gus_voice *voice);
  52. static void note_volume(struct snd_gus_card *card, struct snd_gus_voice *voice);
  53. static void note_pitchbend(struct snd_gus_card *card, struct snd_gus_voice *voice);
  54. static void note_vibrato(struct snd_gus_card *card, struct snd_gus_voice *voice);
  55. static void note_tremolo(struct snd_gus_card *card, struct snd_gus_voice *voice);
  56. static struct snd_gus_note_handlers note_commands = {
  57. note_stop,
  58. note_wait,
  59. note_off,
  60. note_volume,
  61. note_pitchbend,
  62. note_vibrato,
  63. note_tremolo
  64. };
  65. static void chn_trigger_down(struct snd_gus_card *card, ultra_channel_t *channel, ultra_instrument_t *instrument, unsigned char note, unsigned char velocity, unsigned char priority );
  66. static void chn_trigger_up( ultra_card_t *card, ultra_note_t *note );
  67. static void chn_control( ultra_card_t *card, ultra_channel_t *channel, unsigned short p1, unsigned short p2 );
  68. static struct ULTRA_STRU_INSTRUMENT_CHANNEL_COMMANDS channel_commands = {
  69. chn_trigger_down,
  70. chn_trigger_up,
  71. chn_control
  72. };
  73. #endif
  74. static void do_volume_envelope(struct snd_gus_card *card, struct snd_gus_voice *voice);
  75. static void do_pan_envelope(struct snd_gus_card *card, struct snd_gus_voice *voice);
  76. /*
  77. *
  78. */
  79. static void interrupt_wave(struct snd_gus_card *gus, struct snd_gus_voice *voice)
  80. {
  81. spin_lock(&gus->event_lock);
  82. snd_gf1_stop_voice(gus, voice->number);
  83. spin_lock(&gus->reg_lock);
  84. snd_gf1_select_voice(gus, voice->number);
  85. snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, 0);
  86. spin_unlock(&gus->reg_lock);
  87. voice->flags &= ~SNDRV_GF1_VFLG_RUNNING;
  88. spin_unlock(&gus->event_lock);
  89. }
  90. static void interrupt_volume(struct snd_gus_card *gus, struct snd_gus_voice *voice)
  91. {
  92. spin_lock(&gus->event_lock);
  93. if (voice->flags & SNDRV_GF1_VFLG_RUNNING)
  94. do_volume_envelope(gus, voice);
  95. else
  96. snd_gf1_stop_voice(gus, voice->number);
  97. spin_unlock(&gus->event_lock);
  98. }
  99. static void interrupt_effect(struct snd_gus_card *gus, struct snd_gus_voice *voice)
  100. {
  101. spin_lock(&gus->event_lock);
  102. if ((voice->flags & (SNDRV_GF1_VFLG_RUNNING|SNDRV_GF1_VFLG_EFFECT_TIMER1)) ==
  103. (SNDRV_GF1_VFLG_RUNNING|SNDRV_GF1_VFLG_EFFECT_TIMER1))
  104. do_pan_envelope(gus, voice);
  105. spin_unlock(&gus->event_lock);
  106. }
  107. /*
  108. *
  109. */
  110. static void do_volume_envelope(struct snd_gus_card *gus, struct snd_gus_voice *voice)
  111. {
  112. unsigned short next, rate, old_volume;
  113. int program_next_ramp;
  114. unsigned long flags;
  115. if (!gus->gf1.volume_ramp) {
  116. spin_lock_irqsave(&gus->reg_lock, flags);
  117. snd_gf1_select_voice(gus, voice->number);
  118. snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
  119. snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, voice->gf1_volume);
  120. /* printk("gf1_volume = 0x%x\n", voice->gf1_volume); */
  121. spin_unlock_irqrestore(&gus->reg_lock, flags);
  122. return;
  123. }
  124. program_next_ramp = 0;
  125. rate = next = 0;
  126. while (1) {
  127. program_next_ramp = 0;
  128. rate = next = 0;
  129. switch (voice->venv_state) {
  130. case VENV_BEFORE:
  131. voice->venv_state = VENV_ATTACK;
  132. voice->venv_value_next = 0;
  133. spin_lock_irqsave(&gus->reg_lock, flags);
  134. snd_gf1_select_voice(gus, voice->number);
  135. snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
  136. snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, SNDRV_GF1_MIN_VOLUME);
  137. spin_unlock_irqrestore(&gus->reg_lock, flags);
  138. break;
  139. case VENV_ATTACK:
  140. voice->venv_state = VENV_SUSTAIN;
  141. program_next_ramp++;
  142. next = 255;
  143. rate = gus->gf1.volume_ramp;
  144. break;
  145. case VENV_SUSTAIN:
  146. voice->venv_state = VENV_RELEASE;
  147. spin_lock_irqsave(&gus->reg_lock, flags);
  148. snd_gf1_select_voice(gus, voice->number);
  149. snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
  150. snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, ((int)voice->gf1_volume * (int)voice->venv_value_next) / 255);
  151. spin_unlock_irqrestore(&gus->reg_lock, flags);
  152. return;
  153. case VENV_RELEASE:
  154. voice->venv_state = VENV_DONE;
  155. program_next_ramp++;
  156. next = 0;
  157. rate = gus->gf1.volume_ramp;
  158. break;
  159. case VENV_DONE:
  160. snd_gf1_stop_voice(gus, voice->number);
  161. voice->flags &= ~SNDRV_GF1_VFLG_RUNNING;
  162. return;
  163. case VENV_VOLUME:
  164. program_next_ramp++;
  165. next = voice->venv_value_next;
  166. rate = gus->gf1.volume_ramp;
  167. voice->venv_state = voice->venv_state_prev;
  168. break;
  169. }
  170. voice->venv_value_next = next;
  171. if (!program_next_ramp)
  172. continue;
  173. spin_lock_irqsave(&gus->reg_lock, flags);
  174. snd_gf1_select_voice(gus, voice->number);
  175. snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL);
  176. old_volume = snd_gf1_read16(gus, SNDRV_GF1_VW_VOLUME) >> 8;
  177. if (!rate) {
  178. spin_unlock_irqrestore(&gus->reg_lock, flags);
  179. continue;
  180. }
  181. next = (((int)voice->gf1_volume * (int)next) / 255) >> 8;
  182. if (old_volume < SNDRV_GF1_MIN_OFFSET)
  183. old_volume = SNDRV_GF1_MIN_OFFSET;
  184. if (next < SNDRV_GF1_MIN_OFFSET)
  185. next = SNDRV_GF1_MIN_OFFSET;
  186. if (next > SNDRV_GF1_MAX_OFFSET)
  187. next = SNDRV_GF1_MAX_OFFSET;
  188. if (old_volume == next) {
  189. spin_unlock_irqrestore(&gus->reg_lock, flags);
  190. continue;
  191. }
  192. voice->volume_control &= ~0xc3;
  193. voice->volume_control |= 0x20;
  194. if (old_volume > next) {
  195. snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_START, next);
  196. snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_END, old_volume);
  197. voice->volume_control |= 0x40;
  198. } else {
  199. snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_START, old_volume);
  200. snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_END, next);
  201. }
  202. snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_RATE, rate);
  203. snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, voice->volume_control);
  204. if (!gus->gf1.enh_mode) {
  205. snd_gf1_delay(gus);
  206. snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, voice->volume_control);
  207. }
  208. spin_unlock_irqrestore(&gus->reg_lock, flags);
  209. return;
  210. }
  211. }
  212. static void do_pan_envelope(struct snd_gus_card *gus, struct snd_gus_voice *voice)
  213. {
  214. unsigned long flags;
  215. unsigned char old_pan;
  216. #if 0
  217. snd_gf1_select_voice(gus, voice->number);
  218. printk(" -%i- do_pan_envelope - flags = 0x%x (0x%x -> 0x%x)\n",
  219. voice->number,
  220. voice->flags,
  221. voice->gf1_pan,
  222. snd_gf1_i_read8(gus, SNDRV_GF1_VB_PAN) & 0x0f);
  223. #endif
  224. if (gus->gf1.enh_mode) {
  225. voice->flags &= ~(SNDRV_GF1_VFLG_EFFECT_TIMER1|SNDRV_GF1_VFLG_PAN);
  226. return;
  227. }
  228. if (!gus->gf1.smooth_pan) {
  229. spin_lock_irqsave(&gus->reg_lock, flags);
  230. snd_gf1_select_voice(gus, voice->number);
  231. snd_gf1_write8(gus, SNDRV_GF1_VB_PAN, voice->gf1_pan);
  232. spin_unlock_irqrestore(&gus->reg_lock, flags);
  233. return;
  234. }
  235. if (!(voice->flags & SNDRV_GF1_VFLG_PAN)) /* before */
  236. voice->flags |= SNDRV_GF1_VFLG_EFFECT_TIMER1|SNDRV_GF1_VFLG_PAN;
  237. spin_lock_irqsave(&gus->reg_lock, flags);
  238. snd_gf1_select_voice(gus, voice->number);
  239. old_pan = snd_gf1_read8(gus, SNDRV_GF1_VB_PAN) & 0x0f;
  240. if (old_pan > voice->gf1_pan )
  241. old_pan--;
  242. if (old_pan < voice->gf1_pan)
  243. old_pan++;
  244. snd_gf1_write8(gus, SNDRV_GF1_VB_PAN, old_pan);
  245. spin_unlock_irqrestore(&gus->reg_lock, flags);
  246. if (old_pan == voice->gf1_pan) /* the goal was reached */
  247. voice->flags &= ~(SNDRV_GF1_VFLG_EFFECT_TIMER1|SNDRV_GF1_VFLG_PAN);
  248. #if 0
  249. snd_gf1_select_voice(gus, voice->number);
  250. printk(" -%i- (1) do_pan_envelope - flags = 0x%x (0x%x -> 0x%x)\n",
  251. voice->number,
  252. voice->flags,
  253. voice->gf1_pan,
  254. snd_gf1_i_read8(gus, GF1_VB_PAN) & 0x0f);
  255. #endif
  256. }
  257. static void set_enhanced_pan(struct snd_gus_card *gus, struct snd_gus_voice *voice, unsigned short pan)
  258. {
  259. unsigned long flags;
  260. unsigned short vlo, vro;
  261. vlo = SNDRV_GF1_ATTEN((SNDRV_GF1_ATTEN_TABLE_SIZE-1) - pan);
  262. vro = SNDRV_GF1_ATTEN(pan);
  263. if (pan != SNDRV_GF1_ATTEN_TABLE_SIZE - 1 && pan != 0) {
  264. vlo >>= 1;
  265. vro >>= 1;
  266. }
  267. vlo <<= 4;
  268. vro <<= 4;
  269. #if 0
  270. printk("vlo = 0x%x (0x%x), vro = 0x%x (0x%x)\n",
  271. vlo, snd_gf1_i_read16(gus, GF1_VW_OFFSET_LEFT),
  272. vro, snd_gf1_i_read16(gus, GF1_VW_OFFSET_RIGHT));
  273. #endif
  274. spin_lock_irqsave(&gus->reg_lock, flags);
  275. snd_gf1_select_voice(gus, voice->number);
  276. snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_LEFT_FINAL, vlo);
  277. snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_RIGHT_FINAL, vro);
  278. spin_unlock_irqrestore(&gus->reg_lock, flags);
  279. voice->vlo = vlo;
  280. voice->vro = vro;
  281. }
  282. /*
  283. *
  284. */
  285. static void sample_start(struct snd_gus_card *gus, struct snd_gus_voice *voice, snd_seq_position_t position)
  286. {
  287. unsigned long flags;
  288. unsigned int begin, addr, addr_end, addr_start;
  289. int w_16;
  290. struct simple_instrument *simple;
  291. struct snd_seq_kinstr *instr;
  292. instr = snd_seq_instr_find(gus->gf1.ilist, &voice->instr, 0, 1);
  293. if (instr == NULL)
  294. return;
  295. voice->instr = instr->instr; /* copy ID to speedup aliases */
  296. simple = KINSTR_DATA(instr);
  297. begin = simple->address.memory << 4;
  298. w_16 = simple->format & SIMPLE_WAVE_16BIT ? 0x04 : 0;
  299. addr_start = simple->loop_start;
  300. if (simple->format & SIMPLE_WAVE_LOOP) {
  301. addr_end = simple->loop_end;
  302. } else {
  303. addr_end = (simple->size << 4) - (w_16 ? 40 : 24);
  304. }
  305. if (simple->format & SIMPLE_WAVE_BACKWARD) {
  306. addr = simple->loop_end;
  307. if (position < simple->loop_end)
  308. addr -= position;
  309. } else {
  310. addr = position;
  311. }
  312. voice->control = 0x00;
  313. voice->mode = 0x20; /* enable offset registers */
  314. if (simple->format & SIMPLE_WAVE_16BIT)
  315. voice->control |= 0x04;
  316. if (simple->format & SIMPLE_WAVE_BACKWARD)
  317. voice->control |= 0x40;
  318. if (simple->format & SIMPLE_WAVE_LOOP) {
  319. voice->control |= 0x08;
  320. } else {
  321. voice->control |= 0x20;
  322. }
  323. if (simple->format & SIMPLE_WAVE_BIDIR)
  324. voice->control |= 0x10;
  325. if (simple->format & SIMPLE_WAVE_ULAW)
  326. voice->mode |= 0x40;
  327. if (w_16) {
  328. addr = ((addr << 1) & ~0x1f) | (addr & 0x0f);
  329. addr_start = ((addr_start << 1) & ~0x1f) | (addr_start & 0x0f);
  330. addr_end = ((addr_end << 1) & ~0x1f) | (addr_end & 0x0f);
  331. }
  332. addr += begin;
  333. addr_start += begin;
  334. addr_end += begin;
  335. snd_gf1_stop_voice(gus, voice->number);
  336. spin_lock_irqsave(&gus->reg_lock, flags);
  337. snd_gf1_select_voice(gus, voice->number);
  338. snd_gf1_write16(gus, SNDRV_GF1_VW_FREQUENCY, voice->fc_register + voice->fc_lfo);
  339. voice->venv_state = VENV_BEFORE;
  340. voice->volume_control = 0x03;
  341. snd_gf1_write_addr(gus, SNDRV_GF1_VA_START, addr_start, w_16);
  342. snd_gf1_write_addr(gus, SNDRV_GF1_VA_END, addr_end, w_16);
  343. snd_gf1_write_addr(gus, SNDRV_GF1_VA_CURRENT, addr, w_16);
  344. if (!gus->gf1.enh_mode) {
  345. snd_gf1_write8(gus, SNDRV_GF1_VB_PAN, voice->gf1_pan);
  346. } else {
  347. snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_LEFT, voice->vlo);
  348. snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_LEFT_FINAL, voice->vlo);
  349. snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_RIGHT, voice->vro);
  350. snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_RIGHT_FINAL, voice->vro);
  351. snd_gf1_write8(gus, SNDRV_GF1_VB_ACCUMULATOR, voice->effect_accumulator);
  352. snd_gf1_write16(gus, SNDRV_GF1_VW_EFFECT_VOLUME, voice->gf1_effect_volume);
  353. snd_gf1_write16(gus, SNDRV_GF1_VW_EFFECT_VOLUME_FINAL, voice->gf1_effect_volume);
  354. }
  355. spin_unlock_irqrestore(&gus->reg_lock, flags);
  356. do_volume_envelope(gus, voice);
  357. spin_lock_irqsave(&gus->reg_lock, flags);
  358. snd_gf1_select_voice(gus, voice->number);
  359. if (gus->gf1.enh_mode)
  360. snd_gf1_write8(gus, SNDRV_GF1_VB_MODE, voice->mode);
  361. snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, voice->control);
  362. if (!gus->gf1.enh_mode) {
  363. snd_gf1_delay(gus);
  364. snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, voice->control );
  365. }
  366. spin_unlock_irqrestore(&gus->reg_lock, flags);
  367. #if 0
  368. snd_gf1_print_voice_registers(gus);
  369. #endif
  370. voice->flags |= SNDRV_GF1_VFLG_RUNNING;
  371. snd_seq_instr_free_use(gus->gf1.ilist, instr);
  372. }
  373. static void sample_stop(struct snd_gus_card *gus, struct snd_gus_voice *voice, int mode)
  374. {
  375. unsigned char control;
  376. unsigned long flags;
  377. if (!(voice->flags & SNDRV_GF1_VFLG_RUNNING))
  378. return;
  379. switch (mode) {
  380. default:
  381. if (gus->gf1.volume_ramp > 0) {
  382. if (voice->venv_state < VENV_RELEASE) {
  383. voice->venv_state = VENV_RELEASE;
  384. do_volume_envelope(gus, voice);
  385. }
  386. }
  387. if (mode != SAMPLE_STOP_VENVELOPE) {
  388. snd_gf1_stop_voice(gus, voice->number);
  389. spin_lock_irqsave(&gus->reg_lock, flags);
  390. snd_gf1_select_voice(gus, voice->number);
  391. snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, SNDRV_GF1_MIN_VOLUME);
  392. spin_unlock_irqrestore(&gus->reg_lock, flags);
  393. voice->flags &= ~SNDRV_GF1_VFLG_RUNNING;
  394. }
  395. break;
  396. case SAMPLE_STOP_LOOP: /* disable loop only */
  397. spin_lock_irqsave(&gus->reg_lock, flags);
  398. snd_gf1_select_voice(gus, voice->number);
  399. control = snd_gf1_read8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL);
  400. control &= ~(0x83 | 0x04);
  401. control |= 0x20;
  402. snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, control);
  403. spin_unlock_irqrestore(&gus->reg_lock, flags);
  404. break;
  405. }
  406. }
  407. static void sample_freq(struct snd_gus_card *gus, struct snd_gus_voice *voice, snd_seq_frequency_t freq)
  408. {
  409. unsigned long flags;
  410. spin_lock_irqsave(&gus->reg_lock, flags);
  411. voice->fc_register = snd_gf1_translate_freq(gus, freq);
  412. snd_gf1_select_voice(gus, voice->number);
  413. snd_gf1_write16(gus, SNDRV_GF1_VW_FREQUENCY, voice->fc_register + voice->fc_lfo);
  414. spin_unlock_irqrestore(&gus->reg_lock, flags);
  415. }
  416. static void sample_volume(struct snd_gus_card *gus, struct snd_gus_voice *voice, struct snd_seq_ev_volume *volume)
  417. {
  418. if (volume->volume >= 0) {
  419. volume->volume &= 0x3fff;
  420. voice->gf1_volume = snd_gf1_lvol_to_gvol_raw(volume->volume << 2) << 4;
  421. voice->venv_state_prev = VENV_SUSTAIN;
  422. voice->venv_state = VENV_VOLUME;
  423. do_volume_envelope(gus, voice);
  424. }
  425. if (volume->lr >= 0) {
  426. volume->lr &= 0x3fff;
  427. if (!gus->gf1.enh_mode) {
  428. voice->gf1_pan = (volume->lr >> 10) & 15;
  429. if (!gus->gf1.full_range_pan) {
  430. if (voice->gf1_pan == 0)
  431. voice->gf1_pan++;
  432. if (voice->gf1_pan == 15)
  433. voice->gf1_pan--;
  434. }
  435. voice->flags &= ~SNDRV_GF1_VFLG_PAN; /* before */
  436. do_pan_envelope(gus, voice);
  437. } else {
  438. set_enhanced_pan(gus, voice, volume->lr >> 7);
  439. }
  440. }
  441. }
  442. static void sample_loop(struct snd_gus_card *gus, struct snd_gus_voice *voice, struct snd_seq_ev_loop *loop)
  443. {
  444. unsigned long flags;
  445. int w_16 = voice->control & 0x04;
  446. unsigned int begin, addr_start, addr_end;
  447. struct simple_instrument *simple;
  448. struct snd_seq_kinstr *instr;
  449. #if 0
  450. printk("voice_loop: start = 0x%x, end = 0x%x\n", loop->start, loop->end);
  451. #endif
  452. instr = snd_seq_instr_find(gus->gf1.ilist, &voice->instr, 0, 1);
  453. if (instr == NULL)
  454. return;
  455. voice->instr = instr->instr; /* copy ID to speedup aliases */
  456. simple = KINSTR_DATA(instr);
  457. begin = simple->address.memory;
  458. addr_start = loop->start;
  459. addr_end = loop->end;
  460. addr_start = (((addr_start << 1) & ~0x1f) | (addr_start & 0x0f)) + begin;
  461. addr_end = (((addr_end << 1) & ~0x1f) | (addr_end & 0x0f)) + begin;
  462. spin_lock_irqsave(&gus->reg_lock, flags);
  463. snd_gf1_select_voice(gus, voice->number);
  464. snd_gf1_write_addr(gus, SNDRV_GF1_VA_START, addr_start, w_16);
  465. snd_gf1_write_addr(gus, SNDRV_GF1_VA_END, addr_end, w_16);
  466. spin_unlock_irqrestore(&gus->reg_lock, flags);
  467. snd_seq_instr_free_use(gus->gf1.ilist, instr);
  468. }
  469. static void sample_pos(struct snd_gus_card *gus, struct snd_gus_voice *voice, snd_seq_position_t position)
  470. {
  471. unsigned long flags;
  472. int w_16 = voice->control & 0x04;
  473. unsigned int begin, addr;
  474. struct simple_instrument *simple;
  475. struct snd_seq_kinstr *instr;
  476. #if 0
  477. printk("voice_loop: start = 0x%x, end = 0x%x\n", loop->start, loop->end);
  478. #endif
  479. instr = snd_seq_instr_find(gus->gf1.ilist, &voice->instr, 0, 1);
  480. if (instr == NULL)
  481. return;
  482. voice->instr = instr->instr; /* copy ID to speedup aliases */
  483. simple = KINSTR_DATA(instr);
  484. begin = simple->address.memory;
  485. addr = (((position << 1) & ~0x1f) | (position & 0x0f)) + begin;
  486. spin_lock_irqsave(&gus->reg_lock, flags);
  487. snd_gf1_select_voice(gus, voice->number);
  488. snd_gf1_write_addr(gus, SNDRV_GF1_VA_CURRENT, addr, w_16);
  489. spin_unlock_irqrestore(&gus->reg_lock, flags);
  490. snd_seq_instr_free_use(gus->gf1.ilist, instr);
  491. }
  492. #if 0
  493. static unsigned char get_effects_mask( ultra_card_t *card, int value )
  494. {
  495. if ( value > 7 ) return 0;
  496. if ( card -> gf1.effects && card -> gf1.effects -> chip_type == ULTRA_EFFECT_CHIP_INTERWAVE )
  497. return card -> gf1.effects -> chip.interwave.voice_output[ value ];
  498. return 0;
  499. }
  500. #endif
  501. static void sample_private1(struct snd_gus_card *card, struct snd_gus_voice *voice, unsigned char *data)
  502. {
  503. #if 0
  504. unsigned long flags;
  505. unsigned char uc;
  506. switch ( *data ) {
  507. case ULTRA_PRIV1_IW_EFFECT:
  508. uc = get_effects_mask( card, ultra_get_byte( data, 4 ) );
  509. uc |= get_effects_mask( card, ultra_get_byte( data, 4 ) >> 4 );
  510. uc |= get_effects_mask( card, ultra_get_byte( data, 5 ) );
  511. uc |= get_effects_mask( card, ultra_get_byte( data, 5 ) >> 4 );
  512. voice -> data.simple.effect_accumulator = uc;
  513. voice -> data.simple.effect_volume = ultra_translate_voice_volume( card, ultra_get_word( data, 2 ) ) << 4;
  514. if ( !card -> gf1.enh_mode ) return;
  515. if ( voice -> flags & VFLG_WAIT_FOR_START ) return;
  516. if ( voice -> flags & VFLG_RUNNING )
  517. {
  518. CLI( &flags );
  519. gf1_select_voice( card, voice -> number );
  520. ultra_write8( card, GF1_VB_ACCUMULATOR, voice -> data.simple.effect_accumulator );
  521. ultra_write16( card, GF1_VW_EFFECT_VOLUME_FINAL, voice -> data.simple.effect_volume );
  522. STI( &flags );
  523. }
  524. break;
  525. case ULTRA_PRIV1_IW_LFO:
  526. ultra_lfo_command( card, voice -> number, data );
  527. }
  528. #endif
  529. }
  530. #if 0
  531. /*
  532. *
  533. */
  534. static void note_stop( ultra_card_t *card, ultra_voice_t *voice, int wait )
  535. {
  536. }
  537. static void note_wait( ultra_card_t *card, ultra_voice_t *voice )
  538. {
  539. }
  540. static void note_off( ultra_card_t *card, ultra_voice_t *voice )
  541. {
  542. }
  543. static void note_volume( ultra_card_t *card, ultra_voice_t *voice )
  544. {
  545. }
  546. static void note_pitchbend( ultra_card_t *card, ultra_voice_t *voice )
  547. {
  548. }
  549. static void note_vibrato( ultra_card_t *card, ultra_voice_t *voice )
  550. {
  551. }
  552. static void note_tremolo( ultra_card_t *card, ultra_voice_t *voice )
  553. {
  554. }
  555. /*
  556. *
  557. */
  558. static void chn_trigger_down( ultra_card_t *card, ultra_channel_t *channel, ultra_instrument_t *instrument, unsigned char note, unsigned char velocity, unsigned char priority )
  559. {
  560. }
  561. static void chn_trigger_up( ultra_card_t *card, ultra_note_t *note )
  562. {
  563. }
  564. static void chn_control( ultra_card_t *card, ultra_channel_t *channel, unsigned short p1, unsigned short p2 )
  565. {
  566. }
  567. /*
  568. *
  569. */
  570. #endif
  571. void snd_gf1_simple_init(struct snd_gus_voice *voice)
  572. {
  573. voice->handler_wave = interrupt_wave;
  574. voice->handler_volume = interrupt_volume;
  575. voice->handler_effect = interrupt_effect;
  576. voice->volume_change = NULL;
  577. voice->sample_ops = &sample_ops;
  578. }