^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * synth callback routines for Emu10k1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "emu10k1_synth_local.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <sound/asoundef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) /* voice status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) V_FREE=0, V_OFF, V_RELEASED, V_PLAYING, V_END
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /* Keeps track of what we are finding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct best_voice {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) unsigned int time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) int voice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * prototypes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static void lookup_voices(struct snd_emux *emux, struct snd_emu10k1 *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct best_voice *best, int active_only);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static struct snd_emux_voice *get_voice(struct snd_emux *emux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct snd_emux_port *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static int start_voice(struct snd_emux_voice *vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static void trigger_voice(struct snd_emux_voice *vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static void release_voice(struct snd_emux_voice *vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static void update_voice(struct snd_emux_voice *vp, int update);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static void terminate_voice(struct snd_emux_voice *vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static void free_voice(struct snd_emux_voice *vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static void set_fmmod(struct snd_emu10k1 *hw, struct snd_emux_voice *vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static void set_fm2frq2(struct snd_emu10k1 *hw, struct snd_emux_voice *vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static void set_filterQ(struct snd_emu10k1 *hw, struct snd_emux_voice *vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * Ensure a value is between two points
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * macro evaluates its args more than once, so changed to upper-case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define LIMITVALUE(x, a, b) do { if ((x) < (a)) (x) = (a); else if ((x) > (b)) (x) = (b); } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define LIMITMAX(x, a) do {if ((x) > (a)) (x) = (a); } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * set up operators
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static const struct snd_emux_operators emu10k1_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .get_voice = get_voice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .prepare = start_voice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .trigger = trigger_voice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .release = release_voice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .update = update_voice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .terminate = terminate_voice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .free_voice = free_voice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .sample_new = snd_emu10k1_sample_new,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .sample_free = snd_emu10k1_sample_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) snd_emu10k1_ops_setup(struct snd_emux *emux)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) emux->ops = emu10k1_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * get more voice for pcm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * terminate most inactive voice and give it as a pcm voice.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * voice_lock is already held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) snd_emu10k1_synth_get_voice(struct snd_emu10k1 *hw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct snd_emux *emu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct snd_emux_voice *vp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct best_voice best[V_END];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) emu = hw->synth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) lookup_voices(emu, hw, best, 1); /* no OFF voices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) for (i = 0; i < V_END; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (best[i].voice >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) int ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) vp = &emu->voices[best[i].voice];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if ((ch = vp->ch) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) dev_warn(emu->card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) "synth_get_voice: ch < 0 (%d) ??", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) vp->emu->num_voices--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) vp->ch = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) vp->state = SNDRV_EMUX_ST_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* not found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * turn off the voice (not terminated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) release_voice(struct snd_emux_voice *vp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int dcysusv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct snd_emu10k1 *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) hw = vp->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) dcysusv = 0x8000 | (unsigned char)vp->reg.parm.modrelease;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) snd_emu10k1_ptr_write(hw, DCYSUSM, vp->ch, dcysusv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) dcysusv = 0x8000 | (unsigned char)vp->reg.parm.volrelease | DCYSUSV_CHANNELENABLE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) snd_emu10k1_ptr_write(hw, DCYSUSV, vp->ch, dcysusv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * terminate the voice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) terminate_voice(struct snd_emux_voice *vp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct snd_emu10k1 *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (snd_BUG_ON(!vp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) hw = vp->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) snd_emu10k1_ptr_write(hw, DCYSUSV, vp->ch, 0x807f | DCYSUSV_CHANNELENABLE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (vp->block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct snd_emu10k1_memblk *emem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) emem = (struct snd_emu10k1_memblk *)vp->block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (emem->map_locked > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) emem->map_locked--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * release the voice to system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) free_voice(struct snd_emux_voice *vp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct snd_emu10k1 *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) hw = vp->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* FIXME: emu10k1_synth is broken. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /* This can get called with hw == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /* Problem apparent on plug, unplug then plug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* on the Audigy 2 ZS Notebook. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (hw && (vp->ch >= 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) snd_emu10k1_ptr_write(hw, IFATN, vp->ch, 0xff00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) snd_emu10k1_ptr_write(hw, DCYSUSV, vp->ch, 0x807f | DCYSUSV_CHANNELENABLE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) // snd_emu10k1_ptr_write(hw, DCYSUSV, vp->ch, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) snd_emu10k1_ptr_write(hw, VTFT, vp->ch, 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) snd_emu10k1_ptr_write(hw, CVCF, vp->ch, 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) snd_emu10k1_voice_free(hw, &hw->voices[vp->ch]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) vp->emu->num_voices--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) vp->ch = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * update registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) update_voice(struct snd_emux_voice *vp, int update)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct snd_emu10k1 *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) hw = vp->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (update & SNDRV_EMUX_UPDATE_VOLUME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) snd_emu10k1_ptr_write(hw, IFATN_ATTENUATION, vp->ch, vp->avol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (update & SNDRV_EMUX_UPDATE_PITCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) snd_emu10k1_ptr_write(hw, IP, vp->ch, vp->apitch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (update & SNDRV_EMUX_UPDATE_PAN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) snd_emu10k1_ptr_write(hw, PTRX_FXSENDAMOUNT_A, vp->ch, vp->apan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) snd_emu10k1_ptr_write(hw, PTRX_FXSENDAMOUNT_B, vp->ch, vp->aaux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (update & SNDRV_EMUX_UPDATE_FMMOD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) set_fmmod(hw, vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (update & SNDRV_EMUX_UPDATE_TREMFREQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) snd_emu10k1_ptr_write(hw, TREMFRQ, vp->ch, vp->reg.parm.tremfrq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (update & SNDRV_EMUX_UPDATE_FM2FRQ2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) set_fm2frq2(hw, vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (update & SNDRV_EMUX_UPDATE_Q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) set_filterQ(hw, vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * look up voice table - get the best voice in order of preference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* spinlock held! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) lookup_voices(struct snd_emux *emu, struct snd_emu10k1 *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct best_voice *best, int active_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct snd_emux_voice *vp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct best_voice *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) for (i = 0; i < V_END; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) best[i].time = (unsigned int)-1; /* XXX MAX_?INT really */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) best[i].voice = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * Go through them all and get a best one to use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * NOTE: could also look at volume and pick the quietest one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) for (i = 0; i < emu->max_voices; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) int state, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) vp = &emu->voices[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) state = vp->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (state == SNDRV_EMUX_ST_OFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (vp->ch < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (active_only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) bp = best + V_FREE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) bp = best + V_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) else if (state == SNDRV_EMUX_ST_RELEASED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) state == SNDRV_EMUX_ST_PENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) bp = best + V_RELEASED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #if 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) val = snd_emu10k1_ptr_read(hw, CVCF_CURRENTVOL, vp->ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (! val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) bp = best + V_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) else if (state == SNDRV_EMUX_ST_STANDBY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) else if (state & SNDRV_EMUX_ST_ON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) bp = best + V_PLAYING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* check if sample is finished playing (non-looping only) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (bp != best + V_OFF && bp != best + V_FREE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) (vp->reg.sample_mode & SNDRV_SFNT_SAMPLE_SINGLESHOT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) val = snd_emu10k1_ptr_read(hw, CCCA_CURRADDR, vp->ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (val >= vp->reg.loopstart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) bp = best + V_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (vp->time < bp->time) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) bp->time = vp->time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) bp->voice = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * get an empty voice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * emu->voice_lock is already held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static struct snd_emux_voice *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) get_voice(struct snd_emux *emu, struct snd_emux_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct snd_emu10k1 *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct snd_emux_voice *vp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct best_voice best[V_END];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) hw = emu->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) lookup_voices(emu, hw, best, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) for (i = 0; i < V_END; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (best[i].voice >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) vp = &emu->voices[best[i].voice];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (vp->ch < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) /* allocate a voice */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct snd_emu10k1_voice *hwvoice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (snd_emu10k1_voice_alloc(hw, EMU10K1_SYNTH, 1, &hwvoice) < 0 || hwvoice == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) vp->ch = hwvoice->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) emu->num_voices++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) return vp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /* not found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * prepare envelopes and LFOs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) start_voice(struct snd_emux_voice *vp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) unsigned int temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) int ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) unsigned int addr, mapped_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct snd_midi_channel *chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) struct snd_emu10k1 *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) struct snd_emu10k1_memblk *emem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) hw = vp->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) ch = vp->ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (snd_BUG_ON(ch < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) chan = vp->chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) emem = (struct snd_emu10k1_memblk *)vp->block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (emem == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) emem->map_locked++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (snd_emu10k1_memblk_map(hw, emem) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) /* dev_err(hw->card->devK, "emu: cannot map!\n"); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) mapped_offset = snd_emu10k1_memblk_offset(emem) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) vp->reg.start += mapped_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) vp->reg.end += mapped_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) vp->reg.loopstart += mapped_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) vp->reg.loopend += mapped_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /* set channel routing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /* A = left(0), B = right(1), C = reverb(c), D = chorus(d) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (hw->audigy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) temp = FXBUS_MIDI_LEFT | (FXBUS_MIDI_RIGHT << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) (FXBUS_MIDI_REVERB << 16) | (FXBUS_MIDI_CHORUS << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) snd_emu10k1_ptr_write(hw, A_FXRT1, ch, temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) temp = (FXBUS_MIDI_LEFT << 16) | (FXBUS_MIDI_RIGHT << 20) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) (FXBUS_MIDI_REVERB << 24) | (FXBUS_MIDI_CHORUS << 28);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) snd_emu10k1_ptr_write(hw, FXRT, ch, temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /* channel to be silent and idle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) snd_emu10k1_ptr_write(hw, DCYSUSV, ch, 0x0000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) snd_emu10k1_ptr_write(hw, VTFT, ch, 0x0000FFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) snd_emu10k1_ptr_write(hw, CVCF, ch, 0x0000FFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) snd_emu10k1_ptr_write(hw, PTRX, ch, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) snd_emu10k1_ptr_write(hw, CPF, ch, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /* set pitch offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) snd_emu10k1_ptr_write(hw, IP, vp->ch, vp->apitch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /* set envelope parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) snd_emu10k1_ptr_write(hw, ENVVAL, ch, vp->reg.parm.moddelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) snd_emu10k1_ptr_write(hw, ATKHLDM, ch, vp->reg.parm.modatkhld);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) snd_emu10k1_ptr_write(hw, DCYSUSM, ch, vp->reg.parm.moddcysus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) snd_emu10k1_ptr_write(hw, ENVVOL, ch, vp->reg.parm.voldelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) snd_emu10k1_ptr_write(hw, ATKHLDV, ch, vp->reg.parm.volatkhld);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) /* decay/sustain parameter for volume envelope is used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) for triggerg the voice */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) /* cutoff and volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) temp = (unsigned int)vp->acutoff << 8 | (unsigned char)vp->avol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) snd_emu10k1_ptr_write(hw, IFATN, vp->ch, temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) /* modulation envelope heights */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) snd_emu10k1_ptr_write(hw, PEFE, ch, vp->reg.parm.pefe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) /* lfo1/2 delay */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) snd_emu10k1_ptr_write(hw, LFOVAL1, ch, vp->reg.parm.lfo1delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) snd_emu10k1_ptr_write(hw, LFOVAL2, ch, vp->reg.parm.lfo2delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) /* lfo1 pitch & cutoff shift */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) set_fmmod(hw, vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) /* lfo1 volume & freq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) snd_emu10k1_ptr_write(hw, TREMFRQ, vp->ch, vp->reg.parm.tremfrq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) /* lfo2 pitch & freq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) set_fm2frq2(hw, vp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) /* reverb and loop start (reverb 8bit, MSB) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) temp = vp->reg.parm.reverb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) temp += (int)vp->chan->control[MIDI_CTL_E1_REVERB_DEPTH] * 9 / 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) LIMITMAX(temp, 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) addr = vp->reg.loopstart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) snd_emu10k1_ptr_write(hw, PSST, vp->ch, (temp << 24) | addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /* chorus & loop end (chorus 8bit, MSB) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) addr = vp->reg.loopend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) temp = vp->reg.parm.chorus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) temp += (int)chan->control[MIDI_CTL_E3_CHORUS_DEPTH] * 9 / 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) LIMITMAX(temp, 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) temp = (temp <<24) | addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) snd_emu10k1_ptr_write(hw, DSL, ch, temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) /* clear filter delay memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) snd_emu10k1_ptr_write(hw, Z1, ch, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) snd_emu10k1_ptr_write(hw, Z2, ch, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /* invalidate maps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) temp = (hw->silent_page.addr << hw->address_mode) | (hw->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) snd_emu10k1_ptr_write(hw, MAPA, ch, temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) snd_emu10k1_ptr_write(hw, MAPB, ch, temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) /* cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) unsigned int val, sample;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) val = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (vp->reg.sample_mode & SNDRV_SFNT_SAMPLE_8BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) sample = 0x80808080;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) sample = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) val *= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) /* cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) snd_emu10k1_ptr_write(hw, CCR, ch, 0x1c << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) snd_emu10k1_ptr_write(hw, CDE, ch, sample);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) snd_emu10k1_ptr_write(hw, CDF, ch, sample);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) /* invalidate maps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) temp = ((unsigned int)hw->silent_page.addr << hw_address_mode) | (hw->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) snd_emu10k1_ptr_write(hw, MAPA, ch, temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) snd_emu10k1_ptr_write(hw, MAPB, ch, temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) /* fill cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) val -= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) val <<= 25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) val |= 0x1c << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) snd_emu10k1_ptr_write(hw, CCR, ch, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) /* Q & current address (Q 4bit value, MSB) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) addr = vp->reg.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) temp = vp->reg.parm.filterQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) temp = (temp<<28) | addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (vp->apitch < 0xe400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) temp |= CCCA_INTERPROM_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) unsigned int shift = (vp->apitch - 0xe000) >> 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) temp |= shift << 25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (vp->reg.sample_mode & SNDRV_SFNT_SAMPLE_8BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) temp |= CCCA_8BITSELECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) snd_emu10k1_ptr_write(hw, CCCA, ch, temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* reset volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) temp = (unsigned int)vp->vtarget << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) snd_emu10k1_ptr_write(hw, VTFT, ch, temp | vp->ftarget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) snd_emu10k1_ptr_write(hw, CVCF, ch, temp | 0xff00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * Start envelope
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) trigger_voice(struct snd_emux_voice *vp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) unsigned int temp, ptarget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct snd_emu10k1 *hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) struct snd_emu10k1_memblk *emem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) hw = vp->hw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) emem = (struct snd_emu10k1_memblk *)vp->block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) if (! emem || emem->mapped_page < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return; /* not mapped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) ptarget = (unsigned int)vp->ptarget << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) ptarget = IP_TO_CP(vp->apitch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) /* set pitch target and pan (volume) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) temp = ptarget | (vp->apan << 8) | vp->aaux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) snd_emu10k1_ptr_write(hw, PTRX, vp->ch, temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) /* pitch target */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) snd_emu10k1_ptr_write(hw, CPF, vp->ch, ptarget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) /* trigger voice */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) snd_emu10k1_ptr_write(hw, DCYSUSV, vp->ch, vp->reg.parm.voldcysus|DCYSUSV_CHANNELENABLE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) #define MOD_SENSE 18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) /* set lfo1 modulation height and cutoff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) set_fmmod(struct snd_emu10k1 *hw, struct snd_emux_voice *vp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) unsigned short fmmod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) short pitch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) unsigned char cutoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) int modulation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) pitch = (char)(vp->reg.parm.fmmod>>8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) cutoff = (vp->reg.parm.fmmod & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) modulation = vp->chan->gm_modulation + vp->chan->midi_pressure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) pitch += (MOD_SENSE * modulation) / 1200;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) LIMITVALUE(pitch, -128, 127);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) fmmod = ((unsigned char)pitch<<8) | cutoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) snd_emu10k1_ptr_write(hw, FMMOD, vp->ch, fmmod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) /* set lfo2 pitch & frequency */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) set_fm2frq2(struct snd_emu10k1 *hw, struct snd_emux_voice *vp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) unsigned short fm2frq2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) short pitch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) unsigned char freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) int modulation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) pitch = (char)(vp->reg.parm.fm2frq2>>8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) freq = vp->reg.parm.fm2frq2 & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) modulation = vp->chan->gm_modulation + vp->chan->midi_pressure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) pitch += (MOD_SENSE * modulation) / 1200;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) LIMITVALUE(pitch, -128, 127);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) fm2frq2 = ((unsigned char)pitch<<8) | freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) snd_emu10k1_ptr_write(hw, FM2FRQ2, vp->ch, fm2frq2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) /* set filterQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) set_filterQ(struct snd_emu10k1 *hw, struct snd_emux_voice *vp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) val = snd_emu10k1_ptr_read(hw, CCCA, vp->ch) & ~CCCA_RESONANCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) val |= (vp->reg.parm.filterQ << 28);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) snd_emu10k1_ptr_write(hw, CCCA, vp->ch, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }