1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include "opl3_voice.h"
23
24extern char snd_opl3_regmap[MAX_OPL2_VOICES][4];
25
26static char snd_opl3_drum_table[47] =
27{
28 OPL3_BASSDRUM_ON, OPL3_BASSDRUM_ON, OPL3_HIHAT_ON,
29 OPL3_SNAREDRUM_ON, OPL3_HIHAT_ON, OPL3_SNAREDRUM_ON,
30 OPL3_BASSDRUM_ON, OPL3_HIHAT_ON, OPL3_BASSDRUM_ON,
31 OPL3_HIHAT_ON, OPL3_TOMTOM_ON, OPL3_HIHAT_ON,
32 OPL3_TOMTOM_ON, OPL3_TOMTOM_ON, OPL3_CYMBAL_ON,
33
34 OPL3_TOMTOM_ON, OPL3_CYMBAL_ON, OPL3_CYMBAL_ON,
35 OPL3_CYMBAL_ON, OPL3_CYMBAL_ON, OPL3_CYMBAL_ON,
36 OPL3_HIHAT_ON, OPL3_CYMBAL_ON, OPL3_TOMTOM_ON,
37 OPL3_CYMBAL_ON, OPL3_TOMTOM_ON, OPL3_TOMTOM_ON,
38 OPL3_HIHAT_ON, OPL3_TOMTOM_ON, OPL3_TOMTOM_ON,
39
40 OPL3_TOMTOM_ON, OPL3_TOMTOM_ON, OPL3_TOMTOM_ON,
41 OPL3_TOMTOM_ON, OPL3_HIHAT_ON, OPL3_HIHAT_ON,
42 OPL3_HIHAT_ON, OPL3_HIHAT_ON, OPL3_TOMTOM_ON,
43 OPL3_TOMTOM_ON, OPL3_TOMTOM_ON, OPL3_TOMTOM_ON,
44 OPL3_TOMTOM_ON, OPL3_TOMTOM_ON, OPL3_TOMTOM_ON,
45 OPL3_CYMBAL_ON, OPL3_CYMBAL_ON
46};
47
48struct snd_opl3_drum_voice {
49 int voice;
50 int op;
51 unsigned char am_vib;
52 unsigned char ksl_level;
53 unsigned char attack_decay;
54 unsigned char sustain_release;
55 unsigned char feedback_connection;
56 unsigned char wave_select;
57};
58
59struct snd_opl3_drum_note {
60 int voice;
61 unsigned char fnum;
62 unsigned char octave_f;
63 unsigned char feedback_connection;
64};
65
66static struct snd_opl3_drum_voice bass_op0 = {6, 0, 0x00, 0x32, 0xf8, 0x66, 0x30, 0x00};
67static struct snd_opl3_drum_voice bass_op1 = {6, 1, 0x00, 0x03, 0xf6, 0x57, 0x30, 0x00};
68static struct snd_opl3_drum_note bass_note = {6, 0x90, 0x09};
69
70static struct snd_opl3_drum_voice hihat = {7, 0, 0x00, 0x03, 0xf0, 0x06, 0x20, 0x00};
71
72static struct snd_opl3_drum_voice snare = {7, 1, 0x00, 0x03, 0xf0, 0x07, 0x20, 0x02};
73static struct snd_opl3_drum_note snare_note = {7, 0xf4, 0x0d};
74
75static struct snd_opl3_drum_voice tomtom = {8, 0, 0x02, 0x03, 0xf0, 0x06, 0x10, 0x00};
76static struct snd_opl3_drum_note tomtom_note = {8, 0xf4, 0x09};
77
78static struct snd_opl3_drum_voice cymbal = {8, 1, 0x04, 0x03, 0xf0, 0x06, 0x10, 0x00};
79
80
81
82
83static void snd_opl3_drum_voice_set(struct snd_opl3 *opl3,
84 struct snd_opl3_drum_voice *data)
85{
86 unsigned char op_offset = snd_opl3_regmap[data->voice][data->op];
87 unsigned char voice_offset = data->voice;
88 unsigned short opl3_reg;
89
90
91 opl3_reg = OPL3_LEFT | (OPL3_REG_AM_VIB + op_offset);
92 opl3->command(opl3, opl3_reg, data->am_vib);
93
94
95 opl3_reg = OPL3_LEFT | (OPL3_REG_KSL_LEVEL + op_offset);
96 opl3->command(opl3, opl3_reg, data->ksl_level);
97
98
99 opl3_reg = OPL3_LEFT | (OPL3_REG_ATTACK_DECAY + op_offset);
100 opl3->command(opl3, opl3_reg, data->attack_decay);
101
102
103 opl3_reg = OPL3_LEFT | (OPL3_REG_SUSTAIN_RELEASE + op_offset);
104 opl3->command(opl3, opl3_reg, data->sustain_release);
105
106
107 opl3_reg = OPL3_LEFT | (OPL3_REG_FEEDBACK_CONNECTION + voice_offset);
108 opl3->command(opl3, opl3_reg, data->feedback_connection);
109
110
111 opl3_reg = OPL3_LEFT | (OPL3_REG_WAVE_SELECT + op_offset);
112 opl3->command(opl3, opl3_reg, data->wave_select);
113}
114
115
116
117
118static void snd_opl3_drum_note_set(struct snd_opl3 *opl3,
119 struct snd_opl3_drum_note *data)
120{
121 unsigned char voice_offset = data->voice;
122 unsigned short opl3_reg;
123
124
125 opl3_reg = OPL3_LEFT | (OPL3_REG_FNUM_LOW + voice_offset);
126 opl3->command(opl3, opl3_reg, data->fnum);
127
128
129 opl3_reg = OPL3_LEFT | (OPL3_REG_KEYON_BLOCK + voice_offset);
130 opl3->command(opl3, opl3_reg, data->octave_f);
131}
132
133
134
135
136static void snd_opl3_drum_vol_set(struct snd_opl3 *opl3,
137 struct snd_opl3_drum_voice *data,
138 int vel, struct snd_midi_channel *chan)
139{
140 unsigned char op_offset = snd_opl3_regmap[data->voice][data->op];
141 unsigned char voice_offset = data->voice;
142 unsigned char reg_val;
143 unsigned short opl3_reg;
144
145
146 reg_val = data->ksl_level;
147 snd_opl3_calc_volume(®_val, vel, chan);
148 opl3_reg = OPL3_LEFT | (OPL3_REG_KSL_LEVEL + op_offset);
149 opl3->command(opl3, opl3_reg, reg_val);
150
151
152
153 reg_val = data->feedback_connection | OPL3_STEREO_BITS;
154 if (chan->gm_pan < 43)
155 reg_val &= ~OPL3_VOICE_TO_RIGHT;
156 if (chan->gm_pan > 85)
157 reg_val &= ~OPL3_VOICE_TO_LEFT;
158 opl3_reg = OPL3_LEFT | (OPL3_REG_FEEDBACK_CONNECTION + voice_offset);
159 opl3->command(opl3, opl3_reg, reg_val);
160}
161
162
163
164
165void snd_opl3_load_drums(struct snd_opl3 *opl3)
166{
167 snd_opl3_drum_voice_set(opl3, &bass_op0);
168 snd_opl3_drum_voice_set(opl3, &bass_op1);
169 snd_opl3_drum_note_set(opl3, &bass_note);
170
171 snd_opl3_drum_voice_set(opl3, &hihat);
172
173 snd_opl3_drum_voice_set(opl3, &snare);
174 snd_opl3_drum_note_set(opl3, &snare_note);
175
176 snd_opl3_drum_voice_set(opl3, &tomtom);
177 snd_opl3_drum_note_set(opl3, &tomtom_note);
178
179 snd_opl3_drum_voice_set(opl3, &cymbal);
180}
181
182
183
184
185void snd_opl3_drum_switch(struct snd_opl3 *opl3, int note, int vel, int on_off,
186 struct snd_midi_channel *chan)
187{
188 unsigned char drum_mask;
189 struct snd_opl3_drum_voice *drum_voice;
190
191 if (!(opl3->drum_reg & OPL3_PERCUSSION_ENABLE))
192 return;
193
194 if ((note < 35) || (note > 81))
195 return;
196 drum_mask = snd_opl3_drum_table[note - 35];
197
198 if (on_off) {
199 switch (drum_mask) {
200 case OPL3_BASSDRUM_ON:
201 drum_voice = &bass_op1;
202 break;
203 case OPL3_HIHAT_ON:
204 drum_voice = &hihat;
205 break;
206 case OPL3_SNAREDRUM_ON:
207 drum_voice = &snare;
208 break;
209 case OPL3_TOMTOM_ON:
210 drum_voice = &tomtom;
211 break;
212 case OPL3_CYMBAL_ON:
213 drum_voice = &cymbal;
214 break;
215 default:
216 drum_voice = &tomtom;
217 }
218
219 snd_opl3_drum_vol_set(opl3, drum_voice, vel, chan);
220 opl3->drum_reg |= drum_mask;
221 } else {
222 opl3->drum_reg &= ~drum_mask;
223 }
224 opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION,
225 opl3->drum_reg);
226}
227