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