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