Lines Matching +full:vp +full:- +full:p
1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Copyright (c) 1999-2000 Takashi Iwai <tiwai@suse.de>
21 * macro evaluates its args more than once, so changed to upper-case.
34 static void terminate_voice(struct snd_emux *emu, struct snd_emux_voice *vp, int free);
35 static void update_voice(struct snd_emux *emu, struct snd_emux_voice *vp, int update);
36 static void setup_voice(struct snd_emux_voice *vp);
37 static int calc_pan(struct snd_emux_voice *vp);
38 static int calc_volume(struct snd_emux_voice *vp);
39 static int calc_pitch(struct snd_emux_voice *vp);
46 snd_emux_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)
50 struct snd_emux_voice *vp;
54 port = p;
58 emu = port->emu;
59 if (snd_BUG_ON(!emu || !emu->ops.get_voice || !emu->ops.trigger))
70 if (zp && zp->v.exclusiveClass)
71 exclusive_note_off(emu, port, zp->v.exclusiveClass);
79 guard(spinlock_irqsave)(&emu->voice_lock);
88 vp = emu->ops.get_voice(emu, port);
89 if (vp == NULL || vp->ch < 0)
91 if (STATE_IS_PLAYING(vp->state))
92 emu->ops.terminate(vp);
94 vp->time = emu->use_time++;
95 vp->chan = chan;
96 vp->port = port;
97 vp->key = key;
98 vp->note = note;
99 vp->velocity = vel;
100 vp->zone = table[i];
101 if (vp->zone->sample)
102 vp->block = vp->zone->sample->block;
104 vp->block = NULL;
106 setup_voice(vp);
108 vp->state = SNDRV_EMUX_ST_STANDBY;
109 if (emu->ops.prepare) {
110 vp->state = SNDRV_EMUX_ST_OFF;
111 if (emu->ops.prepare(vp) >= 0)
112 vp->state = SNDRV_EMUX_ST_STANDBY;
117 for (i = 0; i < emu->max_voices; i++) {
118 vp = &emu->voices[i];
119 if (vp->state == SNDRV_EMUX_ST_STANDBY &&
120 vp->chan == chan) {
121 emu->ops.trigger(vp);
122 vp->state = SNDRV_EMUX_ST_ON;
123 vp->ontime = jiffies; /* remember the trigger timing */
128 if (port->port_mode == SNDRV_EMUX_PORT_MODE_OSS_SYNTH) {
130 struct snd_emux_effect_table *fx = chan->private;
132 fx->flag[EMUX_FX_SAMPLE_START] = 0;
133 fx->flag[EMUX_FX_COARSE_SAMPLE_START] = 0;
143 snd_emux_note_off(void *p, int note, int vel, struct snd_midi_channel *chan)
147 struct snd_emux_voice *vp;
150 port = p;
154 emu = port->emu;
155 if (snd_BUG_ON(!emu || !emu->ops.release))
158 guard(spinlock_irqsave)(&emu->voice_lock);
159 for (ch = 0; ch < emu->max_voices; ch++) {
160 vp = &emu->voices[ch];
161 if (STATE_IS_PLAYING(vp->state) &&
162 vp->chan == chan && vp->key == note) {
163 vp->state = SNDRV_EMUX_ST_RELEASED;
164 if (vp->ontime == jiffies) {
165 /* if note-off is sent too shortly after
166 * note-on, emuX engine cannot produce the sound
170 vp->state = SNDRV_EMUX_ST_PENDING;
171 if (! emu->timer_active) {
172 mod_timer(&emu->tlist, jiffies + 1);
173 emu->timer_active = 1;
177 emu->ops.release(vp);
185 * release the pending note-offs
190 struct snd_emux_voice *vp;
193 guard(spinlock_irqsave)(&emu->voice_lock);
194 for (ch = 0; ch < emu->max_voices; ch++) {
195 vp = &emu->voices[ch];
196 if (vp->state == SNDRV_EMUX_ST_PENDING) {
197 if (vp->ontime == jiffies)
200 emu->ops.release(vp);
201 vp->state = SNDRV_EMUX_ST_RELEASED;
206 mod_timer(&emu->tlist, jiffies + 1);
207 emu->timer_active = 1;
209 emu->timer_active = 0;
216 snd_emux_key_press(void *p, int note, int vel, struct snd_midi_channel *chan)
220 struct snd_emux_voice *vp;
223 port = p;
227 emu = port->emu;
228 if (snd_BUG_ON(!emu || !emu->ops.update))
231 guard(spinlock_irqsave)(&emu->voice_lock);
232 for (ch = 0; ch < emu->max_voices; ch++) {
233 vp = &emu->voices[ch];
234 if (vp->state == SNDRV_EMUX_ST_ON &&
235 vp->chan == chan && vp->key == note) {
236 vp->velocity = vel;
237 update_voice(emu, vp, SNDRV_EMUX_UPDATE_VOLUME);
250 struct snd_emux_voice *vp;
256 emu = port->emu;
257 if (snd_BUG_ON(!emu || !emu->ops.update))
260 guard(spinlock_irqsave)(&emu->voice_lock);
261 for (i = 0; i < emu->max_voices; i++) {
262 vp = &emu->voices[i];
263 if (vp->chan == chan)
264 update_voice(emu, vp, update);
275 struct snd_emux_voice *vp;
281 emu = port->emu;
282 if (snd_BUG_ON(!emu || !emu->ops.update))
285 guard(spinlock_irqsave)(&emu->voice_lock);
286 for (i = 0; i < emu->max_voices; i++) {
287 vp = &emu->voices[i];
288 if (vp->port == port)
289 update_voice(emu, vp, update);
299 snd_emux_control(void *p, int type, struct snd_midi_channel *chan)
303 port = p;
320 if (chan->control[type] >= 64)
321 snd_emux_send_effect(port, chan, EMUX_FX_CUTOFF, -160,
342 if (port->chset.midi_mode == SNDRV_MIDI_MODE_XG) {
349 * terminate note - if free flag is true, free the terminated voice
355 struct snd_emux_voice *vp;
357 guard(spinlock_irqsave)(&emu->voice_lock);
358 for (i = 0; i < emu->max_voices; i++) {
359 vp = &emu->voices[i];
360 if (STATE_IS_PLAYING(vp->state) && vp->chan == chan &&
361 vp->key == note)
362 terminate_voice(emu, vp, free);
368 * terminate note - exported for midi emulation
371 snd_emux_terminate_note(void *p, int note, struct snd_midi_channel *chan)
376 port = p;
380 emu = port->emu;
381 if (snd_BUG_ON(!emu || !emu->ops.terminate))
395 struct snd_emux_voice *vp;
397 guard(spinlock_irqsave)(&emu->voice_lock);
398 for (i = 0; i < emu->max_voices; i++) {
399 vp = &emu->voices[i];
400 if (STATE_IS_PLAYING(vp->state))
401 terminate_voice(emu, vp, 0);
402 if (vp->state == SNDRV_EMUX_ST_OFF) {
403 if (emu->ops.free_voice)
404 emu->ops.free_voice(vp);
405 if (emu->ops.reset)
406 emu->ops.reset(emu, i);
408 vp->time = 0;
411 emu->use_time = 0;
424 struct snd_emux_voice *vp;
428 emu = port->emu;
429 if (snd_BUG_ON(!emu || !emu->ops.terminate))
432 guard(spinlock_irqsave)(&emu->voice_lock);
433 for (i = 0; i < emu->max_voices; i++) {
434 vp = &emu->voices[i];
435 if (STATE_IS_PLAYING(vp->state) &&
436 vp->port == port)
437 terminate_voice(emu, vp, 0);
438 if (vp->state == SNDRV_EMUX_ST_OFF) {
439 if (emu->ops.free_voice)
440 emu->ops.free_voice(vp);
441 if (emu->ops.reset)
442 emu->ops.reset(emu, i);
455 struct snd_emux_voice *vp;
458 guard(spinlock_irqsave)(&emu->voice_lock);
459 for (i = 0; i < emu->max_voices; i++) {
460 vp = &emu->voices[i];
461 if (STATE_IS_PLAYING(vp->state) && vp->port == port &&
462 vp->reg.exclusiveClass == exclass) {
463 terminate_voice(emu, vp, 0);
473 terminate_voice(struct snd_emux *emu, struct snd_emux_voice *vp, int free)
475 emu->ops.terminate(vp);
476 vp->time = emu->use_time++;
477 vp->chan = NULL;
478 vp->port = NULL;
479 vp->zone = NULL;
480 vp->block = NULL;
481 vp->state = SNDRV_EMUX_ST_OFF;
482 if (free && emu->ops.free_voice)
483 emu->ops.free_voice(vp);
491 update_voice(struct snd_emux *emu, struct snd_emux_voice *vp, int update)
493 if (!STATE_IS_PLAYING(vp->state))
496 if (vp->chan == NULL || vp->port == NULL)
499 calc_volume(vp);
501 calc_pitch(vp);
503 if (! calc_pan(vp) && (update == SNDRV_EMUX_UPDATE_PAN))
506 emu->ops.update(vp, update);
526 setup_voice(struct snd_emux_voice *vp)
532 vp->reg = vp->zone->v;
535 snd_emux_setup_effect(vp);
539 vp->apan = -1;
540 vp->avol = -1;
541 vp->apitch = -1;
543 calc_volume(vp);
544 calc_pitch(vp);
545 calc_pan(vp);
547 parm = &vp->reg.parm;
550 if (LO_BYTE(parm->modatkhld) >= 0x80 && parm->moddelay >= 0x8000) {
551 parm->moddelay = 0xbfff;
552 pitch = (HI_BYTE(parm->pefe) << 4) + vp->apitch;
556 vp->ftarget = parm->cutoff + LO_BYTE(parm->pefe);
557 LIMITVALUE(vp->ftarget, 0, 255);
558 vp->ftarget <<= 8;
560 vp->ftarget = parm->cutoff;
561 vp->ftarget <<= 8;
562 pitch = vp->apitch;
567 vp->ptarget = 1 << (pitch >> 12);
568 if (pitch & 0x800) vp->ptarget += (vp->ptarget*0x102e)/0x2710;
569 if (pitch & 0x400) vp->ptarget += (vp->ptarget*0x764)/0x2710;
570 if (pitch & 0x200) vp->ptarget += (vp->ptarget*0x389)/0x2710;
571 vp->ptarget += (vp->ptarget >> 1);
572 if (vp->ptarget > 0xffff) vp->ptarget = 0xffff;
574 vp->ptarget = 0xffff;
576 if (LO_BYTE(parm->modatkhld) >= 0x80) {
577 parm->modatkhld &= ~0xff;
578 parm->modatkhld |= 0x7f;
582 vp->vtarget = 0;
584 if (LO_BYTE(parm->volatkhld) >= 0x80 && parm->voldelay >= 0x8000) {
585 parm->voldelay = 0xbfff;
586 vp->vtarget = voltarget[vp->avol % 0x10] >> (vp->avol >> 4);
590 if (LO_BYTE(parm->volatkhld) >= 0x80) {
591 parm->volatkhld &= ~0xff;
592 parm->volatkhld |= 0x7f;
619 calc_pan(struct snd_emux_voice *vp)
621 struct snd_midi_channel *chan = vp->chan;
625 if (vp->reg.fixpan > 0) /* 0-127 */
626 pan = 255 - (int)vp->reg.fixpan * 2;
628 pan = chan->control[MIDI_CTL_MSB_PAN] - 64;
629 if (vp->reg.pan >= 0) /* 0-127 */
630 pan += vp->reg.pan - 64;
631 pan = 127 - (int)pan * 2;
635 if (vp->emu->linear_panning) {
637 if (pan != vp->apan) {
638 vp->apan = pan;
640 vp->aaux = 0xff;
642 vp->aaux = (-pan) & 0xff;
648 if (vp->apan != (int)pan_volumes[pan]) {
649 vp->apan = pan_volumes[pan];
650 vp->aaux = pan_volumes[255 - pan];
663 * minimum when 255 (-96dB or silence).
666 /* tables for volume->attenuation calculation */
720 calc_volume(struct snd_emux_voice *vp)
724 struct snd_midi_channel *chan = vp->chan;
725 struct snd_emux_port *port = vp->port;
727 expression_vol = chan->control[MIDI_CTL_MSB_EXPRESSION];
728 LIMITMAX(vp->velocity, 127);
730 if (port->port_mode == SNDRV_EMUX_PORT_MODE_OSS_SYNTH) {
731 /* 0 - 127 */
732 main_vol = chan->control[MIDI_CTL_MSB_MAIN_VOLUME];
733 vol = (vp->velocity * main_vol * expression_vol) / (127*127);
734 vol = vol * vp->reg.amplitude / 127;
742 main_vol = chan->control[MIDI_CTL_MSB_MAIN_VOLUME] * vp->reg.amplitude / 127;
745 vol = voltab1[main_vol] + voltab2[vp->velocity];
747 vol += vp->reg.attenuation;
748 vol += ((0x100 - vol) * expressiontab[expression_vol])/128;
751 master_vol = port->chset.gs_master_volume;
754 vol += port->volume_atten;
757 if (chan->private) {
758 struct snd_emux_effect_table *fx = chan->private;
759 vol += fx->val[EMUX_FX_ATTEN];
764 if (vp->avol == vol)
767 vp->avol = vol;
769 && LO_BYTE(vp->reg.parm.volatkhld) < 0x7d) {
771 if (vp->velocity < 70)
774 atten = vp->velocity;
775 vp->acutoff = (atten * vp->reg.parm.cutoff + 0xa0) >> 7;
777 vp->acutoff = vp->reg.parm.cutoff;
791 calc_pitch(struct snd_emux_voice *vp)
793 struct snd_midi_channel *chan = vp->chan;
797 if (vp->reg.fixkey >= 0) {
798 offset = (vp->reg.fixkey - vp->reg.root) * 4096 / 12;
800 offset = (vp->note - vp->reg.root) * 4096 / 12;
802 offset = (offset * vp->reg.scaleTuning) / 100;
803 offset += vp->reg.tune * 4096 / 1200;
804 if (chan->midi_pitchbend != 0) {
806 offset += chan->midi_pitchbend * chan->gm_rpn_pitch_bend_range / 3072;
810 * coarse = -8192 to 8192 (100 cent per 128)
811 * fine = -8192 to 8192 (max=100cent)
814 offset += chan->gm_rpn_coarse_tuning * 4096 / (12 * 128);
815 offset += chan->gm_rpn_fine_tuning / 24;
819 if (chan->private) {
820 struct snd_emux_effect_table *fx = chan->private;
821 if (fx->flag[EMUX_FX_INIT_PITCH])
822 offset += fx->val[EMUX_FX_INIT_PITCH];
827 offset += 0xe000 + vp->reg.rate_offset;
828 if (vp->emu->ops.get_pitch_shift)
829 offset += vp->emu->ops.get_pitch_shift(vp->emu);
831 if (offset == vp->apitch)
833 vp->apitch = offset;
845 switch (port->chset.midi_mode) {
847 val = chan->control[MIDI_CTL_MSB_BANK];
850 return chan->control[MIDI_CTL_LSB_BANK];
853 if (chan->drum_channel)
856 return chan->control[MIDI_CTL_MSB_BANK];
859 if (chan->drum_channel)
861 return chan->control[MIDI_CTL_MSB_BANK];
877 preset = chan->midi_program;
880 def_preset = port->ctrls[EMUX_MD_DEF_DRUM];
884 def_bank = port->ctrls[EMUX_MD_DEF_BANK];
887 return snd_soundfont_search_zone(emu->sflist, notep, vel, preset, bank,
897 struct snd_emux_voice *vp;
900 guard(spinlock_irqsave)(&emu->voice_lock);
901 for (i = 0; i < emu->max_voices; i++) {
902 vp = &emu->voices[i];
903 vp->ch = -1; /* not used */
904 vp->state = SNDRV_EMUX_ST_OFF;
905 vp->chan = NULL;
906 vp->port = NULL;
907 vp->time = 0;
908 vp->emu = emu;
909 vp->hw = emu->hw;
917 guard(spinlock_irqsave)(&emu->voice_lock);
918 if (emu->voices[voice].state == SNDRV_EMUX_ST_OFF)
919 emu->voices[voice].state = SNDRV_EMUX_ST_LOCKED;
921 dev_warn(emu->card->dev,
923 voice, emu->voices[voice].state);
932 guard(spinlock_irqsave)(&emu->voice_lock);
933 if (emu->voices[voice].state == SNDRV_EMUX_ST_LOCKED)
934 emu->voices[voice].state = SNDRV_EMUX_ST_OFF;
936 dev_warn(emu->card->dev,
938 voice, emu->voices[voice].state);