Lines Matching +full:vp +full:- +full:p
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) by Uros Bizjak <uros@kss-loka.si>
16 dev_dbg(((struct snd_opl3 *)(opl3))->card->dev, fmt, ##__VA_ARGS__)
21 static void snd_opl3_note_off_unsafe(void *p, int note, int vel,
26 * for i=0. This log-table converts a linear volume-scaling (0..127) to a
27 * logarithmic scaling as present in the FM-synthesizer chips. so : Volume
28 * 64 = 0 db = relative volume 0 and: Volume 32 = -6 db = relative
29 * volume -8 it was implemented as a table because it is only 128 bytes and
35 -63, -48, -40, -35, -32, -29, -27, -26,
36 -24, -23, -21, -20, -19, -18, -18, -17,
37 -16, -15, -15, -14, -13, -13, -12, -12,
38 -11, -11, -10, -10, -10, -9, -9, -8,
39 -8, -8, -7, -7, -7, -6, -6, -6,
40 -5, -5, -5, -5, -4, -4, -4, -4,
41 -3, -3, -3, -3, -2, -2, -2, -2,
42 -2, -1, -1, -1, -1, 0, 0, 0,
59 volume = (vel * chan->gm_volume * chan->gm_expression) / (127*127);
63 oldvol = OPL3_TOTAL_LEVEL_MASK - (*volbyte & OPL3_TOTAL_LEVEL_MASK);
71 n = OPL3_TOTAL_LEVEL_MASK - (newvol & OPL3_TOTAL_LEVEL_MASK);
81 305, 323, /* for pitch bending, -2 semitones */
89 int block = ((note / 12) & 0x07) - 1;
93 if (chan->midi_pitchbend) {
94 int pitchbend = chan->midi_pitchbend;
97 if (pitchbend < -0x2000)
98 pitchbend = -0x2000;
104 freq += ((opl3_note_table[idx+segment+1] - freq) *
123 for (i = 0; i < opl3->max_voices; i++)
124 buf[i] = str[opl3->voices[i].state + 1];
126 dev_dbg(opl3->card->dev, "time %.5i: %s [%.2i]: %s\n",
127 opl3->use_time, s, voice, buf);
139 struct snd_opl3_voice *vp, *vp2;
160 best[i].time = (unsigned int)(-1); /* XXX MAX_?INT really */
161 best[i].voice = -1;
165 for (i = 0; i < opl3->max_voices; i++) {
166 vp = &opl3->voices[i];
168 if (vp->state == SNDRV_OPL3_ST_NOT_AVAIL)
173 voice_time = vp->time;
184 if (vp->state)
189 vp2 = &opl3->voices[i + 3];
190 if (vp2->state == SNDRV_OPL3_ST_ON_2OP) {
193 voice_time = max(voice_time, vp2->time);
200 else if (vp->state)
204 if (vp->state)
207 if (voice_time < bp->time) {
208 bp->time = voice_time;
209 bp->voice = i;
216 dev_dbg(opl3->card->dev,
225 return -1;
228 /* ------------------------------ */
240 scoped_guard(spinlock_irqsave, &opl3->voice_lock) {
241 for (i = 0; i < opl3->max_voices; i++) {
242 struct snd_opl3_voice *vp = &opl3->voices[i];
243 if (vp->state > 0 && vp->note_off_check) {
244 if (vp->note_off == jiffies)
245 snd_opl3_note_off_unsafe(opl3, vp->note, 0,
246 vp->chan);
253 guard(spinlock_irqsave)(&opl3->sys_timer_lock);
255 mod_timer(&opl3->tlist, jiffies + 1); /* invoke again */
257 opl3->sys_timer_status = 0;
265 guard(spinlock_irqsave)(&opl3->sys_timer_lock);
266 if (! opl3->sys_timer_status) {
267 mod_timer(&opl3->tlist, jiffies + 1);
268 opl3->sys_timer_status = 1;
272 /* ------------------------------ */
282 void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)
288 struct snd_opl3_voice *vp, *vp2;
309 opl3 = p;
312 chan->number, chan->midi_program, note, vel);
316 if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) {
317 if (chan->drum_channel) {
322 bank = chan->gm_bank_select;
323 prg = chan->midi_program;
327 if (chan->number >= MAX_OPL3_VOICES)
332 prg = chan->midi_program;
335 guard(spinlock_irqsave)(&opl3->voice_lock);
347 fm = &patch->inst;
348 switch (patch->type) {
353 if (opl3->hardware >= OPL3_HW_OPL3) {
361 opl3_dbg(opl3, " --> OPL%i instrument: %s\n",
362 instr_4op ? 3 : 2, patch->name);
365 if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) {
369 voice = snd_opl3_oss_map[chan->number];
383 voice_offset = voice - MAX_OPL2_VOICES;
388 vp = &opl3->voices[voice];
389 if (vp->state > 0) {
391 reg_val = vp->keyon_reg & ~OPL3_KEYON_BIT;
392 opl3->command(opl3, opl3_reg, reg_val);
395 vp2 = &opl3->voices[voice + 3];
396 if (vp2->state > 0) {
399 reg_val = vp->keyon_reg & ~OPL3_KEYON_BIT;
400 opl3->command(opl3, opl3_reg, reg_val);
406 if ((opl3->connection_reg ^ connect_mask) & connect_mask) {
407 opl3->connection_reg |= connect_mask;
410 opl3->command(opl3, opl3_reg, opl3->connection_reg);
413 if ((opl3->connection_reg ^ ~connect_mask) & connect_mask) {
414 opl3->connection_reg &= ~connect_mask;
417 opl3->command(opl3, opl3_reg, opl3->connection_reg);
421 opl3_dbg(opl3, " --> setting OPL3 connection: 0x%x\n",
422 opl3->connection_reg);
428 vol_op[i] = fm->op[i].ksl_level;
430 connection = fm->feedback_connection[0] & 0x01;
433 connection |= fm->feedback_connection[1] & 0x01;
454 opl3_dbg(opl3, " --> programming operator %i\n", i);
458 reg_val = fm->op[i].am_vib;
460 opl3->command(opl3, opl3_reg, reg_val);
465 opl3->command(opl3, opl3_reg, reg_val);
468 reg_val = fm->op[i].attack_decay;
470 opl3->command(opl3, opl3_reg, reg_val);
473 reg_val = fm->op[i].sustain_release;
475 opl3->command(opl3, opl3_reg, reg_val);
478 reg_val = fm->op[i].wave_select;
480 opl3->command(opl3, opl3_reg, reg_val);
483 /* Set operator feedback and 2op inter-operator connection */
484 reg_val = fm->feedback_connection[0];
487 if (chan->gm_pan < 43)
489 if (chan->gm_pan > 85)
492 opl3->command(opl3, opl3_reg, reg_val);
495 /* Set 4op inter-operator connection */
496 reg_val = fm->feedback_connection[1] & OPL3_CONNECTION_BIT;
499 if (chan->gm_pan < 43)
501 if (chan->gm_pan > 85)
505 opl3->command(opl3, opl3_reg, reg_val);
513 if (fm->fix_key)
514 note = fm->fix_key;
518 if (fm->trnsps)
519 note += (fm->trnsps - 64);
525 opl3->command(opl3, opl3_reg, fnum);
527 opl3->voices[voice].keyon_reg = blocknum;
532 opl3_dbg(opl3, " --> trigger voice %i\n", voice);
535 opl3->command(opl3, opl3_reg, blocknum);
538 if (fm->fix_dur) {
539 opl3->voices[voice].note_off = jiffies +
540 (fm->fix_dur * HZ) / 100;
542 opl3->voices[voice].note_off_check = 1;
544 opl3->voices[voice].note_off_check = 0;
547 extra_prg = (extra_prg) ? 0 : fm->modes;
550 vp->time = opl3->use_time++;
551 vp->note = key;
552 vp->chan = chan;
555 vp->state = SNDRV_OPL3_ST_ON_4OP;
557 vp2 = &opl3->voices[voice + 3];
558 vp2->time = opl3->use_time++;
559 vp2->note = key;
560 vp2->chan = chan;
561 vp2->state = SNDRV_OPL3_ST_NOT_AVAIL;
563 if (vp->state == SNDRV_OPL3_ST_ON_4OP) {
565 vp2 = &opl3->voices[voice + 3];
566 vp2->time = opl3->use_time++;
567 vp2->state = SNDRV_OPL3_ST_OFF;
569 vp->state = SNDRV_OPL3_ST_ON_2OP;
581 prg = extra_prg - 128 + 35 - 1;
584 prg = extra_prg - 1;
597 struct snd_opl3_voice *vp, *vp2;
602 vp = &opl3->voices[voice];
610 voice_offset = voice - MAX_OPL2_VOICES;
614 opl3_dbg(opl3, " --> kill voice %i\n", voice);
617 opl3->command(opl3, opl3_reg, vp->keyon_reg);
620 vp->time = opl3->use_time++;
622 if (vp->state == SNDRV_OPL3_ST_ON_4OP) {
623 vp2 = &opl3->voices[voice + 3];
625 vp2->time = opl3->use_time++;
626 vp2->state = SNDRV_OPL3_ST_OFF;
628 vp->state = SNDRV_OPL3_ST_OFF;
638 static void snd_opl3_note_off_unsafe(void *p, int note, int vel,
644 struct snd_opl3_voice *vp;
646 opl3 = p;
649 chan->number, chan->midi_program, note);
651 if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) {
652 if (chan->drum_channel && use_internal_drums) {
658 for (voice = 0; voice < opl3->max_voices; voice++) {
659 vp = &opl3->voices[voice];
660 if (vp->state > 0 && vp->chan == chan && vp->note == note) {
666 if (chan->number < MAX_OPL3_VOICES) {
667 voice = snd_opl3_oss_map[chan->number];
673 void snd_opl3_note_off(void *p, int note, int vel,
676 struct snd_opl3 *opl3 = p;
678 guard(spinlock_irqsave)(&opl3->voice_lock);
679 snd_opl3_note_off_unsafe(p, note, vel, chan);
685 void snd_opl3_key_press(void *p, int note, int vel, struct snd_midi_channel *chan)
687 opl3_dbg(p, "Key pressure, ch#: %i, inst#: %i\n",
688 chan->number, chan->midi_program);
694 void snd_opl3_terminate_note(void *p, int note, struct snd_midi_channel *chan)
696 opl3_dbg(p, "Terminate note, ch#: %i, inst#: %i\n",
697 chan->number, chan->midi_program);
708 struct snd_opl3_voice *vp;
713 vp = &opl3->voices[voice];
714 if (vp->chan == NULL)
724 voice_offset = voice - MAX_OPL2_VOICES;
727 snd_opl3_calc_pitch(&fnum, &blocknum, vp->note, vp->chan);
731 opl3->command(opl3, opl3_reg, fnum);
733 vp->keyon_reg = blocknum;
740 opl3->command(opl3, opl3_reg, blocknum);
742 vp->time = opl3->use_time++;
751 struct snd_opl3_voice *vp;
753 guard(spinlock_irqsave)(&opl3->voice_lock);
755 if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) {
756 for (voice = 0; voice < opl3->max_voices; voice++) {
757 vp = &opl3->voices[voice];
758 if (vp->state > 0 && vp->chan == chan) {
764 if (chan->number < MAX_OPL3_VOICES) {
765 voice = snd_opl3_oss_map[chan->number];
775 void snd_opl3_control(void *p, int type, struct snd_midi_channel *chan)
779 opl3 = p;
781 type, chan->number, chan->midi_program);
785 if (chan->control[MIDI_CTL_MSB_MODWHEEL] > 63)
786 opl3->drum_reg |= OPL3_VIBRATO_DEPTH;
788 opl3->drum_reg &= ~OPL3_VIBRATO_DEPTH;
789 opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION,
790 opl3->drum_reg);
793 if (chan->control[MIDI_CTL_E2_TREMOLO_DEPTH] > 63)
794 opl3->drum_reg |= OPL3_TREMOLO_DEPTH;
796 opl3->drum_reg &= ~OPL3_TREMOLO_DEPTH;
797 opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION,
798 opl3->drum_reg);
809 void snd_opl3_nrpn(void *p, struct snd_midi_channel *chan,
812 opl3_dbg(p, "NRPN, ch#: %i, inst#: %i\n",
813 chan->number, chan->midi_program);
819 void snd_opl3_sysex(void *p, unsigned char *buf, int len,
822 opl3_dbg(p, "SYSEX\n");