This source file includes following definitions.
- enable_opl3_mode
- enter_4op_mode
- opl3_ioctl
- opl3_detect
- opl3_kill_note
- store_instr
- opl3_set_instr
- calc_vol
- set_voice_volume
- opl3_start_note
- freq_to_fnum
- opl3_command
- opl3_reset
- opl3_open
- opl3_close
- opl3_hw_control
- opl3_load_patch
- opl3_panning
- opl3_aftertouch
- opl3_controller
- opl3_patchmgr
- opl3_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #include "sound_config.h"
34
35 #if defined(CONFIGURE_SOUNDCARD) && !defined(EXCLUDE_YM3812)
36
37 #include "opl3.h"
38
39 #define MAX_VOICE 18
40 #define OFFS_4OP 11
41
42
43 static int opl3_enabled = 0;
44 static int left_address = 0x388, right_address = 0x388, both_address = 0;
45
46 static int nr_voices = 9;
47 static int logical_voices[MAX_VOICE] =
48 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
49
50 struct voice_info
51 {
52 unsigned char keyon_byte;
53 long bender;
54 long bender_range;
55 unsigned long orig_freq;
56 unsigned long current_freq;
57 int mode;
58 };
59
60 static struct voice_info voices[MAX_VOICE];
61
62 typedef struct sbi_instrument instr_array[SBFM_MAXINSTR];
63 static instr_array instrmap;
64 static struct sbi_instrument *active_instrument[MAX_VOICE] =
65 {NULL};
66
67 static struct synth_info fm_info =
68 {"AdLib", 0, SYNTH_TYPE_FM, FM_TYPE_ADLIB, 0, 9, 0, SBFM_MAXINSTR, 0};
69
70 static int already_initialized = 0;
71
72 static int opl3_ok = 0;
73 static int opl3_busy = 0;
74 static int fm_model = 0;
75
76 static int store_instr (int instr_no, struct sbi_instrument *instr);
77 static void freq_to_fnum (int freq, int *block, int *fnum);
78 static void opl3_command (int io_addr, const unsigned char addr, const unsigned char val);
79 static int opl3_kill_note (int dev, int voice, int velocity);
80 static unsigned char connection_mask = 0x00;
81
82 void
83 enable_opl3_mode (int left, int right, int both)
84 {
85 opl3_enabled = 1;
86 left_address = left;
87 right_address = right;
88 both_address = both;
89 fm_info.capabilities = SYNTH_CAP_OPL3;
90 fm_info.synth_subtype = FM_TYPE_OPL3;
91 }
92
93 static void
94 enter_4op_mode (void)
95 {
96 int i;
97 static int voices_4op[MAX_VOICE] =
98 {0, 1, 2, 9, 10, 11, 6, 7, 8, 15, 16, 17};
99
100 connection_mask = 0x3f;
101 opl3_command (right_address, CONNECTION_SELECT_REGISTER, 0x3f);
102
103 for (i = 0; i < 3; i++)
104 physical_voices[i].voice_mode = 4;
105 for (i = 3; i < 6; i++)
106 physical_voices[i].voice_mode = 0;
107
108 for (i = 9; i < 12; i++)
109 physical_voices[i].voice_mode = 4;
110 for (i = 12; i < 15; i++)
111 physical_voices[i].voice_mode = 0;
112
113 for (i = 0; i < 12; i++)
114 logical_voices[i] = voices_4op[i];
115 nr_voices = 12;
116 }
117
118 static int
119 opl3_ioctl (int dev,
120 unsigned int cmd, unsigned int arg)
121 {
122 switch (cmd)
123 {
124
125 case SNDCTL_FM_LOAD_INSTR:
126 {
127 struct sbi_instrument ins;
128
129 IOCTL_FROM_USER ((char *) &ins, (char *) arg, 0, sizeof (ins));
130
131 if (ins.channel < 0 || ins.channel >= SBFM_MAXINSTR)
132 {
133 printk ("FM Error: Invalid instrument number %d\n", ins.channel);
134 return RET_ERROR (EINVAL);
135 }
136
137 pmgr_inform (dev, PM_E_PATCH_LOADED, ins.channel, 0, 0, 0);
138 return store_instr (ins.channel, &ins);
139 }
140 break;
141
142 case SNDCTL_SYNTH_INFO:
143 fm_info.nr_voices = (nr_voices == 12) ? 6 : nr_voices;
144
145 IOCTL_TO_USER ((char *) arg, 0, &fm_info, sizeof (fm_info));
146 return 0;
147 break;
148
149 case SNDCTL_SYNTH_MEMAVL:
150 return 0x7fffffff;
151 break;
152
153 case SNDCTL_FM_4OP_ENABLE:
154 if (opl3_enabled)
155 enter_4op_mode ();
156 return 0;
157 break;
158
159 default:
160 return RET_ERROR (EINVAL);
161 }
162
163 }
164
165 int
166 opl3_detect (int ioaddr)
167 {
168
169
170
171
172
173
174
175
176
177
178
179 unsigned char stat1, stat2;
180 int i;
181
182 if (already_initialized)
183 {
184 return 0;
185 }
186
187 if (opl3_enabled)
188 ioaddr = left_address;
189
190 opl3_command (ioaddr, TIMER_CONTROL_REGISTER, TIMER1_MASK | TIMER2_MASK);
191 opl3_command (ioaddr, TIMER_CONTROL_REGISTER, IRQ_RESET);
192
193
194 stat1 = INB (ioaddr);
195
196 if ((stat1 & 0xE0) != 0x00)
197 {
198 return 0;
199 }
200
201 opl3_command (ioaddr, TIMER1_REGISTER, 0xff);
202 opl3_command (ioaddr, TIMER_CONTROL_REGISTER,
203 TIMER2_MASK | TIMER1_START);
204
205
206
207
208
209 for (i = 0; i < 50; i++)
210 tenmicrosec ();
211
212 stat2 = INB (ioaddr);
213
214
215
216 opl3_command (ioaddr, TIMER_CONTROL_REGISTER, TIMER1_MASK | TIMER2_MASK);
217 opl3_command (ioaddr, TIMER_CONTROL_REGISTER, IRQ_RESET);
218
219
220 if ((stat2 & 0xE0) != 0xc0)
221 {
222 return 0;
223 }
224
225
226
227 for (i = 0; i < 9; i++)
228 opl3_command (ioaddr, KEYON_BLOCK + i, 0);
229
230 opl3_command (ioaddr, TEST_REGISTER, ENABLE_WAVE_SELECT);
231 opl3_command (ioaddr, PERCUSSION_REGISTER, 0x00);
232
233 return 1;
234 }
235
236 static int
237 opl3_kill_note (int dev, int voice, int velocity)
238 {
239 struct physical_voice_info *map;
240
241 if (voice < 0 || voice >= nr_voices)
242 return 0;
243
244 map = &physical_voices[logical_voices[voice]];
245
246 DEB (printk ("Kill note %d\n", voice));
247
248 if (map->voice_mode == 0)
249 return 0;
250
251 opl3_command (map->ioaddr, KEYON_BLOCK + map->voice_num, voices[voice].keyon_byte & ~0x20);
252
253 voices[voice].keyon_byte = 0;
254 voices[voice].bender = 0;
255 voices[voice].bender_range = 200;
256 voices[voice].orig_freq = 0;
257 voices[voice].current_freq = 0;
258 voices[voice].mode = 0;
259
260 return 0;
261 }
262
263 #define HIHAT 0
264 #define CYMBAL 1
265 #define TOMTOM 2
266 #define SNARE 3
267 #define BDRUM 4
268 #define UNDEFINED TOMTOM
269 #define DEFAULT TOMTOM
270
271 static int
272 store_instr (int instr_no, struct sbi_instrument *instr)
273 {
274
275 if (instr->key != FM_PATCH && (instr->key != OPL3_PATCH || !opl3_enabled))
276 printk ("FM warning: Invalid patch format field (key) 0x%04x\n", instr->key);
277 memcpy ((char *) &(instrmap[instr_no]), (char *) instr, sizeof (*instr));
278
279 return 0;
280 }
281
282 static int
283 opl3_set_instr (int dev, int voice, int instr_no)
284 {
285 if (voice < 0 || voice >= nr_voices)
286 return 0;
287
288 if (instr_no < 0 || instr_no >= SBFM_MAXINSTR)
289 return 0;
290
291 active_instrument[voice] = &instrmap[instr_no];
292 return 0;
293 }
294
295
296
297
298
299
300
301
302
303
304 char fm_volume_table[128] =
305 {-64, -48, -40, -35, -32, -29, -27, -26,
306 -24, -23, -21, -20, -19, -18, -18, -17,
307 -16, -15, -15, -14, -13, -13, -12, -12,
308 -11, -11, -10, -10, -10, -9, -9, -8,
309 -8, -8, -7, -7, -7, -6, -6, -6,
310 -5, -5, -5, -5, -4, -4, -4, -4,
311 -3, -3, -3, -3, -2, -2, -2, -2,
312 -2, -1, -1, -1, -1, 0, 0, 0,
313 0, 0, 0, 1, 1, 1, 1, 1,
314 1, 2, 2, 2, 2, 2, 2, 2,
315 3, 3, 3, 3, 3, 3, 3, 4,
316 4, 4, 4, 4, 4, 4, 4, 5,
317 5, 5, 5, 5, 5, 5, 5, 5,
318 6, 6, 6, 6, 6, 6, 6, 6,
319 6, 7, 7, 7, 7, 7, 7, 7,
320 7, 7, 7, 8, 8, 8, 8, 8};
321
322 static void
323 calc_vol (unsigned char *regbyte, int volume)
324 {
325 int level = (~*regbyte & 0x3f);
326
327 if (level)
328 level += fm_volume_table[volume];
329
330 if (level > 0x3f)
331 level = 0x3f;
332 if (level < 0)
333 level = 0;
334
335 *regbyte = (*regbyte & 0xc0) | (~level & 0x3f);
336 }
337
338 static void
339 set_voice_volume (int voice, int volume)
340 {
341 unsigned char vol1, vol2, vol3, vol4;
342 struct sbi_instrument *instr;
343 struct physical_voice_info *map;
344
345 if (voice < 0 || voice >= nr_voices)
346 return;
347
348 map = &physical_voices[logical_voices[voice]];
349
350 instr = active_instrument[voice];
351
352 if (!instr)
353 instr = &instrmap[0];
354
355 if (instr->channel < 0)
356 return;
357
358 if (voices[voice].mode == 0)
359 return;
360
361 if (voices[voice].mode == 2)
362 {
363
364 vol1 = instr->operators[2];
365 vol2 = instr->operators[3];
366
367 if ((instr->operators[10] & 0x01))
368 {
369 calc_vol (&vol1, volume);
370 calc_vol (&vol2, volume);
371 }
372 else
373 {
374 calc_vol (&vol2, volume);
375 }
376
377 opl3_command (map->ioaddr, KSL_LEVEL + map->op[0], vol1);
378 opl3_command (map->ioaddr, KSL_LEVEL + map->op[1], vol2);
379 }
380 else
381 {
382 int connection;
383
384 vol1 = instr->operators[2];
385 vol2 = instr->operators[3];
386 vol3 = instr->operators[OFFS_4OP + 2];
387 vol4 = instr->operators[OFFS_4OP + 3];
388
389
390
391
392
393
394 connection = ((instr->operators[10] & 0x01) << 1) | (instr->operators[10 + OFFS_4OP] & 0x01);
395
396 switch (connection)
397 {
398 case 0:
399 calc_vol (&vol4, volume);
400 break;
401
402 case 1:
403 calc_vol (&vol2, volume);
404 calc_vol (&vol4, volume);
405 break;
406
407 case 2:
408 calc_vol (&vol1, volume);
409 calc_vol (&vol4, volume);
410 break;
411
412 case 3:
413 calc_vol (&vol1, volume);
414 calc_vol (&vol3, volume);
415 calc_vol (&vol4, volume);
416 break;
417
418 default: ;
419 }
420
421 opl3_command (map->ioaddr, KSL_LEVEL + map->op[0], vol1);
422 opl3_command (map->ioaddr, KSL_LEVEL + map->op[1], vol2);
423 opl3_command (map->ioaddr, KSL_LEVEL + map->op[2], vol3);
424 opl3_command (map->ioaddr, KSL_LEVEL + map->op[3], vol4);
425 }
426 }
427
428 static int
429 opl3_start_note (int dev, int voice, int note, int volume)
430 {
431 unsigned char data, fpc;
432 int block, fnum, freq, voice_mode;
433 struct sbi_instrument *instr;
434 struct physical_voice_info *map;
435
436 if (voice < 0 || voice >= nr_voices)
437 return 0;
438
439 map = &physical_voices[logical_voices[voice]];
440
441 if (map->voice_mode == 0)
442 return 0;
443
444 if (note == 255)
445 {
446 set_voice_volume (voice, volume);
447 return 0;
448 }
449
450
451 opl3_command (map->ioaddr, KSL_LEVEL + map->op[1], 0xff);
452 opl3_command (map->ioaddr, KSL_LEVEL + map->op[0], 0xff);
453
454 if (map->voice_mode == 4)
455 {
456 opl3_command (map->ioaddr, KSL_LEVEL + map->op[2], 0xff);
457 opl3_command (map->ioaddr, KSL_LEVEL + map->op[3], 0xff);
458 }
459
460 opl3_command (map->ioaddr, KEYON_BLOCK + map->voice_num, 0x00);
461
462 instr = active_instrument[voice];
463
464 if (!instr)
465 instr = &instrmap[0];
466
467 if (instr->channel < 0)
468 {
469 printk (
470 "OPL3: Initializing voice %d with undefined instrument\n",
471 voice);
472 return 0;
473 }
474
475 if (map->voice_mode == 2 && instr->key == OPL3_PATCH)
476 return 0;
477
478 voice_mode = map->voice_mode;
479
480 if (voice_mode == 4)
481 {
482 int voice_shift;
483
484 voice_shift = (map->ioaddr == left_address) ? 0 : 3;
485 voice_shift += map->voice_num;
486
487 if (instr->key != OPL3_PATCH)
488 {
489 voice_mode = 2;
490 connection_mask &= ~(1 << voice_shift);
491 }
492 else
493 {
494 connection_mask |= (1 << voice_shift);
495 }
496
497 opl3_command (right_address, CONNECTION_SELECT_REGISTER, connection_mask);
498 }
499
500
501 opl3_command (map->ioaddr, AM_VIB + map->op[0], instr->operators[0]);
502 opl3_command (map->ioaddr, AM_VIB + map->op[1], instr->operators[1]);
503
504
505 opl3_command (map->ioaddr, ATTACK_DECAY + map->op[0], instr->operators[4]);
506 opl3_command (map->ioaddr, ATTACK_DECAY + map->op[1], instr->operators[5]);
507
508
509 opl3_command (map->ioaddr, SUSTAIN_RELEASE + map->op[0], instr->operators[6]);
510 opl3_command (map->ioaddr, SUSTAIN_RELEASE + map->op[1], instr->operators[7]);
511
512
513 opl3_command (map->ioaddr, WAVE_SELECT + map->op[0], instr->operators[8]);
514 opl3_command (map->ioaddr, WAVE_SELECT + map->op[1], instr->operators[9]);
515
516
517 fpc = instr->operators[10];
518 if (!(fpc & 0x30))
519 fpc |= 0x30;
520 opl3_command (map->ioaddr, FEEDBACK_CONNECTION + map->voice_num,
521 fpc);
522
523
524
525
526
527 if (voice_mode == 4)
528 {
529
530
531 opl3_command (map->ioaddr, AM_VIB + map->op[2], instr->operators[OFFS_4OP + 0]);
532 opl3_command (map->ioaddr, AM_VIB + map->op[3], instr->operators[OFFS_4OP + 1]);
533
534
535 opl3_command (map->ioaddr, ATTACK_DECAY + map->op[2], instr->operators[OFFS_4OP + 4]);
536 opl3_command (map->ioaddr, ATTACK_DECAY + map->op[3], instr->operators[OFFS_4OP + 5]);
537
538
539 opl3_command (map->ioaddr, SUSTAIN_RELEASE + map->op[2], instr->operators[OFFS_4OP + 6]);
540 opl3_command (map->ioaddr, SUSTAIN_RELEASE + map->op[3], instr->operators[OFFS_4OP + 7]);
541
542
543 opl3_command (map->ioaddr, WAVE_SELECT + map->op[2], instr->operators[OFFS_4OP + 8]);
544 opl3_command (map->ioaddr, WAVE_SELECT + map->op[3], instr->operators[OFFS_4OP + 9]);
545
546
547 fpc = instr->operators[OFFS_4OP + 10];
548 if (!(fpc & 0x30))
549 fpc |= 0x30;
550 opl3_command (map->ioaddr, FEEDBACK_CONNECTION + map->voice_num + 3, fpc);
551 }
552
553 voices[voice].mode = voice_mode;
554
555 set_voice_volume (voice, volume);
556
557 freq = voices[voice].orig_freq = note_to_freq (note) / 1000;
558
559
560
561
562
563
564 freq = compute_finetune (voices[voice].orig_freq, voices[voice].bender, voices[voice].bender_range);
565 voices[voice].current_freq = freq;
566
567 freq_to_fnum (freq, &block, &fnum);
568
569
570
571 data = fnum & 0xff;
572 opl3_command (map->ioaddr, FNUM_LOW + map->voice_num, data);
573
574 data = 0x20 | ((block & 0x7) << 2) | ((fnum >> 8) & 0x3);
575 voices[voice].keyon_byte = data;
576 opl3_command (map->ioaddr, KEYON_BLOCK + map->voice_num, data);
577 if (voice_mode == 4)
578 opl3_command (map->ioaddr, KEYON_BLOCK + map->voice_num + 3, data);
579
580 return 0;
581 }
582
583 static void
584 freq_to_fnum (int freq, int *block, int *fnum)
585 {
586 int f, octave;
587
588
589
590
591 f = freq;
592
593 octave = 5;
594
595 if (f == 0)
596 octave = 0;
597 else if (f < 261)
598 {
599 while (f < 261)
600 {
601 octave--;
602 f <<= 1;
603 }
604 }
605 else if (f > 493)
606 {
607 while (f > 493)
608 {
609 octave++;
610 f >>= 1;
611 }
612 }
613
614 if (octave > 7)
615 octave = 7;
616
617 *fnum = freq * (1 << (20 - octave)) / 49716;
618 *block = octave;
619 }
620
621 static void
622 opl3_command (int io_addr, const unsigned char addr, const unsigned char val)
623 {
624 int i;
625
626
627
628
629
630
631 OUTB (addr, io_addr);
632
633 if (!opl3_enabled)
634 tenmicrosec ();
635 else
636 for (i = 0; i < 2; i++)
637 INB (io_addr);
638
639 OUTB (val, io_addr + 1);
640
641 if (!opl3_enabled)
642 {
643 tenmicrosec ();
644 tenmicrosec ();
645 tenmicrosec ();
646 }
647 else
648 for (i = 0; i < 2; i++)
649 INB (io_addr);
650 }
651
652 static void
653 opl3_reset (int dev)
654 {
655 int i;
656
657 for (i = 0; i < nr_voices; i++)
658 {
659 opl3_command (physical_voices[logical_voices[i]].ioaddr,
660 KSL_LEVEL + physical_voices[logical_voices[i]].op[0], 0xff);
661
662 opl3_command (physical_voices[logical_voices[i]].ioaddr,
663 KSL_LEVEL + physical_voices[logical_voices[i]].op[1], 0xff);
664
665 if (physical_voices[logical_voices[i]].voice_mode == 4)
666 {
667 opl3_command (physical_voices[logical_voices[i]].ioaddr,
668 KSL_LEVEL + physical_voices[logical_voices[i]].op[2], 0xff);
669
670 opl3_command (physical_voices[logical_voices[i]].ioaddr,
671 KSL_LEVEL + physical_voices[logical_voices[i]].op[3], 0xff);
672 }
673
674 opl3_kill_note (dev, i, 64);
675 }
676
677 if (opl3_enabled)
678 {
679 nr_voices = 18;
680
681 for (i = 0; i < 18; i++)
682 logical_voices[i] = i;
683
684 for (i = 0; i < 18; i++)
685 physical_voices[i].voice_mode = 2;
686
687 }
688
689 }
690
691 static int
692 opl3_open (int dev, int mode)
693 {
694 if (!opl3_ok)
695 return RET_ERROR (ENXIO);
696 if (opl3_busy)
697 return RET_ERROR (EBUSY);
698 opl3_busy = 1;
699
700 connection_mask = 0x00;
701 if (opl3_enabled)
702 opl3_command (right_address, CONNECTION_SELECT_REGISTER, connection_mask);
703 return 0;
704 }
705
706 static void
707 opl3_close (int dev)
708 {
709 opl3_busy = 0;
710 nr_voices = opl3_enabled ? 18 : 9;
711 fm_info.nr_drums = 0;
712 fm_info.perc_mode = 0;
713
714 opl3_reset (dev);
715 }
716
717 static void
718 opl3_hw_control (int dev, unsigned char *event)
719 {
720 }
721
722 static int
723 opl3_load_patch (int dev, int format, snd_rw_buf * addr,
724 int offs, int count, int pmgr_flag)
725 {
726 struct sbi_instrument ins;
727
728 if (count < sizeof (ins))
729 {
730 printk ("FM Error: Patch record too short\n");
731 return RET_ERROR (EINVAL);
732 }
733
734 COPY_FROM_USER (&((char *) &ins)[offs], (char *) addr, offs, sizeof (ins) - offs);
735
736 if (ins.channel < 0 || ins.channel >= SBFM_MAXINSTR)
737 {
738 printk ("FM Error: Invalid instrument number %d\n", ins.channel);
739 return RET_ERROR (EINVAL);
740 }
741 ins.key = format;
742
743 return store_instr (ins.channel, &ins);
744 }
745
746 static void
747 opl3_panning (int dev, int voice, int pressure)
748 {
749 }
750
751 #define SET_VIBRATO(cell) { \
752 tmp = instr->operators[(cell-1)+(((cell-1)/2)*OFFS_4OP)]; \
753 if (pressure > 110) \
754 tmp |= 0x40; \
755 opl3_command (map->ioaddr, AM_VIB + map->op[cell-1], tmp);}
756
757 static void
758 opl3_aftertouch (int dev, int voice, int pressure)
759 {
760 int tmp;
761 struct sbi_instrument *instr;
762 struct physical_voice_info *map;
763
764 if (voice < 0 || voice >= nr_voices)
765 return;
766
767 map = &physical_voices[logical_voices[voice]];
768
769 DEB (printk ("Aftertouch %d\n", voice));
770
771 if (map->voice_mode == 0)
772 return;
773
774
775
776
777
778 instr = active_instrument[voice];
779
780 if (!instr)
781 instr = &instrmap[0];
782
783 if (voices[voice].mode == 4)
784 {
785 int connection = ((instr->operators[10] & 0x01) << 1) | (instr->operators[10 + OFFS_4OP] & 0x01);
786
787 switch (connection)
788 {
789 case 0:
790 SET_VIBRATO (4);
791 break;
792
793 case 1:
794 SET_VIBRATO (2);
795 SET_VIBRATO (4);
796 break;
797
798 case 2:
799 SET_VIBRATO (1);
800 SET_VIBRATO (4);
801 break;
802
803 case 3:
804 SET_VIBRATO (1);
805 SET_VIBRATO (3);
806 SET_VIBRATO (4);
807 break;
808
809 }
810
811 }
812 else
813 {
814 SET_VIBRATO (1);
815
816 if ((instr->operators[10] & 0x01))
817 SET_VIBRATO (2);
818 }
819 }
820
821 #undef SET_VIBRATO
822
823 static void
824 opl3_controller (int dev, int voice, int ctrl_num, int value)
825 {
826 unsigned char data;
827 int block, fnum, freq;
828 struct physical_voice_info *map;
829
830 if (voice < 0 || voice >= nr_voices)
831 return;
832
833 map = &physical_voices[logical_voices[voice]];
834
835 if (map->voice_mode == 0)
836 return;
837
838 switch (ctrl_num)
839 {
840 case CTRL_PITCH_BENDER:
841 voices[voice].bender = value;
842 if (!value)
843 return;
844 if (!(voices[voice].keyon_byte & 0x20))
845 return;
846
847 freq = compute_finetune (voices[voice].orig_freq, voices[voice].bender, voices[voice].bender_range);
848 voices[voice].current_freq = freq;
849
850 freq_to_fnum (freq, &block, &fnum);
851
852 data = fnum & 0xff;
853 opl3_command (map->ioaddr, FNUM_LOW + map->voice_num, data);
854
855 data = 0x20 | ((block & 0x7) << 2) | ((fnum >> 8) & 0x3);
856
857 voices[voice].keyon_byte = data;
858 opl3_command (map->ioaddr, KEYON_BLOCK + map->voice_num, data);
859 break;
860
861 case CTRL_PITCH_BENDER_RANGE:
862 voices[voice].bender_range = value;
863 break;
864 }
865 }
866
867 static int
868 opl3_patchmgr (int dev, struct patmgr_info *rec)
869 {
870 return RET_ERROR (EINVAL);
871 }
872
873 static struct synth_operations opl3_operations =
874 {
875 &fm_info,
876 SYNTH_TYPE_FM,
877 FM_TYPE_ADLIB,
878 opl3_open,
879 opl3_close,
880 opl3_ioctl,
881 opl3_kill_note,
882 opl3_start_note,
883 opl3_set_instr,
884 opl3_reset,
885 opl3_hw_control,
886 opl3_load_patch,
887 opl3_aftertouch,
888 opl3_controller,
889 opl3_panning,
890 opl3_patchmgr
891 };
892
893 long
894 opl3_init (long mem_start)
895 {
896 int i;
897
898 synth_devs[num_synths++] = &opl3_operations;
899 fm_model = 0;
900 opl3_ok = 1;
901 if (opl3_enabled)
902 {
903 printk (" <Yamaha OPL-3 FM>");
904 fm_model = 2;
905 nr_voices = 18;
906 fm_info.nr_drums = 0;
907 fm_info.capabilities |= SYNTH_CAP_OPL3;
908 #ifndef SCO
909 strcpy (fm_info.name, "Yamaha OPL-3");
910 #endif
911
912 for (i = 0; i < 18; i++)
913 if (physical_voices[i].ioaddr == USE_LEFT)
914 physical_voices[i].ioaddr = left_address;
915 else
916 physical_voices[i].ioaddr = right_address;
917
918
919 opl3_command (right_address, OPL3_MODE_REGISTER, OPL3_ENABLE);
920 opl3_command (right_address, CONNECTION_SELECT_REGISTER, 0x00);
921
922 }
923 else
924 {
925 printk (" <Yamaha 2-OP FM>");
926 fm_model = 1;
927 nr_voices = 9;
928 fm_info.nr_drums = 0;
929
930 for (i = 0; i < 18; i++)
931 physical_voices[i].ioaddr = left_address;
932 };
933
934 already_initialized = 1;
935 for (i = 0; i < SBFM_MAXINSTR; i++)
936 instrmap[i].channel = -1;
937
938 return mem_start;
939 }
940
941 #endif