voice.c (3eb5b1d0a11d1daf85243eb06f813cf83752e1d0) voice.c (b840f8d8fcb3df9e65bb6782a9072897b6ea117d)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4 * Creative Labs, Inc.
5 * Lee Revell <rlrevell@joe-job.com>
6 * Routines for control of EMU10K1 chips - voice manager
7 *
8 * Rewrote voice allocator for multichannel support - rlrevell 12/2004

--- 64 unchanged lines hidden (view full) ---

73 return -ENOMEM;
74
75 for (i = 0; i < number; i++) {
76 voice = &emu->voices[(first_voice + i) % NUM_G];
77 /*
78 dev_dbg(emu->card->dev, "voice alloc - %i, %i of %i\n",
79 voice->number, idx-first_voice+1, number);
80 */
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4 * Creative Labs, Inc.
5 * Lee Revell <rlrevell@joe-job.com>
6 * Routines for control of EMU10K1 chips - voice manager
7 *
8 * Rewrote voice allocator for multichannel support - rlrevell 12/2004

--- 64 unchanged lines hidden (view full) ---

73 return -ENOMEM;
74
75 for (i = 0; i < number; i++) {
76 voice = &emu->voices[(first_voice + i) % NUM_G];
77 /*
78 dev_dbg(emu->card->dev, "voice alloc - %i, %i of %i\n",
79 voice->number, idx-first_voice+1, number);
80 */
81 voice->use = 1;
82 switch (type) {
83 case EMU10K1_PCM:
84 voice->pcm = 1;
85 break;
86 case EMU10K1_SYNTH:
87 voice->synth = 1;
88 break;
89 case EMU10K1_MIDI:
90 voice->midi = 1;
91 break;
92 case EMU10K1_EFX:
93 voice->efx = 1;
94 break;
95 }
81 voice->use = type;
96 }
97 *rvoice = &emu->voices[first_voice];
98 return 0;
99}
100
101static void voice_free(struct snd_emu10k1 *emu,
102 struct snd_emu10k1_voice *pvoice)
103{
104 snd_emu10k1_voice_init(emu, pvoice->number);
105 pvoice->interrupt = NULL;
82 }
83 *rvoice = &emu->voices[first_voice];
84 return 0;
85}
86
87static void voice_free(struct snd_emu10k1 *emu,
88 struct snd_emu10k1_voice *pvoice)
89{
90 snd_emu10k1_voice_init(emu, pvoice->number);
91 pvoice->interrupt = NULL;
106 pvoice->use = pvoice->pcm = pvoice->synth = pvoice->midi = pvoice->efx = 0;
92 pvoice->use = 0;
107 pvoice->epcm = NULL;
108}
109
110int snd_emu10k1_voice_alloc(struct snd_emu10k1 *emu, int type, int number,
111 struct snd_emu10k1_voice **rvoice)
112{
113 unsigned long flags;
114 int result;
115
116 if (snd_BUG_ON(!rvoice))
117 return -EINVAL;
118 if (snd_BUG_ON(!number))
119 return -EINVAL;
120
121 spin_lock_irqsave(&emu->voice_lock, flags);
122 for (;;) {
123 result = voice_alloc(emu, type, number, rvoice);
93 pvoice->epcm = NULL;
94}
95
96int snd_emu10k1_voice_alloc(struct snd_emu10k1 *emu, int type, int number,
97 struct snd_emu10k1_voice **rvoice)
98{
99 unsigned long flags;
100 int result;
101
102 if (snd_BUG_ON(!rvoice))
103 return -EINVAL;
104 if (snd_BUG_ON(!number))
105 return -EINVAL;
106
107 spin_lock_irqsave(&emu->voice_lock, flags);
108 for (;;) {
109 result = voice_alloc(emu, type, number, rvoice);
124 if (result == 0 || type == EMU10K1_SYNTH || type == EMU10K1_MIDI)
110 if (result == 0 || type == EMU10K1_SYNTH)
125 break;
126
127 /* free a voice from synth */
128 if (emu->get_synth_voice) {
129 result = emu->get_synth_voice(emu);
130 if (result >= 0)
131 voice_free(emu, &emu->voices[result]);
132 }

--- 24 unchanged lines hidden ---
111 break;
112
113 /* free a voice from synth */
114 if (emu->get_synth_voice) {
115 result = emu->get_synth_voice(emu);
116 if (result >= 0)
117 voice_free(emu, &emu->voices[result]);
118 }

--- 24 unchanged lines hidden ---