⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 emux_synth.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
			terminate_voice(emu, vp, 0);		}	}	spin_unlock_irqrestore(&emu->voice_lock, flags);}/* * terminate a voice * if free flag is true, call free_voice after termination */static voidterminate_voice(snd_emux_t *emu, snd_emux_voice_t *vp, int free){	emu->ops.terminate(vp);	vp->time = emu->use_time++;	vp->chan = NULL;	vp->port = NULL;	vp->zone = NULL;	vp->block = NULL;	vp->state = SNDRV_EMUX_ST_OFF;	if (free && emu->ops.free_voice)		emu->ops.free_voice(vp);}/* * Modulate the voice */static voidupdate_voice(snd_emux_t *emu, snd_emux_voice_t *vp, int update){	if (!STATE_IS_PLAYING(vp->state))		return;	if (vp->chan == NULL || vp->port == NULL)		return;	if (update & SNDRV_EMUX_UPDATE_VOLUME)		calc_volume(vp);	if (update & SNDRV_EMUX_UPDATE_PITCH)		calc_pitch(vp);	if (update & SNDRV_EMUX_UPDATE_PAN) {		if (! calc_pan(vp) && (update == SNDRV_EMUX_UPDATE_PAN))			return;	}	emu->ops.update(vp, update);}#if 0 // not used/* table for volume target calculation */static unsigned short voltarget[16] = { 	0xEAC0, 0xE0C8, 0xD740, 0xCE20, 0xC560, 0xBD08, 0xB500, 0xAD58,	0xA5F8, 0x9EF0, 0x9830, 0x91C0, 0x8B90, 0x85A8, 0x8000, 0x7A90};#endif#define LO_BYTE(v)	((v) & 0xff)#define HI_BYTE(v)	(((v) >> 8) & 0xff)/* * Sets up the voice structure by calculating some values that * will be needed later. */static voidsetup_voice(snd_emux_voice_t *vp){	soundfont_voice_parm_t *parm;	int pitch;	/* copy the original register values */	vp->reg = vp->zone->v;#ifdef SNDRV_EMUX_USE_RAW_EFFECT	snd_emux_setup_effect(vp);#endif	/* reset status */	vp->apan = -1;	vp->avol = -1;	vp->apitch = -1;	calc_volume(vp);	calc_pitch(vp);	calc_pan(vp);	parm = &vp->reg.parm;	/* compute filter target and correct modulation parameters */	if (LO_BYTE(parm->modatkhld) >= 0x80 && parm->moddelay >= 0x8000) {		parm->moddelay = 0xbfff;		pitch = (HI_BYTE(parm->pefe) << 4) + vp->apitch;		if (pitch > 0xffff)			pitch = 0xffff;		/* calculate filter target */		vp->ftarget = parm->cutoff + LO_BYTE(parm->pefe);		LIMITVALUE(vp->ftarget, 0, 255);		vp->ftarget <<= 8;	} else {		vp->ftarget = parm->cutoff;		vp->ftarget <<= 8;		pitch = vp->apitch;	}	/* compute pitch target */	if (pitch != 0xffff) {		vp->ptarget = 1 << (pitch >> 12);		if (pitch & 0x800) vp->ptarget += (vp->ptarget*0x102e)/0x2710;		if (pitch & 0x400) vp->ptarget += (vp->ptarget*0x764)/0x2710;		if (pitch & 0x200) vp->ptarget += (vp->ptarget*0x389)/0x2710;		vp->ptarget += (vp->ptarget >> 1);		if (vp->ptarget > 0xffff) vp->ptarget = 0xffff;	} else		vp->ptarget = 0xffff;	if (LO_BYTE(parm->modatkhld) >= 0x80) {		parm->modatkhld &= ~0xff;		parm->modatkhld |= 0x7f;	}	/* compute volume target and correct volume parameters */	vp->vtarget = 0;#if 0 /* FIXME: this leads to some clicks.. */	if (LO_BYTE(parm->volatkhld) >= 0x80 && parm->voldelay >= 0x8000) {		parm->voldelay = 0xbfff;		vp->vtarget = voltarget[vp->avol % 0x10] >> (vp->avol >> 4);	}#endif	if (LO_BYTE(parm->volatkhld) >= 0x80) {		parm->volatkhld &= ~0xff;		parm->volatkhld |= 0x7f;	}}/* * calculate pitch parameter */static unsigned char pan_volumes[256] = {0x00,0x03,0x06,0x09,0x0c,0x0f,0x12,0x14,0x17,0x1a,0x1d,0x20,0x22,0x25,0x28,0x2a,0x2d,0x30,0x32,0x35,0x37,0x3a,0x3c,0x3f,0x41,0x44,0x46,0x49,0x4b,0x4d,0x50,0x52,0x54,0x57,0x59,0x5b,0x5d,0x60,0x62,0x64,0x66,0x68,0x6a,0x6c,0x6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_t *chan = vp->chan;	int pan;	/* pan & loop start (pan 8bit, MSB, 0:right, 0xff:left) */	if (vp->reg.fixpan > 0)	/* 0-127 */		pan = 255 - (int)vp->reg.fixpan * 2;	else {		pan = chan->control[MIDI_CTL_MSB_PAN] - 64;		if (vp->reg.pan >= 0) /* 0-127 */			pan += vp->reg.pan - 64;		pan = 127 - (int)pan * 2;	}	LIMITVALUE(pan, 0, 255);	if (vp->emu->linear_panning) {		/* assuming linear volume */		if (pan != vp->apan) {			vp->apan = pan;			if (pan == 0)				vp->aaux = 0xff;			else				vp->aaux = (-pan) & 0xff;			return 1;		} else			return 0;	} else {		/* using volume table */		if (vp->apan != (int)pan_volumes[pan]) {			vp->apan = pan_volumes[pan];			vp->aaux = pan_volumes[255 - pan];			return 1;		}		return 0;	}}/* * calculate volume attenuation * * Voice volume is controlled by volume attenuation parameter. * So volume becomes maximum when avol is 0 (no attenuation), and * minimum when 255 (-96dB or silence). *//* tables for volume->attenuation calculation */static unsigned char voltab1[128] = {   0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,   0x63, 0x2b, 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22,   0x21, 0x20, 0x1f, 0x1e, 0x1e, 0x1d, 0x1c, 0x1b, 0x1b, 0x1a,   0x19, 0x19, 0x18, 0x17, 0x17, 0x16, 0x16, 0x15, 0x15, 0x14,   0x14, 0x13, 0x13, 0x13, 0x12, 0x12, 0x11, 0x11, 0x11, 0x10,   0x10, 0x10, 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e, 0x0e, 0x0d,   0x0d, 0x0d, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0b, 0x0b, 0x0b,   0x0b, 0x0a, 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09,   0x08, 0x08, 0x08, 0x08, 0x08, 0x07, 0x07, 0x07, 0x07, 0x06,   0x06, 0x06, 0x06, 0x06, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04,   0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02,   0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01,   0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};static unsigned char voltab2[128] = {   0x32, 0x31, 0x30, 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x2a,   0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x24, 0x23, 0x22, 0x21,   0x21, 0x20, 0x1f, 0x1e, 0x1e, 0x1d, 0x1c, 0x1c, 0x1b, 0x1a,   0x1a, 0x19, 0x19, 0x18, 0x18, 0x17, 0x16, 0x16, 0x15, 0x15,   0x14, 0x14, 0x13, 0x13, 0x13, 0x12, 0x12, 0x11, 0x11, 0x10,   0x10, 0x10, 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e, 0x0d, 0x0d,   0x0d, 0x0c, 0x0c, 0x0c, 0x0b, 0x0b, 0x0b, 0x0b, 0x0a, 0x0a,   0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x08, 0x08, 0x08,   0x08, 0x08, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06,   0x06, 0x06, 0x06, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,   0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03,   0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01,   0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};static unsigned char expressiontab[128] = {   0x7f, 0x6c, 0x62, 0x5a, 0x54, 0x50, 0x4b, 0x48, 0x45, 0x42,   0x40, 0x3d, 0x3b, 0x39, 0x38, 0x36, 0x34, 0x33, 0x31, 0x30,   0x2f, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, 0x27, 0x26, 0x25,   0x24, 0x24, 0x23, 0x22, 0x21, 0x21, 0x20, 0x1f, 0x1e, 0x1e,   0x1d, 0x1d, 0x1c, 0x1b, 0x1b, 0x1a, 0x1a, 0x19, 0x18, 0x18,   0x17, 0x17, 0x16, 0x16, 0x15, 0x15, 0x15, 0x14, 0x14, 0x13,   0x13, 0x12, 0x12, 0x11, 0x11, 0x11, 0x10, 0x10, 0x0f, 0x0f,   0x0f, 0x0e, 0x0e, 0x0e, 0x0d, 0x0d, 0x0d, 0x0c, 0x0c, 0x0c,   0x0b, 0x0b, 0x0b, 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09,   0x08, 0x08, 0x08, 0x07, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06,   0x06, 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03,   0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01,   0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};/* * Magic to calculate the volume (actually attenuation) from all the * voice and channels parameters. */static intcalc_volume(snd_emux_voice_t *vp){	int vol;	int main_vol, expression_vol, master_vol;	snd_midi_channel_t *chan = vp->chan;	snd_emux_port_t *port = vp->port;	expression_vol = chan->control[MIDI_CTL_MSB_EXPRESSION];	LIMITMAX(vp->velocity, 127);	LIMITVALUE(expression_vol, 0, 127);	if (port->port_mode == SNDRV_EMUX_PORT_MODE_OSS_SYNTH) {		/* 0 - 127 */		main_vol = chan->control[MIDI_CTL_MSB_MAIN_VOLUME];		vol = (vp->velocity * main_vol * expression_vol) / (127*127);		vol = vol * vp->reg.amplitude / 127;		LIMITVALUE(vol, 0, 127);		/* calc to attenuation */		vol = snd_sf_vol_table[vol];	} else {		main_vol = chan->control[MIDI_CTL_MSB_MAIN_VOLUME] * vp->reg.amplitude / 127;		LIMITVALUE(main_vol, 0, 127);		vol = voltab1[main_vol] + voltab2[vp->velocity];		vol = (vol * 8) / 3;		vol += vp->reg.attenuation;		vol += ((0x100 - vol) * expressiontab[expression_vol])/128;	}	master_vol = port->chset.gs_master_volume;	LIMITVALUE(master_vol, 0, 127);	vol += snd_sf_vol_table[master_vol];	vol += port->volume_atten;#ifdef SNDRV_EMUX_USE_RAW_EFFECT	if (chan->private) {		snd_emux_effect_table_t *fx = chan->private;		vol += fx->val[EMUX_FX_ATTEN];	}#endif	LIMITVALUE(vol, 0, 255);	if (vp->avol == vol)		return 0; /* value unchanged */	vp->avol = vol;	if (!SF_IS_DRUM_BANK(get_bank(port, chan))	    && LO_BYTE(vp->reg.parm.volatkhld) < 0x7d) {		int atten;		if (vp->velocity < 70)			atten = 70;		else			atten = vp->velocity;		vp->acutoff = (atten * vp->reg.parm.cutoff + 0xa0) >> 7;	} else {		vp->acutoff = vp->reg.parm.cutoff;	}	return 1; /* value changed */}/* * calculate pitch offset * * 0xE000 is no pitch offset at 44100Hz sample. * Every 4096 is one octave. */static intcalc_pitch(snd_emux_voice_t *vp){	snd_midi_channel_t *chan = vp->chan;	int offset;	/* calculate offset */	if (vp->reg.fixkey >= 0) {		offset = (vp->reg.fixkey - vp->reg.root) * 4096 / 12;	} else {		offset = (vp->note - vp->reg.root) * 4096 / 12;	}	offset = (offset * vp->reg.scaleTuning) / 100;	offset += vp->reg.tune * 4096 / 1200;	if (chan->midi_pitchbend != 0) {		/* (128 * 8192: 1 semitone) ==> (4096: 12 semitones) */		offset += chan->midi_pitchbend * chan->gm_rpn_pitch_bend_range / 3072;	}	/* tuning via RPN:	 *   coarse = -8192 to 8192 (100 cent per 128)	 *   fine = -8192 to 8192 (max=100cent)	 */	/* 4096 = 1200 cents in emu8000 parameter */	offset += chan->gm_rpn_coarse_tuning * 4096 / (12 * 128);	offset += chan->gm_rpn_fine_tuning / 24;#ifdef SNDRV_EMUX_USE_RAW_EFFECT	/* add initial pitch correction */	if (chan->private) {		snd_emux_effect_table_t *fx = chan->private;		if (fx->flag[EMUX_FX_INIT_PITCH])			offset += fx->val[EMUX_FX_INIT_PITCH];	}#endif	/* 0xe000: root pitch */	offset += 0xe000 + vp->reg.rate_offset;	offset += vp->emu->pitch_shift;	LIMITVALUE(offset, 0, 0xffff);	if (offset == vp->apitch)		return 0; /* unchanged */	vp->apitch = offset;	return 1; /* value changed */}/* * Get the bank number assigned to the channel */static intget_bank(snd_emux_port_t *port, snd_midi_channel_t *chan){	int val;	switch (port->chset.midi_mode) {	case SNDRV_MIDI_MODE_XG:		val = chan->control[MIDI_CTL_MSB_BANK];		if (val == 127)			return 128; /* return drum bank */		return chan->control[MIDI_CTL_LSB_BANK];	case SNDRV_MIDI_MODE_GS:		if (chan->drum_channel)			return 128;		/* ignore LSB (bank map) */		return chan->control[MIDI_CTL_MSB_BANK];			default:		if (chan->drum_channel)			return 128;		return chan->control[MIDI_CTL_MSB_BANK];	}}/* Look for the zones matching with the given note and velocity. * The resultant zones are stored on table. */static intget_zone(snd_emux_t *emu, snd_emux_port_t *port,	 int *notep, int vel, snd_midi_channel_t *chan, snd_sf_zone_t **table){	int preset, bank, def_preset, def_bank;	bank = get_bank(port, chan);	preset = chan->midi_program;	if (SF_IS_DRUM_BANK(bank)) {		def_preset = port->ctrls[EMUX_MD_DEF_DRUM];		def_bank = bank;	} else {		def_preset = preset;		def_bank = port->ctrls[EMUX_MD_DEF_BANK];	}	return snd_soundfont_search_zone(emu->sflist, notep, vel, preset, bank,					 def_preset, def_bank,					 table, SNDRV_EMUX_MAX_MULTI_VOICES);}/* */voidsnd_emux_init_voices(snd_emux_t *emu){	snd_emux_voice_t *vp;	int i;	unsigned long flags;	spin_lock_irqsave(&emu->voice_lock, flags);	for (i = 0; i < emu->max_voices; i++) {		vp = &emu->voices[i];		vp->ch = -1; /* not used */		vp->state = SNDRV_EMUX_ST_OFF;		vp->chan = NULL;		vp->port = NULL;		vp->time = 0;		vp->emu = emu;		vp->hw = emu->hw;	}	spin_unlock_irqrestore(&emu->voice_lock, flags);}/* */void snd_emux_lock_voice(snd_emux_t *emu, int voice){	unsigned long flags;	spin_lock_irqsave(&emu->voice_lock, flags);	if (emu->voices[voice].state == SNDRV_EMUX_ST_OFF)		emu->voices[voice].state = SNDRV_EMUX_ST_LOCKED;	else		snd_printk("invalid voice for lock %d (state = %x)\n",			   voice, emu->voices[voice].state);	spin_unlock_irqrestore(&emu->voice_lock, flags);}/* */void snd_emux_unlock_voice(snd_emux_t *emu, int voice){	unsigned long flags;	spin_lock_irqsave(&emu->voice_lock, flags);	if (emu->voices[voice].state == SNDRV_EMUX_ST_LOCKED)		emu->voices[voice].state = SNDRV_EMUX_ST_OFF;	else		snd_printk("invalid voice for unlock %d (state = %x)\n",			   voice, emu->voices[voice].state);	spin_unlock_irqrestore(&emu->voice_lock, flags);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -