Lines Matching +full:0 +full:- +full:127

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.
23 …efine LIMITVALUE(x, a, b) do { if ((x) < (a)) (x) = (a); else if ((x) > (b)) (x) = (b); } while (0)
24 #define LIMITMAX(x, a) do {if ((x) > (a)) (x) = (a); } while (0)
59 emu = port->emu; in snd_emux_note_on()
60 if (snd_BUG_ON(!emu || !emu->ops.get_voice || !emu->ops.trigger)) in snd_emux_note_on()
69 for (i = 0; i < nvoices; i++) { in snd_emux_note_on()
71 if (zp && zp->v.exclusiveClass) in snd_emux_note_on()
72 exclusive_note_off(emu, port, zp->v.exclusiveClass); in snd_emux_note_on()
75 #if 0 // seems not necessary in snd_emux_note_on()
77 terminate_note1(emu, key, chan, 0); in snd_emux_note_on()
80 spin_lock_irqsave(&emu->voice_lock, flags); in snd_emux_note_on()
81 for (i = 0; i < nvoices; i++) { in snd_emux_note_on()
89 vp = emu->ops.get_voice(emu, port); in snd_emux_note_on()
90 if (vp == NULL || vp->ch < 0) in snd_emux_note_on()
92 if (STATE_IS_PLAYING(vp->state)) in snd_emux_note_on()
93 emu->ops.terminate(vp); in snd_emux_note_on()
95 vp->time = emu->use_time++; in snd_emux_note_on()
96 vp->chan = chan; in snd_emux_note_on()
97 vp->port = port; in snd_emux_note_on()
98 vp->key = key; in snd_emux_note_on()
99 vp->note = note; in snd_emux_note_on()
100 vp->velocity = vel; in snd_emux_note_on()
101 vp->zone = table[i]; in snd_emux_note_on()
102 if (vp->zone->sample) in snd_emux_note_on()
103 vp->block = vp->zone->sample->block; in snd_emux_note_on()
105 vp->block = NULL; in snd_emux_note_on()
109 vp->state = SNDRV_EMUX_ST_STANDBY; in snd_emux_note_on()
110 if (emu->ops.prepare) { in snd_emux_note_on()
111 vp->state = SNDRV_EMUX_ST_OFF; in snd_emux_note_on()
112 if (emu->ops.prepare(vp) >= 0) in snd_emux_note_on()
113 vp->state = SNDRV_EMUX_ST_STANDBY; in snd_emux_note_on()
118 for (i = 0; i < emu->max_voices; i++) { in snd_emux_note_on()
119 vp = &emu->voices[i]; in snd_emux_note_on()
120 if (vp->state == SNDRV_EMUX_ST_STANDBY && in snd_emux_note_on()
121 vp->chan == chan) { in snd_emux_note_on()
122 emu->ops.trigger(vp); in snd_emux_note_on()
123 vp->state = SNDRV_EMUX_ST_ON; in snd_emux_note_on()
124 vp->ontime = jiffies; /* remember the trigger timing */ in snd_emux_note_on()
127 spin_unlock_irqrestore(&emu->voice_lock, flags); in snd_emux_note_on()
130 if (port->port_mode == SNDRV_EMUX_PORT_MODE_OSS_SYNTH) { in snd_emux_note_on()
132 struct snd_emux_effect_table *fx = chan->private; in snd_emux_note_on()
134 fx->flag[EMUX_FX_SAMPLE_START] = 0; in snd_emux_note_on()
135 fx->flag[EMUX_FX_COARSE_SAMPLE_START] = 0; in snd_emux_note_on()
157 emu = port->emu; in snd_emux_note_off()
158 if (snd_BUG_ON(!emu || !emu->ops.release)) in snd_emux_note_off()
161 spin_lock_irqsave(&emu->voice_lock, flags); in snd_emux_note_off()
162 for (ch = 0; ch < emu->max_voices; ch++) { in snd_emux_note_off()
163 vp = &emu->voices[ch]; in snd_emux_note_off()
164 if (STATE_IS_PLAYING(vp->state) && in snd_emux_note_off()
165 vp->chan == chan && vp->key == note) { in snd_emux_note_off()
166 vp->state = SNDRV_EMUX_ST_RELEASED; in snd_emux_note_off()
167 if (vp->ontime == jiffies) { in snd_emux_note_off()
168 /* if note-off is sent too shortly after in snd_emux_note_off()
169 * note-on, emuX engine cannot produce the sound in snd_emux_note_off()
173 vp->state = SNDRV_EMUX_ST_PENDING; in snd_emux_note_off()
174 if (! emu->timer_active) { in snd_emux_note_off()
175 mod_timer(&emu->tlist, jiffies + 1); in snd_emux_note_off()
176 emu->timer_active = 1; in snd_emux_note_off()
180 emu->ops.release(vp); in snd_emux_note_off()
183 spin_unlock_irqrestore(&emu->voice_lock, flags); in snd_emux_note_off()
189 * release the pending note-offs
196 int ch, do_again = 0; in snd_emux_timer_callback()
198 spin_lock_irqsave(&emu->voice_lock, flags); in snd_emux_timer_callback()
199 for (ch = 0; ch < emu->max_voices; ch++) { in snd_emux_timer_callback()
200 vp = &emu->voices[ch]; in snd_emux_timer_callback()
201 if (vp->state == SNDRV_EMUX_ST_PENDING) { in snd_emux_timer_callback()
202 if (vp->ontime == jiffies) in snd_emux_timer_callback()
205 emu->ops.release(vp); in snd_emux_timer_callback()
206 vp->state = SNDRV_EMUX_ST_RELEASED; in snd_emux_timer_callback()
211 mod_timer(&emu->tlist, jiffies + 1); in snd_emux_timer_callback()
212 emu->timer_active = 1; in snd_emux_timer_callback()
214 emu->timer_active = 0; in snd_emux_timer_callback()
215 spin_unlock_irqrestore(&emu->voice_lock, flags); in snd_emux_timer_callback()
234 emu = port->emu; in snd_emux_key_press()
235 if (snd_BUG_ON(!emu || !emu->ops.update)) in snd_emux_key_press()
238 spin_lock_irqsave(&emu->voice_lock, flags); in snd_emux_key_press()
239 for (ch = 0; ch < emu->max_voices; ch++) { in snd_emux_key_press()
240 vp = &emu->voices[ch]; in snd_emux_key_press()
241 if (vp->state == SNDRV_EMUX_ST_ON && in snd_emux_key_press()
242 vp->chan == chan && vp->key == note) { in snd_emux_key_press()
243 vp->velocity = vel; in snd_emux_key_press()
247 spin_unlock_irqrestore(&emu->voice_lock, flags); in snd_emux_key_press()
265 emu = port->emu; in snd_emux_update_channel()
266 if (snd_BUG_ON(!emu || !emu->ops.update)) in snd_emux_update_channel()
269 spin_lock_irqsave(&emu->voice_lock, flags); in snd_emux_update_channel()
270 for (i = 0; i < emu->max_voices; i++) { in snd_emux_update_channel()
271 vp = &emu->voices[i]; in snd_emux_update_channel()
272 if (vp->chan == chan) in snd_emux_update_channel()
275 spin_unlock_irqrestore(&emu->voice_lock, flags); in snd_emux_update_channel()
292 emu = port->emu; in snd_emux_update_port()
293 if (snd_BUG_ON(!emu || !emu->ops.update)) in snd_emux_update_port()
296 spin_lock_irqsave(&emu->voice_lock, flags); in snd_emux_update_port()
297 for (i = 0; i < emu->max_voices; i++) { in snd_emux_update_port()
298 vp = &emu->voices[i]; in snd_emux_update_port()
299 if (vp->port == port) in snd_emux_update_port()
302 spin_unlock_irqrestore(&emu->voice_lock, flags); in snd_emux_update_port()
332 if (chan->control[type] >= 64) in snd_emux_control()
333 snd_emux_send_effect(port, chan, EMUX_FX_CUTOFF, -160, in snd_emux_control()
336 snd_emux_send_effect(port, chan, EMUX_FX_CUTOFF, 0, in snd_emux_control()
354 if (port->chset.midi_mode == SNDRV_MIDI_MODE_XG) { in snd_emux_control()
361 * terminate note - if free flag is true, free the terminated voice
370 spin_lock_irqsave(&emu->voice_lock, flags); in terminate_note1()
371 for (i = 0; i < emu->max_voices; i++) { in terminate_note1()
372 vp = &emu->voices[i]; in terminate_note1()
373 if (STATE_IS_PLAYING(vp->state) && vp->chan == chan && in terminate_note1()
374 vp->key == note) in terminate_note1()
377 spin_unlock_irqrestore(&emu->voice_lock, flags); in terminate_note1()
382 * terminate note - exported for midi emulation
394 emu = port->emu; in snd_emux_terminate_note()
395 if (snd_BUG_ON(!emu || !emu->ops.terminate)) in snd_emux_terminate_note()
412 spin_lock_irqsave(&emu->voice_lock, flags); in snd_emux_terminate_all()
413 for (i = 0; i < emu->max_voices; i++) { in snd_emux_terminate_all()
414 vp = &emu->voices[i]; in snd_emux_terminate_all()
415 if (STATE_IS_PLAYING(vp->state)) in snd_emux_terminate_all()
416 terminate_voice(emu, vp, 0); in snd_emux_terminate_all()
417 if (vp->state == SNDRV_EMUX_ST_OFF) { in snd_emux_terminate_all()
418 if (emu->ops.free_voice) in snd_emux_terminate_all()
419 emu->ops.free_voice(vp); in snd_emux_terminate_all()
420 if (emu->ops.reset) in snd_emux_terminate_all()
421 emu->ops.reset(emu, i); in snd_emux_terminate_all()
423 vp->time = 0; in snd_emux_terminate_all()
426 emu->use_time = 0; in snd_emux_terminate_all()
427 spin_unlock_irqrestore(&emu->voice_lock, flags); in snd_emux_terminate_all()
445 emu = port->emu; in snd_emux_sounds_off_all()
446 if (snd_BUG_ON(!emu || !emu->ops.terminate)) in snd_emux_sounds_off_all()
449 spin_lock_irqsave(&emu->voice_lock, flags); in snd_emux_sounds_off_all()
450 for (i = 0; i < emu->max_voices; i++) { in snd_emux_sounds_off_all()
451 vp = &emu->voices[i]; in snd_emux_sounds_off_all()
452 if (STATE_IS_PLAYING(vp->state) && in snd_emux_sounds_off_all()
453 vp->port == port) in snd_emux_sounds_off_all()
454 terminate_voice(emu, vp, 0); in snd_emux_sounds_off_all()
455 if (vp->state == SNDRV_EMUX_ST_OFF) { in snd_emux_sounds_off_all()
456 if (emu->ops.free_voice) in snd_emux_sounds_off_all()
457 emu->ops.free_voice(vp); in snd_emux_sounds_off_all()
458 if (emu->ops.reset) in snd_emux_sounds_off_all()
459 emu->ops.reset(emu, i); in snd_emux_sounds_off_all()
462 spin_unlock_irqrestore(&emu->voice_lock, flags); in snd_emux_sounds_off_all()
477 spin_lock_irqsave(&emu->voice_lock, flags); in exclusive_note_off()
478 for (i = 0; i < emu->max_voices; i++) { in exclusive_note_off()
479 vp = &emu->voices[i]; in exclusive_note_off()
480 if (STATE_IS_PLAYING(vp->state) && vp->port == port && in exclusive_note_off()
481 vp->reg.exclusiveClass == exclass) { in exclusive_note_off()
482 terminate_voice(emu, vp, 0); in exclusive_note_off()
485 spin_unlock_irqrestore(&emu->voice_lock, flags); in exclusive_note_off()
495 emu->ops.terminate(vp); in terminate_voice()
496 vp->time = emu->use_time++; in terminate_voice()
497 vp->chan = NULL; in terminate_voice()
498 vp->port = NULL; in terminate_voice()
499 vp->zone = NULL; in terminate_voice()
500 vp->block = NULL; in terminate_voice()
501 vp->state = SNDRV_EMUX_ST_OFF; in terminate_voice()
502 if (free && emu->ops.free_voice) in terminate_voice()
503 emu->ops.free_voice(vp); in terminate_voice()
513 if (!STATE_IS_PLAYING(vp->state)) in update_voice()
516 if (vp->chan == NULL || vp->port == NULL) in update_voice()
526 emu->ops.update(vp, update); in update_voice()
530 #if 0 // not used
533 0xEAC0, 0xE0C8, 0xD740, 0xCE20, 0xC560, 0xBD08, 0xB500, 0xAD58,
534 0xA5F8, 0x9EF0, 0x9830, 0x91C0, 0x8B90, 0x85A8, 0x8000, 0x7A90
538 #define LO_BYTE(v) ((v) & 0xff)
539 #define HI_BYTE(v) (((v) >> 8) & 0xff)
552 vp->reg = vp->zone->v; in setup_voice()
559 vp->apan = -1; in setup_voice()
560 vp->avol = -1; in setup_voice()
561 vp->apitch = -1; in setup_voice()
567 parm = &vp->reg.parm; in setup_voice()
570 if (LO_BYTE(parm->modatkhld) >= 0x80 && parm->moddelay >= 0x8000) { in setup_voice()
571 parm->moddelay = 0xbfff; in setup_voice()
572 pitch = (HI_BYTE(parm->pefe) << 4) + vp->apitch; in setup_voice()
573 if (pitch > 0xffff) in setup_voice()
574 pitch = 0xffff; in setup_voice()
576 vp->ftarget = parm->cutoff + LO_BYTE(parm->pefe); in setup_voice()
577 LIMITVALUE(vp->ftarget, 0, 255); in setup_voice()
578 vp->ftarget <<= 8; in setup_voice()
580 vp->ftarget = parm->cutoff; in setup_voice()
581 vp->ftarget <<= 8; in setup_voice()
582 pitch = vp->apitch; in setup_voice()
586 if (pitch != 0xffff) { in setup_voice()
587 vp->ptarget = 1 << (pitch >> 12); in setup_voice()
588 if (pitch & 0x800) vp->ptarget += (vp->ptarget*0x102e)/0x2710; in setup_voice()
589 if (pitch & 0x400) vp->ptarget += (vp->ptarget*0x764)/0x2710; in setup_voice()
590 if (pitch & 0x200) vp->ptarget += (vp->ptarget*0x389)/0x2710; in setup_voice()
591 vp->ptarget += (vp->ptarget >> 1); in setup_voice()
592 if (vp->ptarget > 0xffff) vp->ptarget = 0xffff; in setup_voice()
594 vp->ptarget = 0xffff; in setup_voice()
596 if (LO_BYTE(parm->modatkhld) >= 0x80) { in setup_voice()
597 parm->modatkhld &= ~0xff; in setup_voice()
598 parm->modatkhld |= 0x7f; in setup_voice()
602 vp->vtarget = 0; in setup_voice()
603 #if 0 /* FIXME: this leads to some clicks.. */ in setup_voice()
604 if (LO_BYTE(parm->volatkhld) >= 0x80 && parm->voldelay >= 0x8000) { in setup_voice()
605 parm->voldelay = 0xbfff; in setup_voice()
606 vp->vtarget = voltarget[vp->avol % 0x10] >> (vp->avol >> 4); in setup_voice()
610 if (LO_BYTE(parm->volatkhld) >= 0x80) { in setup_voice()
611 parm->volatkhld &= ~0xff; in setup_voice()
612 parm->volatkhld |= 0x7f; in setup_voice()
620 0x00,0x03,0x06,0x09,0x0c,0x0f,0x12,0x14,0x17,0x1a,0x1d,0x20,0x22,0x25,0x28,0x2a,
621 0x2d,0x30,0x32,0x35,0x37,0x3a,0x3c,0x3f,0x41,0x44,0x46,0x49,0x4b,0x4d,0x50,0x52,
622 0x54,0x57,0x59,0x5b,0x5d,0x60,0x62,0x64,0x66,0x68,0x6a,0x6c,0x6f,0x71,0x73,0x75,
623 0x77,0x79,0x7b,0x7c,0x7e,0x80,0x82,0x84,0x86,0x88,0x89,0x8b,0x8d,0x8f,0x90,0x92,
624 0x94,0x96,0x97,0x99,0x9a,0x9c,0x9e,0x9f,0xa1,0xa2,0xa4,0xa5,0xa7,0xa8,0xaa,0xab,
625 0xad,0xae,0xaf,0xb1,0xb2,0xb3,0xb5,0xb6,0xb7,0xb9,0xba,0xbb,0xbc,0xbe,0xbf,0xc0,
626 0xc1,0xc2,0xc3,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,
627 0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdc,0xdd,0xde,0xdf,
628 0xdf,0xe0,0xe1,0xe2,0xe2,0xe3,0xe4,0xe4,0xe5,0xe6,0xe6,0xe7,0xe8,0xe8,0xe9,0xe9,
629 0xea,0xeb,0xeb,0xec,0xec,0xed,0xed,0xee,0xee,0xef,0xef,0xf0,0xf0,0xf1,0xf1,0xf1,
630 0xf2,0xf2,0xf3,0xf3,0xf3,0xf4,0xf4,0xf5,0xf5,0xf5,0xf6,0xf6,0xf6,0xf7,0xf7,0xf7,
631 0xf7,0xf8,0xf8,0xf8,0xf9,0xf9,0xf9,0xf9,0xf9,0xfa,0xfa,0xfa,0xfa,0xfb,0xfb,0xfb,
632 0xfb,0xfb,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,0xfd,
633 0xfd,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,
634 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
635 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
641 struct snd_midi_channel *chan = vp->chan; in calc_pan()
644 /* pan & loop start (pan 8bit, MSB, 0:right, 0xff:left) */ in calc_pan()
645 if (vp->reg.fixpan > 0) /* 0-127 */ in calc_pan()
646 pan = 255 - (int)vp->reg.fixpan * 2; in calc_pan()
648 pan = chan->control[MIDI_CTL_MSB_PAN] - 64; in calc_pan()
649 if (vp->reg.pan >= 0) /* 0-127 */ in calc_pan()
650 pan += vp->reg.pan - 64; in calc_pan()
651 pan = 127 - (int)pan * 2; in calc_pan()
653 LIMITVALUE(pan, 0, 255); in calc_pan()
655 if (vp->emu->linear_panning) { in calc_pan()
657 if (pan != vp->apan) { in calc_pan()
658 vp->apan = pan; in calc_pan()
659 if (pan == 0) in calc_pan()
660 vp->aaux = 0xff; in calc_pan()
662 vp->aaux = (-pan) & 0xff; in calc_pan()
665 return 0; in calc_pan()
668 if (vp->apan != (int)pan_volumes[pan]) { in calc_pan()
669 vp->apan = pan_volumes[pan]; in calc_pan()
670 vp->aaux = pan_volumes[255 - pan]; in calc_pan()
673 return 0; in calc_pan()
682 * So volume becomes maximum when avol is 0 (no attenuation), and
683 * minimum when 255 (-96dB or silence).
686 /* tables for volume->attenuation calculation */
688 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
689 0x63, 0x2b, 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22,
690 0x21, 0x20, 0x1f, 0x1e, 0x1e, 0x1d, 0x1c, 0x1b, 0x1b, 0x1a,
691 0x19, 0x19, 0x18, 0x17, 0x17, 0x16, 0x16, 0x15, 0x15, 0x14,
692 0x14, 0x13, 0x13, 0x13, 0x12, 0x12, 0x11, 0x11, 0x11, 0x10,
693 0x10, 0x10, 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e, 0x0e, 0x0d,
694 0x0d, 0x0d, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0b, 0x0b, 0x0b,
695 0x0b, 0x0a, 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09,
696 0x08, 0x08, 0x08, 0x08, 0x08, 0x07, 0x07, 0x07, 0x07, 0x06,
697 0x06, 0x06, 0x06, 0x06, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04,
698 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02,
699 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01,
700 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
704 0x32, 0x31, 0x30, 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x2a,
705 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x24, 0x23, 0x22, 0x21,
706 0x21, 0x20, 0x1f, 0x1e, 0x1e, 0x1d, 0x1c, 0x1c, 0x1b, 0x1a,
707 0x1a, 0x19, 0x19, 0x18, 0x18, 0x17, 0x16, 0x16, 0x15, 0x15,
708 0x14, 0x14, 0x13, 0x13, 0x13, 0x12, 0x12, 0x11, 0x11, 0x10,
709 0x10, 0x10, 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e, 0x0d, 0x0d,
710 0x0d, 0x0c, 0x0c, 0x0c, 0x0b, 0x0b, 0x0b, 0x0b, 0x0a, 0x0a,
711 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x08, 0x08, 0x08,
712 0x08, 0x08, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06,
713 0x06, 0x06, 0x06, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
714 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03,
715 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01,
716 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
720 0x7f, 0x6c, 0x62, 0x5a, 0x54, 0x50, 0x4b, 0x48, 0x45, 0x42,
721 0x40, 0x3d, 0x3b, 0x39, 0x38, 0x36, 0x34, 0x33, 0x31, 0x30,
722 0x2f, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, 0x27, 0x26, 0x25,
723 0x24, 0x24, 0x23, 0x22, 0x21, 0x21, 0x20, 0x1f, 0x1e, 0x1e,
724 0x1d, 0x1d, 0x1c, 0x1b, 0x1b, 0x1a, 0x1a, 0x19, 0x18, 0x18,
725 0x17, 0x17, 0x16, 0x16, 0x15, 0x15, 0x15, 0x14, 0x14, 0x13,
726 0x13, 0x12, 0x12, 0x11, 0x11, 0x11, 0x10, 0x10, 0x0f, 0x0f,
727 0x0f, 0x0e, 0x0e, 0x0e, 0x0d, 0x0d, 0x0d, 0x0c, 0x0c, 0x0c,
728 0x0b, 0x0b, 0x0b, 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09,
729 0x08, 0x08, 0x08, 0x07, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06,
730 0x06, 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03,
731 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01,
732 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
744 struct snd_midi_channel *chan = vp->chan; in calc_volume()
745 struct snd_emux_port *port = vp->port; in calc_volume()
747 expression_vol = chan->control[MIDI_CTL_MSB_EXPRESSION]; in calc_volume()
748 LIMITMAX(vp->velocity, 127); in calc_volume()
749 LIMITVALUE(expression_vol, 0, 127); in calc_volume()
750 if (port->port_mode == SNDRV_EMUX_PORT_MODE_OSS_SYNTH) { in calc_volume()
751 /* 0 - 127 */ in calc_volume()
752 main_vol = chan->control[MIDI_CTL_MSB_MAIN_VOLUME]; in calc_volume()
753 vol = (vp->velocity * main_vol * expression_vol) / (127*127); in calc_volume()
754 vol = vol * vp->reg.amplitude / 127; in calc_volume()
756 LIMITVALUE(vol, 0, 127); in calc_volume()
762 main_vol = chan->control[MIDI_CTL_MSB_MAIN_VOLUME] * vp->reg.amplitude / 127; in calc_volume()
763 LIMITVALUE(main_vol, 0, 127); in calc_volume()
765 vol = voltab1[main_vol] + voltab2[vp->velocity]; in calc_volume()
767 vol += vp->reg.attenuation; in calc_volume()
768 vol += ((0x100 - vol) * expressiontab[expression_vol])/128; in calc_volume()
771 master_vol = port->chset.gs_master_volume; in calc_volume()
772 LIMITVALUE(master_vol, 0, 127); in calc_volume()
774 vol += port->volume_atten; in calc_volume()
777 if (chan->private) { in calc_volume()
778 struct snd_emux_effect_table *fx = chan->private; in calc_volume()
779 vol += fx->val[EMUX_FX_ATTEN]; in calc_volume()
783 LIMITVALUE(vol, 0, 255); in calc_volume()
784 if (vp->avol == vol) in calc_volume()
785 return 0; /* value unchanged */ in calc_volume()
787 vp->avol = vol; in calc_volume()
789 && LO_BYTE(vp->reg.parm.volatkhld) < 0x7d) { in calc_volume()
791 if (vp->velocity < 70) in calc_volume()
794 atten = vp->velocity; in calc_volume()
795 vp->acutoff = (atten * vp->reg.parm.cutoff + 0xa0) >> 7; in calc_volume()
797 vp->acutoff = vp->reg.parm.cutoff; in calc_volume()
806 * 0xE000 is no pitch offset at 44100Hz sample.
813 struct snd_midi_channel *chan = vp->chan; in calc_pitch()
817 if (vp->reg.fixkey >= 0) { in calc_pitch()
818 offset = (vp->reg.fixkey - vp->reg.root) * 4096 / 12; in calc_pitch()
820 offset = (vp->note - vp->reg.root) * 4096 / 12; in calc_pitch()
822 offset = (offset * vp->reg.scaleTuning) / 100; in calc_pitch()
823 offset += vp->reg.tune * 4096 / 1200; in calc_pitch()
824 if (chan->midi_pitchbend != 0) { in calc_pitch()
826 offset += chan->midi_pitchbend * chan->gm_rpn_pitch_bend_range / 3072; in calc_pitch()
830 * coarse = -8192 to 8192 (100 cent per 128) in calc_pitch()
831 * fine = -8192 to 8192 (max=100cent) in calc_pitch()
834 offset += chan->gm_rpn_coarse_tuning * 4096 / (12 * 128); in calc_pitch()
835 offset += chan->gm_rpn_fine_tuning / 24; in calc_pitch()
839 if (chan->private) { in calc_pitch()
840 struct snd_emux_effect_table *fx = chan->private; in calc_pitch()
841 if (fx->flag[EMUX_FX_INIT_PITCH]) in calc_pitch()
842 offset += fx->val[EMUX_FX_INIT_PITCH]; in calc_pitch()
846 /* 0xe000: root pitch */ in calc_pitch()
847 offset += 0xe000 + vp->reg.rate_offset; in calc_pitch()
848 offset += vp->emu->pitch_shift; in calc_pitch()
849 LIMITVALUE(offset, 0, 0xffff); in calc_pitch()
850 if (offset == vp->apitch) in calc_pitch()
851 return 0; /* unchanged */ in calc_pitch()
852 vp->apitch = offset; in calc_pitch()
864 switch (port->chset.midi_mode) { in get_bank()
866 val = chan->control[MIDI_CTL_MSB_BANK]; in get_bank()
867 if (val == 127) in get_bank()
869 return chan->control[MIDI_CTL_LSB_BANK]; in get_bank()
872 if (chan->drum_channel) in get_bank()
875 return chan->control[MIDI_CTL_MSB_BANK]; in get_bank()
878 if (chan->drum_channel) in get_bank()
880 return chan->control[MIDI_CTL_MSB_BANK]; in get_bank()
896 preset = chan->midi_program; in get_zone()
899 def_preset = port->ctrls[EMUX_MD_DEF_DRUM]; in get_zone()
903 def_bank = port->ctrls[EMUX_MD_DEF_BANK]; in get_zone()
906 return snd_soundfont_search_zone(emu->sflist, notep, vel, preset, bank, in get_zone()
920 spin_lock_irqsave(&emu->voice_lock, flags); in snd_emux_init_voices()
921 for (i = 0; i < emu->max_voices; i++) { in snd_emux_init_voices()
922 vp = &emu->voices[i]; in snd_emux_init_voices()
923 vp->ch = -1; /* not used */ in snd_emux_init_voices()
924 vp->state = SNDRV_EMUX_ST_OFF; in snd_emux_init_voices()
925 vp->chan = NULL; in snd_emux_init_voices()
926 vp->port = NULL; in snd_emux_init_voices()
927 vp->time = 0; in snd_emux_init_voices()
928 vp->emu = emu; in snd_emux_init_voices()
929 vp->hw = emu->hw; in snd_emux_init_voices()
931 spin_unlock_irqrestore(&emu->voice_lock, flags); in snd_emux_init_voices()
940 spin_lock_irqsave(&emu->voice_lock, flags); in snd_emux_lock_voice()
941 if (emu->voices[voice].state == SNDRV_EMUX_ST_OFF) in snd_emux_lock_voice()
942 emu->voices[voice].state = SNDRV_EMUX_ST_LOCKED; in snd_emux_lock_voice()
946 voice, emu->voices[voice].state); in snd_emux_lock_voice()
947 spin_unlock_irqrestore(&emu->voice_lock, flags); in snd_emux_lock_voice()
958 spin_lock_irqsave(&emu->voice_lock, flags); in snd_emux_unlock_voice()
959 if (emu->voices[voice].state == SNDRV_EMUX_ST_LOCKED) in snd_emux_unlock_voice()
960 emu->voices[voice].state = SNDRV_EMUX_ST_OFF; in snd_emux_unlock_voice()
964 voice, emu->voices[voice].state); in snd_emux_unlock_voice()
965 spin_unlock_irqrestore(&emu->voice_lock, flags); in snd_emux_unlock_voice()