Blame view
sound/pci/emu10k1/voice.c
4.53 KB
1da177e4c Linux-2.6.12-rc2 |
1 |
/* |
c1017a4cd [ALSA] Changed Ja... |
2 |
* Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
1da177e4c Linux-2.6.12-rc2 |
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
* Creative Labs, Inc. * Lee Revell <rlrevell@joe-job.com> * Routines for control of EMU10K1 chips - voice manager * * Rewrote voice allocator for multichannel support - rlrevell 12/2004 * * BUGS: * -- * * TODO: * -- * * 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 * */ |
1da177e4c Linux-2.6.12-rc2 |
30 |
#include <linux/time.h> |
d81a6d717 sound: Add export... |
31 |
#include <linux/export.h> |
1da177e4c Linux-2.6.12-rc2 |
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#include <sound/core.h> #include <sound/emu10k1.h> /* Previously the voice allocator started at 0 every time. The new voice * allocator uses a round robin scheme. The next free voice is tracked in * the card record and each allocation begins where the last left off. The * hardware requires stereo interleaved voices be aligned to an even/odd * boundary. For multichannel voice allocation we ensure than the block of * voices does not cross the 32 voice boundary. This simplifies the * multichannel support and ensures we can use a single write to the * (set|clear)_loop_stop registers. Otherwise (for example) the voices would * get out of sync when pausing/resuming a stream. * --rlrevell */ |
eb4698f34 [ALSA] Remove xxx... |
46 47 |
static int voice_alloc(struct snd_emu10k1 *emu, int type, int number, struct snd_emu10k1_voice **rvoice) |
1da177e4c Linux-2.6.12-rc2 |
48 |
{ |
eb4698f34 [ALSA] Remove xxx... |
49 |
struct snd_emu10k1_voice *voice; |
1da177e4c Linux-2.6.12-rc2 |
50 51 52 53 54 |
int i, j, k, first_voice, last_voice, skip; *rvoice = NULL; first_voice = last_voice = 0; for (i = emu->next_free_voice, j = 0; j < NUM_G ; i += number, j += number) { |
28a97c194 ALSA: emu10k1 - A... |
55 56 57 58 59 |
/* printk(KERN_DEBUG "i %d j %d next free %d! ", i, j, emu->next_free_voice); */ |
1da177e4c Linux-2.6.12-rc2 |
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
i %= NUM_G; /* stereo voices must be even/odd */ if ((number == 2) && (i % 2)) { i++; continue; } skip = 0; for (k = 0; k < number; k++) { voice = &emu->voices[(i+k) % NUM_G]; if (voice->use) { skip = 1; break; } } if (!skip) { |
28a97c194 ALSA: emu10k1 - A... |
77 78 |
/* printk(KERN_DEBUG "allocated voice %d ", i); */ |
1da177e4c Linux-2.6.12-rc2 |
79 80 81 82 83 84 85 86 87 88 |
first_voice = i; last_voice = (i + number) % NUM_G; emu->next_free_voice = last_voice; break; } } if (first_voice == last_voice) return -ENOMEM; |
9f4bd5dde [ALSA] snd-emu10k... |
89 |
for (i = 0; i < number; i++) { |
1da177e4c Linux-2.6.12-rc2 |
90 |
voice = &emu->voices[(first_voice + i) % NUM_G]; |
28a97c194 ALSA: emu10k1 - A... |
91 92 93 94 95 |
/* printk(kERN_DEBUG "voice alloc - %i, %i of %i ", voice->number, idx-first_voice+1, number); */ |
1da177e4c Linux-2.6.12-rc2 |
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
voice->use = 1; switch (type) { case EMU10K1_PCM: voice->pcm = 1; break; case EMU10K1_SYNTH: voice->synth = 1; break; case EMU10K1_MIDI: voice->midi = 1; break; case EMU10K1_EFX: voice->efx = 1; break; } } *rvoice = &emu->voices[first_voice]; return 0; } |
eb4698f34 [ALSA] Remove xxx... |
115 116 |
int snd_emu10k1_voice_alloc(struct snd_emu10k1 *emu, int type, int number, struct snd_emu10k1_voice **rvoice) |
1da177e4c Linux-2.6.12-rc2 |
117 118 119 |
{ unsigned long flags; int result; |
da3cec35d ALSA: Kill snd_as... |
120 121 122 123 |
if (snd_BUG_ON(!rvoice)) return -EINVAL; if (snd_BUG_ON(!number)) return -EINVAL; |
1da177e4c Linux-2.6.12-rc2 |
124 125 126 127 128 129 130 131 132 133 134 |
spin_lock_irqsave(&emu->voice_lock, flags); for (;;) { result = voice_alloc(emu, type, number, rvoice); if (result == 0 || type == EMU10K1_SYNTH || type == EMU10K1_MIDI) break; /* free a voice from synth */ if (emu->get_synth_voice) { result = emu->get_synth_voice(emu); if (result >= 0) { |
eb4698f34 [ALSA] Remove xxx... |
135 |
struct snd_emu10k1_voice *pvoice = &emu->voices[result]; |
1da177e4c Linux-2.6.12-rc2 |
136 137 138 139 140 141 142 143 144 145 146 147 |
pvoice->interrupt = NULL; pvoice->use = pvoice->pcm = pvoice->synth = pvoice->midi = pvoice->efx = 0; pvoice->epcm = NULL; } } if (result < 0) break; } spin_unlock_irqrestore(&emu->voice_lock, flags); return result; } |
2dd31deee [ALSA] emu10k1 - ... |
148 |
EXPORT_SYMBOL(snd_emu10k1_voice_alloc); |
eb4698f34 [ALSA] Remove xxx... |
149 150 |
int snd_emu10k1_voice_free(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *pvoice) |
1da177e4c Linux-2.6.12-rc2 |
151 152 |
{ unsigned long flags; |
da3cec35d ALSA: Kill snd_as... |
153 154 |
if (snd_BUG_ON(!pvoice)) return -EINVAL; |
1da177e4c Linux-2.6.12-rc2 |
155 156 157 158 159 160 161 162 |
spin_lock_irqsave(&emu->voice_lock, flags); pvoice->interrupt = NULL; pvoice->use = pvoice->pcm = pvoice->synth = pvoice->midi = pvoice->efx = 0; pvoice->epcm = NULL; snd_emu10k1_voice_init(emu, pvoice->number); spin_unlock_irqrestore(&emu->voice_lock, flags); return 0; } |
2dd31deee [ALSA] emu10k1 - ... |
163 164 |
EXPORT_SYMBOL(snd_emu10k1_voice_free); |