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