Blame view

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