2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4 * Routines for control of EMU10K1 chips - voice manager
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <sound/driver.h>
29 #include <linux/time.h>
30 #include <sound/core.h>
31 #include <sound/emu10k1.h>
33 static int voice_alloc(emu10k1_t *emu, emu10k1_voice_type_t type, int pair, emu10k1_voice_t **rvoice)
35 emu10k1_voice_t *voice, *voice2;
39 for (idx = 0; idx < 64; idx += pair ? 2 : 1) {
40 voice = &emu->voices[idx];
41 voice2 = pair ? &emu->voices[idx+1] : NULL;
42 if (voice->use || (voice2 && voice2->use))
60 // printk("voice alloc - %i, pair = %i\n", voice->number, pair);
67 int snd_emu10k1_voice_alloc(emu10k1_t *emu, emu10k1_voice_type_t type, int pair, emu10k1_voice_t **rvoice)
72 snd_assert(rvoice != NULL, return -EINVAL);
73 snd_assert(!pair || type == EMU10K1_PCM, return -EINVAL);
75 spin_lock_irqsave(&emu->voice_lock, flags);
77 result = voice_alloc(emu, type, pair, rvoice);
78 if (result == 0 || type != EMU10K1_PCM)
81 /* free a voice from synth */
82 if (emu->get_synth_voice) {
83 result = emu->get_synth_voice(emu);
85 emu10k1_voice_t *pvoice = &emu->voices[result];
86 pvoice->interrupt = NULL;
87 pvoice->use = pvoice->pcm = pvoice->synth = pvoice->midi = 0;
94 spin_unlock_irqrestore(&emu->voice_lock, flags);
99 int snd_emu10k1_voice_free(emu10k1_t *emu, emu10k1_voice_t *pvoice)
103 snd_assert(pvoice != NULL, return -EINVAL);
104 spin_lock_irqsave(&emu->voice_lock, flags);
105 pvoice->interrupt = NULL;
106 pvoice->use = pvoice->pcm = pvoice->synth = pvoice->midi = 0;
108 snd_emu10k1_voice_init(emu, pvoice->number);
109 spin_unlock_irqrestore(&emu->voice_lock, flags);