aboutsummaryrefslogtreecommitdiffstats
path: root/sound/isa/gus/gus_sample.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /sound/isa/gus/gus_sample.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'sound/isa/gus/gus_sample.c')
-rw-r--r--sound/isa/gus/gus_sample.c155
1 files changed, 155 insertions, 0 deletions
diff --git a/sound/isa/gus/gus_sample.c b/sound/isa/gus/gus_sample.c
new file mode 100644
index 000000000000..4290e03acd51
--- /dev/null
+++ b/sound/isa/gus/gus_sample.c
@@ -0,0 +1,155 @@
1/*
2 * Routines for Gravis UltraSound soundcards - Sample support
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4 *
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include <sound/driver.h>
23#include <linux/time.h>
24#include <sound/core.h>
25#include <sound/gus.h>
26
27/*
28 *
29 */
30
31static void select_instrument(snd_gus_card_t * gus, snd_gus_voice_t * v)
32{
33 snd_seq_kinstr_t *instr;
34
35#if 0
36 printk("select instrument: cluster = %li, std = 0x%x, bank = %i, prg = %i\n",
37 v->instr.cluster,
38 v->instr.std,
39 v->instr.bank,
40 v->instr.prg);
41#endif
42 instr = snd_seq_instr_find(gus->gf1.ilist, &v->instr, 0, 1);
43 if (instr != NULL) {
44 if (instr->ops) {
45 if (!strcmp(instr->ops->instr_type, SNDRV_SEQ_INSTR_ID_SIMPLE))
46 snd_gf1_simple_init(v);
47 }
48 snd_seq_instr_free_use(gus->gf1.ilist, instr);
49 }
50}
51
52/*
53 *
54 */
55
56static void event_sample(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
57{
58 if (v->sample_ops && v->sample_ops->sample_stop)
59 v->sample_ops->sample_stop(p->gus, v, SAMPLE_STOP_IMMEDIATELY);
60 v->instr.std = ev->data.sample.param.sample.std;
61 if (v->instr.std & 0xff000000) { /* private instrument */
62 v->instr.std &= 0x00ffffff;
63 v->instr.std |= (unsigned int)ev->source.client << 24;
64 }
65 v->instr.bank = ev->data.sample.param.sample.bank;
66 v->instr.prg = ev->data.sample.param.sample.prg;
67 select_instrument(p->gus, v);
68}
69
70static void event_cluster(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
71{
72 if (v->sample_ops && v->sample_ops->sample_stop)
73 v->sample_ops->sample_stop(p->gus, v, SAMPLE_STOP_IMMEDIATELY);
74 v->instr.cluster = ev->data.sample.param.cluster.cluster;
75 select_instrument(p->gus, v);
76}
77
78static void event_start(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
79{
80 if (v->sample_ops && v->sample_ops->sample_start)
81 v->sample_ops->sample_start(p->gus, v, ev->data.sample.param.position);
82}
83
84static void event_stop(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
85{
86 if (v->sample_ops && v->sample_ops->sample_stop)
87 v->sample_ops->sample_stop(p->gus, v, ev->data.sample.param.stop_mode);
88}
89
90static void event_freq(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
91{
92 if (v->sample_ops && v->sample_ops->sample_freq)
93 v->sample_ops->sample_freq(p->gus, v, ev->data.sample.param.frequency);
94}
95
96static void event_volume(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
97{
98 if (v->sample_ops && v->sample_ops->sample_volume)
99 v->sample_ops->sample_volume(p->gus, v, &ev->data.sample.param.volume);
100}
101
102static void event_loop(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
103{
104 if (v->sample_ops && v->sample_ops->sample_loop)
105 v->sample_ops->sample_loop(p->gus, v, &ev->data.sample.param.loop);
106}
107
108static void event_position(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
109{
110 if (v->sample_ops && v->sample_ops->sample_pos)
111 v->sample_ops->sample_pos(p->gus, v, ev->data.sample.param.position);
112}
113
114static void event_private1(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v)
115{
116 if (v->sample_ops && v->sample_ops->sample_private1)
117 v->sample_ops->sample_private1(p->gus, v, (unsigned char *)&ev->data.sample.param.raw8);
118}
119
120typedef void (gus_sample_event_handler_t)(snd_seq_event_t *ev, snd_gus_port_t *p, snd_gus_voice_t *v);
121
122static gus_sample_event_handler_t *gus_sample_event_handlers[9] = {
123 event_sample,
124 event_cluster,
125 event_start,
126 event_stop,
127 event_freq,
128 event_volume,
129 event_loop,
130 event_position,
131 event_private1
132};
133
134void snd_gus_sample_event(snd_seq_event_t *ev, snd_gus_port_t *p)
135{
136 int idx, voice;
137 snd_gus_card_t *gus = p->gus;
138 snd_gus_voice_t *v;
139 unsigned long flags;
140
141 idx = ev->type - SNDRV_SEQ_EVENT_SAMPLE;
142 if (idx < 0 || idx > 8)
143 return;
144 for (voice = 0; voice < 32; voice++) {
145 v = &gus->gf1.voices[voice];
146 if (v->use && v->client == ev->source.client &&
147 v->port == ev->source.port &&
148 v->index == ev->data.sample.channel) {
149 spin_lock_irqsave(&gus->event_lock, flags);
150 gus_sample_event_handlers[idx](ev, p, v);
151 spin_unlock_irqrestore(&gus->event_lock, flags);
152 return;
153 }
154 }
155}