diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /sound/core/seq/instr |
Linux-2.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/core/seq/instr')
-rw-r--r-- | sound/core/seq/instr/Makefile | 23 | ||||
-rw-r--r-- | sound/core/seq/instr/ainstr_fm.c | 156 | ||||
-rw-r--r-- | sound/core/seq/instr/ainstr_gf1.c | 358 | ||||
-rw-r--r-- | sound/core/seq/instr/ainstr_iw.c | 622 | ||||
-rw-r--r-- | sound/core/seq/instr/ainstr_simple.c | 215 |
5 files changed, 1374 insertions, 0 deletions
diff --git a/sound/core/seq/instr/Makefile b/sound/core/seq/instr/Makefile new file mode 100644 index 00000000000..69138f30a29 --- /dev/null +++ b/sound/core/seq/instr/Makefile | |||
@@ -0,0 +1,23 @@ | |||
1 | # | ||
2 | # Makefile for ALSA | ||
3 | # Copyright (c) 1999 by Jaroslav Kysela <perex@suse.cz> | ||
4 | # | ||
5 | |||
6 | snd-ainstr-fm-objs := ainstr_fm.o | ||
7 | snd-ainstr-simple-objs := ainstr_simple.o | ||
8 | snd-ainstr-gf1-objs := ainstr_gf1.o | ||
9 | snd-ainstr-iw-objs := ainstr_iw.o | ||
10 | |||
11 | # | ||
12 | # this function returns: | ||
13 | # "m" - CONFIG_SND_SEQUENCER is m | ||
14 | # <empty string> - CONFIG_SND_SEQUENCER is undefined | ||
15 | # otherwise parameter #1 value | ||
16 | # | ||
17 | sequencer = $(if $(subst y,,$(CONFIG_SND_SEQUENCER)),$(if $(1),m),$(if $(CONFIG_SND_SEQUENCER),$(1))) | ||
18 | |||
19 | # Toplevel Module Dependency | ||
20 | obj-$(call sequencer,$(CONFIG_SND_OPL3_LIB)) += snd-ainstr-fm.o | ||
21 | obj-$(call sequencer,$(CONFIG_SND_OPL4_LIB)) += snd-ainstr-fm.o | ||
22 | obj-$(call sequencer,$(CONFIG_SND_GUS_SYNTH)) += snd-ainstr-gf1.o snd-ainstr-simple.o snd-ainstr-iw.o | ||
23 | obj-$(call sequencer,$(CONFIG_SND_TRIDENT)) += snd-ainstr-simple.o | ||
diff --git a/sound/core/seq/instr/ainstr_fm.c b/sound/core/seq/instr/ainstr_fm.c new file mode 100644 index 00000000000..5c671e69884 --- /dev/null +++ b/sound/core/seq/instr/ainstr_fm.c | |||
@@ -0,0 +1,156 @@ | |||
1 | /* | ||
2 | * FM (OPL2/3) Instrument routines | ||
3 | * Copyright (c) 2000 Uros Bizjak <uros@kss-loka.si> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | * | ||
19 | */ | ||
20 | |||
21 | #include <sound/driver.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/sched.h> | ||
24 | #include <sound/core.h> | ||
25 | #include <sound/ainstr_fm.h> | ||
26 | #include <sound/initval.h> | ||
27 | #include <asm/uaccess.h> | ||
28 | |||
29 | MODULE_AUTHOR("Uros Bizjak <uros@kss-loka.si>"); | ||
30 | MODULE_DESCRIPTION("Advanced Linux Sound Architecture FM Instrument support."); | ||
31 | MODULE_LICENSE("GPL"); | ||
32 | |||
33 | static int snd_seq_fm_put(void *private_data, snd_seq_kinstr_t *instr, | ||
34 | char __user *instr_data, long len, int atomic, int cmd) | ||
35 | { | ||
36 | fm_instrument_t *ip; | ||
37 | fm_xinstrument_t ix; | ||
38 | int idx; | ||
39 | |||
40 | if (cmd != SNDRV_SEQ_INSTR_PUT_CMD_CREATE) | ||
41 | return -EINVAL; | ||
42 | /* copy instrument data */ | ||
43 | if (len < (long)sizeof(ix)) | ||
44 | return -EINVAL; | ||
45 | if (copy_from_user(&ix, instr_data, sizeof(ix))) | ||
46 | return -EFAULT; | ||
47 | if (ix.stype != FM_STRU_INSTR) | ||
48 | return -EINVAL; | ||
49 | ip = (fm_instrument_t *)KINSTR_DATA(instr); | ||
50 | ip->share_id[0] = le32_to_cpu(ix.share_id[0]); | ||
51 | ip->share_id[1] = le32_to_cpu(ix.share_id[1]); | ||
52 | ip->share_id[2] = le32_to_cpu(ix.share_id[2]); | ||
53 | ip->share_id[3] = le32_to_cpu(ix.share_id[3]); | ||
54 | ip->type = ix.type; | ||
55 | for (idx = 0; idx < 4; idx++) { | ||
56 | ip->op[idx].am_vib = ix.op[idx].am_vib; | ||
57 | ip->op[idx].ksl_level = ix.op[idx].ksl_level; | ||
58 | ip->op[idx].attack_decay = ix.op[idx].attack_decay; | ||
59 | ip->op[idx].sustain_release = ix.op[idx].sustain_release; | ||
60 | ip->op[idx].wave_select = ix.op[idx].wave_select; | ||
61 | } | ||
62 | for (idx = 0; idx < 2; idx++) { | ||
63 | ip->feedback_connection[idx] = ix.feedback_connection[idx]; | ||
64 | } | ||
65 | ip->echo_delay = ix.echo_delay; | ||
66 | ip->echo_atten = ix.echo_atten; | ||
67 | ip->chorus_spread = ix.chorus_spread; | ||
68 | ip->trnsps = ix.trnsps; | ||
69 | ip->fix_dur = ix.fix_dur; | ||
70 | ip->modes = ix.modes; | ||
71 | ip->fix_key = ix.fix_key; | ||
72 | return 0; | ||
73 | } | ||
74 | |||
75 | static int snd_seq_fm_get(void *private_data, snd_seq_kinstr_t *instr, | ||
76 | char __user *instr_data, long len, int atomic, | ||
77 | int cmd) | ||
78 | { | ||
79 | fm_instrument_t *ip; | ||
80 | fm_xinstrument_t ix; | ||
81 | int idx; | ||
82 | |||
83 | if (cmd != SNDRV_SEQ_INSTR_GET_CMD_FULL) | ||
84 | return -EINVAL; | ||
85 | if (len < (long)sizeof(ix)) | ||
86 | return -ENOMEM; | ||
87 | memset(&ix, 0, sizeof(ix)); | ||
88 | ip = (fm_instrument_t *)KINSTR_DATA(instr); | ||
89 | ix.stype = FM_STRU_INSTR; | ||
90 | ix.share_id[0] = cpu_to_le32(ip->share_id[0]); | ||
91 | ix.share_id[1] = cpu_to_le32(ip->share_id[1]); | ||
92 | ix.share_id[2] = cpu_to_le32(ip->share_id[2]); | ||
93 | ix.share_id[3] = cpu_to_le32(ip->share_id[3]); | ||
94 | ix.type = ip->type; | ||
95 | for (idx = 0; idx < 4; idx++) { | ||
96 | ix.op[idx].am_vib = ip->op[idx].am_vib; | ||
97 | ix.op[idx].ksl_level = ip->op[idx].ksl_level; | ||
98 | ix.op[idx].attack_decay = ip->op[idx].attack_decay; | ||
99 | ix.op[idx].sustain_release = ip->op[idx].sustain_release; | ||
100 | ix.op[idx].wave_select = ip->op[idx].wave_select; | ||
101 | } | ||
102 | for (idx = 0; idx < 2; idx++) { | ||
103 | ix.feedback_connection[idx] = ip->feedback_connection[idx]; | ||
104 | } | ||
105 | if (copy_to_user(instr_data, &ix, sizeof(ix))) | ||
106 | return -EFAULT; | ||
107 | ix.echo_delay = ip->echo_delay; | ||
108 | ix.echo_atten = ip->echo_atten; | ||
109 | ix.chorus_spread = ip->chorus_spread; | ||
110 | ix.trnsps = ip->trnsps; | ||
111 | ix.fix_dur = ip->fix_dur; | ||
112 | ix.modes = ip->modes; | ||
113 | ix.fix_key = ip->fix_key; | ||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | static int snd_seq_fm_get_size(void *private_data, snd_seq_kinstr_t *instr, | ||
118 | long *size) | ||
119 | { | ||
120 | *size = sizeof(fm_xinstrument_t); | ||
121 | return 0; | ||
122 | } | ||
123 | |||
124 | int snd_seq_fm_init(snd_seq_kinstr_ops_t *ops, | ||
125 | snd_seq_kinstr_ops_t *next) | ||
126 | { | ||
127 | memset(ops, 0, sizeof(*ops)); | ||
128 | // ops->private_data = private_data; | ||
129 | ops->add_len = sizeof(fm_instrument_t); | ||
130 | ops->instr_type = SNDRV_SEQ_INSTR_ID_OPL2_3; | ||
131 | ops->put = snd_seq_fm_put; | ||
132 | ops->get = snd_seq_fm_get; | ||
133 | ops->get_size = snd_seq_fm_get_size; | ||
134 | // ops->remove = snd_seq_fm_remove; | ||
135 | // ops->notify = snd_seq_fm_notify; | ||
136 | ops->next = next; | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | /* | ||
141 | * Init part | ||
142 | */ | ||
143 | |||
144 | static int __init alsa_ainstr_fm_init(void) | ||
145 | { | ||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | static void __exit alsa_ainstr_fm_exit(void) | ||
150 | { | ||
151 | } | ||
152 | |||
153 | module_init(alsa_ainstr_fm_init) | ||
154 | module_exit(alsa_ainstr_fm_exit) | ||
155 | |||
156 | EXPORT_SYMBOL(snd_seq_fm_init); | ||
diff --git a/sound/core/seq/instr/ainstr_gf1.c b/sound/core/seq/instr/ainstr_gf1.c new file mode 100644 index 00000000000..0779c41ca03 --- /dev/null +++ b/sound/core/seq/instr/ainstr_gf1.c | |||
@@ -0,0 +1,358 @@ | |||
1 | /* | ||
2 | * GF1 (GUS) Patch - Instrument routines | ||
3 | * Copyright (c) 1999 by Jaroslav Kysela <perex@suse.cz> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | * | ||
19 | */ | ||
20 | |||
21 | #include <sound/driver.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/sched.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <sound/core.h> | ||
26 | #include <sound/ainstr_gf1.h> | ||
27 | #include <sound/initval.h> | ||
28 | #include <asm/uaccess.h> | ||
29 | |||
30 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); | ||
31 | MODULE_DESCRIPTION("Advanced Linux Sound Architecture GF1 (GUS) Patch support."); | ||
32 | MODULE_LICENSE("GPL"); | ||
33 | |||
34 | static unsigned int snd_seq_gf1_size(unsigned int size, unsigned int format) | ||
35 | { | ||
36 | unsigned int result = size; | ||
37 | |||
38 | if (format & GF1_WAVE_16BIT) | ||
39 | result <<= 1; | ||
40 | if (format & GF1_WAVE_STEREO) | ||
41 | result <<= 1; | ||
42 | return format; | ||
43 | } | ||
44 | |||
45 | static int snd_seq_gf1_copy_wave_from_stream(snd_gf1_ops_t *ops, | ||
46 | gf1_instrument_t *ip, | ||
47 | char __user **data, | ||
48 | long *len, | ||
49 | int atomic) | ||
50 | { | ||
51 | gf1_wave_t *wp, *prev; | ||
52 | gf1_xwave_t xp; | ||
53 | int err, gfp_mask; | ||
54 | unsigned int real_size; | ||
55 | |||
56 | gfp_mask = atomic ? GFP_ATOMIC : GFP_KERNEL; | ||
57 | if (*len < (long)sizeof(xp)) | ||
58 | return -EINVAL; | ||
59 | if (copy_from_user(&xp, *data, sizeof(xp))) | ||
60 | return -EFAULT; | ||
61 | *data += sizeof(xp); | ||
62 | *len -= sizeof(xp); | ||
63 | wp = kcalloc(1, sizeof(*wp), gfp_mask); | ||
64 | if (wp == NULL) | ||
65 | return -ENOMEM; | ||
66 | wp->share_id[0] = le32_to_cpu(xp.share_id[0]); | ||
67 | wp->share_id[1] = le32_to_cpu(xp.share_id[1]); | ||
68 | wp->share_id[2] = le32_to_cpu(xp.share_id[2]); | ||
69 | wp->share_id[3] = le32_to_cpu(xp.share_id[3]); | ||
70 | wp->format = le32_to_cpu(xp.format); | ||
71 | wp->size = le32_to_cpu(xp.size); | ||
72 | wp->start = le32_to_cpu(xp.start); | ||
73 | wp->loop_start = le32_to_cpu(xp.loop_start); | ||
74 | wp->loop_end = le32_to_cpu(xp.loop_end); | ||
75 | wp->loop_repeat = le16_to_cpu(xp.loop_repeat); | ||
76 | wp->flags = xp.flags; | ||
77 | wp->sample_rate = le32_to_cpu(xp.sample_rate); | ||
78 | wp->low_frequency = le32_to_cpu(xp.low_frequency); | ||
79 | wp->high_frequency = le32_to_cpu(xp.high_frequency); | ||
80 | wp->root_frequency = le32_to_cpu(xp.root_frequency); | ||
81 | wp->tune = le16_to_cpu(xp.tune); | ||
82 | wp->balance = xp.balance; | ||
83 | memcpy(wp->envelope_rate, xp.envelope_rate, 6); | ||
84 | memcpy(wp->envelope_offset, xp.envelope_offset, 6); | ||
85 | wp->tremolo_sweep = xp.tremolo_sweep; | ||
86 | wp->tremolo_rate = xp.tremolo_rate; | ||
87 | wp->tremolo_depth = xp.tremolo_depth; | ||
88 | wp->vibrato_sweep = xp.vibrato_sweep; | ||
89 | wp->vibrato_rate = xp.vibrato_rate; | ||
90 | wp->vibrato_depth = xp.vibrato_depth; | ||
91 | wp->scale_frequency = le16_to_cpu(xp.scale_frequency); | ||
92 | wp->scale_factor = le16_to_cpu(xp.scale_factor); | ||
93 | real_size = snd_seq_gf1_size(wp->size, wp->format); | ||
94 | if ((long)real_size > *len) { | ||
95 | kfree(wp); | ||
96 | return -ENOMEM; | ||
97 | } | ||
98 | if (ops->put_sample) { | ||
99 | err = ops->put_sample(ops->private_data, wp, | ||
100 | *data, real_size, atomic); | ||
101 | if (err < 0) { | ||
102 | kfree(wp); | ||
103 | return err; | ||
104 | } | ||
105 | } | ||
106 | *data += real_size; | ||
107 | *len -= real_size; | ||
108 | prev = ip->wave; | ||
109 | if (prev) { | ||
110 | while (prev->next) prev = prev->next; | ||
111 | prev->next = wp; | ||
112 | } else { | ||
113 | ip->wave = wp; | ||
114 | } | ||
115 | return 0; | ||
116 | } | ||
117 | |||
118 | static void snd_seq_gf1_wave_free(snd_gf1_ops_t *ops, | ||
119 | gf1_wave_t *wave, | ||
120 | int atomic) | ||
121 | { | ||
122 | if (ops->remove_sample) | ||
123 | ops->remove_sample(ops->private_data, wave, atomic); | ||
124 | kfree(wave); | ||
125 | } | ||
126 | |||
127 | static void snd_seq_gf1_instr_free(snd_gf1_ops_t *ops, | ||
128 | gf1_instrument_t *ip, | ||
129 | int atomic) | ||
130 | { | ||
131 | gf1_wave_t *wave; | ||
132 | |||
133 | while ((wave = ip->wave) != NULL) { | ||
134 | ip->wave = wave->next; | ||
135 | snd_seq_gf1_wave_free(ops, wave, atomic); | ||
136 | } | ||
137 | } | ||
138 | |||
139 | static int snd_seq_gf1_put(void *private_data, snd_seq_kinstr_t *instr, | ||
140 | char __user *instr_data, long len, int atomic, | ||
141 | int cmd) | ||
142 | { | ||
143 | snd_gf1_ops_t *ops = (snd_gf1_ops_t *)private_data; | ||
144 | gf1_instrument_t *ip; | ||
145 | gf1_xinstrument_t ix; | ||
146 | int err, gfp_mask; | ||
147 | |||
148 | if (cmd != SNDRV_SEQ_INSTR_PUT_CMD_CREATE) | ||
149 | return -EINVAL; | ||
150 | gfp_mask = atomic ? GFP_ATOMIC : GFP_KERNEL; | ||
151 | /* copy instrument data */ | ||
152 | if (len < (long)sizeof(ix)) | ||
153 | return -EINVAL; | ||
154 | if (copy_from_user(&ix, instr_data, sizeof(ix))) | ||
155 | return -EFAULT; | ||
156 | if (ix.stype != GF1_STRU_INSTR) | ||
157 | return -EINVAL; | ||
158 | instr_data += sizeof(ix); | ||
159 | len -= sizeof(ix); | ||
160 | ip = (gf1_instrument_t *)KINSTR_DATA(instr); | ||
161 | ip->exclusion = le16_to_cpu(ix.exclusion); | ||
162 | ip->exclusion_group = le16_to_cpu(ix.exclusion_group); | ||
163 | ip->effect1 = ix.effect1; | ||
164 | ip->effect1_depth = ix.effect1_depth; | ||
165 | ip->effect2 = ix.effect2; | ||
166 | ip->effect2_depth = ix.effect2_depth; | ||
167 | /* copy layers */ | ||
168 | while (len > (long)sizeof(__u32)) { | ||
169 | __u32 stype; | ||
170 | |||
171 | if (copy_from_user(&stype, instr_data, sizeof(stype))) | ||
172 | return -EFAULT; | ||
173 | if (stype != GF1_STRU_WAVE) { | ||
174 | snd_seq_gf1_instr_free(ops, ip, atomic); | ||
175 | return -EINVAL; | ||
176 | } | ||
177 | err = snd_seq_gf1_copy_wave_from_stream(ops, | ||
178 | ip, | ||
179 | &instr_data, | ||
180 | &len, | ||
181 | atomic); | ||
182 | if (err < 0) { | ||
183 | snd_seq_gf1_instr_free(ops, ip, atomic); | ||
184 | return err; | ||
185 | } | ||
186 | } | ||
187 | return 0; | ||
188 | } | ||
189 | |||
190 | static int snd_seq_gf1_copy_wave_to_stream(snd_gf1_ops_t *ops, | ||
191 | gf1_instrument_t *ip, | ||
192 | char __user **data, | ||
193 | long *len, | ||
194 | int atomic) | ||
195 | { | ||
196 | gf1_wave_t *wp; | ||
197 | gf1_xwave_t xp; | ||
198 | int err; | ||
199 | unsigned int real_size; | ||
200 | |||
201 | for (wp = ip->wave; wp; wp = wp->next) { | ||
202 | if (*len < (long)sizeof(xp)) | ||
203 | return -ENOMEM; | ||
204 | memset(&xp, 0, sizeof(xp)); | ||
205 | xp.stype = GF1_STRU_WAVE; | ||
206 | xp.share_id[0] = cpu_to_le32(wp->share_id[0]); | ||
207 | xp.share_id[1] = cpu_to_le32(wp->share_id[1]); | ||
208 | xp.share_id[2] = cpu_to_le32(wp->share_id[2]); | ||
209 | xp.share_id[3] = cpu_to_le32(wp->share_id[3]); | ||
210 | xp.format = cpu_to_le32(wp->format); | ||
211 | xp.size = cpu_to_le32(wp->size); | ||
212 | xp.start = cpu_to_le32(wp->start); | ||
213 | xp.loop_start = cpu_to_le32(wp->loop_start); | ||
214 | xp.loop_end = cpu_to_le32(wp->loop_end); | ||
215 | xp.loop_repeat = cpu_to_le32(wp->loop_repeat); | ||
216 | xp.flags = wp->flags; | ||
217 | xp.sample_rate = cpu_to_le32(wp->sample_rate); | ||
218 | xp.low_frequency = cpu_to_le32(wp->low_frequency); | ||
219 | xp.high_frequency = cpu_to_le32(wp->high_frequency); | ||
220 | xp.root_frequency = cpu_to_le32(wp->root_frequency); | ||
221 | xp.tune = cpu_to_le16(wp->tune); | ||
222 | xp.balance = wp->balance; | ||
223 | memcpy(xp.envelope_rate, wp->envelope_rate, 6); | ||
224 | memcpy(xp.envelope_offset, wp->envelope_offset, 6); | ||
225 | xp.tremolo_sweep = wp->tremolo_sweep; | ||
226 | xp.tremolo_rate = wp->tremolo_rate; | ||
227 | xp.tremolo_depth = wp->tremolo_depth; | ||
228 | xp.vibrato_sweep = wp->vibrato_sweep; | ||
229 | xp.vibrato_rate = wp->vibrato_rate; | ||
230 | xp.vibrato_depth = wp->vibrato_depth; | ||
231 | xp.scale_frequency = cpu_to_le16(wp->scale_frequency); | ||
232 | xp.scale_factor = cpu_to_le16(wp->scale_factor); | ||
233 | if (copy_to_user(*data, &xp, sizeof(xp))) | ||
234 | return -EFAULT; | ||
235 | *data += sizeof(xp); | ||
236 | *len -= sizeof(xp); | ||
237 | real_size = snd_seq_gf1_size(wp->size, wp->format); | ||
238 | if (*len < (long)real_size) | ||
239 | return -ENOMEM; | ||
240 | if (ops->get_sample) { | ||
241 | err = ops->get_sample(ops->private_data, wp, | ||
242 | *data, real_size, atomic); | ||
243 | if (err < 0) | ||
244 | return err; | ||
245 | } | ||
246 | *data += wp->size; | ||
247 | *len -= wp->size; | ||
248 | } | ||
249 | return 0; | ||
250 | } | ||
251 | |||
252 | static int snd_seq_gf1_get(void *private_data, snd_seq_kinstr_t *instr, | ||
253 | char __user *instr_data, long len, int atomic, | ||
254 | int cmd) | ||
255 | { | ||
256 | snd_gf1_ops_t *ops = (snd_gf1_ops_t *)private_data; | ||
257 | gf1_instrument_t *ip; | ||
258 | gf1_xinstrument_t ix; | ||
259 | |||
260 | if (cmd != SNDRV_SEQ_INSTR_GET_CMD_FULL) | ||
261 | return -EINVAL; | ||
262 | if (len < (long)sizeof(ix)) | ||
263 | return -ENOMEM; | ||
264 | memset(&ix, 0, sizeof(ix)); | ||
265 | ip = (gf1_instrument_t *)KINSTR_DATA(instr); | ||
266 | ix.stype = GF1_STRU_INSTR; | ||
267 | ix.exclusion = cpu_to_le16(ip->exclusion); | ||
268 | ix.exclusion_group = cpu_to_le16(ip->exclusion_group); | ||
269 | ix.effect1 = cpu_to_le16(ip->effect1); | ||
270 | ix.effect1_depth = cpu_to_le16(ip->effect1_depth); | ||
271 | ix.effect2 = ip->effect2; | ||
272 | ix.effect2_depth = ip->effect2_depth; | ||
273 | if (copy_to_user(instr_data, &ix, sizeof(ix))) | ||
274 | return -EFAULT; | ||
275 | instr_data += sizeof(ix); | ||
276 | len -= sizeof(ix); | ||
277 | return snd_seq_gf1_copy_wave_to_stream(ops, | ||
278 | ip, | ||
279 | &instr_data, | ||
280 | &len, | ||
281 | atomic); | ||
282 | } | ||
283 | |||
284 | static int snd_seq_gf1_get_size(void *private_data, snd_seq_kinstr_t *instr, | ||
285 | long *size) | ||
286 | { | ||
287 | long result; | ||
288 | gf1_instrument_t *ip; | ||
289 | gf1_wave_t *wp; | ||
290 | |||
291 | *size = 0; | ||
292 | ip = (gf1_instrument_t *)KINSTR_DATA(instr); | ||
293 | result = sizeof(gf1_xinstrument_t); | ||
294 | for (wp = ip->wave; wp; wp = wp->next) { | ||
295 | result += sizeof(gf1_xwave_t); | ||
296 | result += wp->size; | ||
297 | } | ||
298 | *size = result; | ||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | static int snd_seq_gf1_remove(void *private_data, | ||
303 | snd_seq_kinstr_t *instr, | ||
304 | int atomic) | ||
305 | { | ||
306 | snd_gf1_ops_t *ops = (snd_gf1_ops_t *)private_data; | ||
307 | gf1_instrument_t *ip; | ||
308 | |||
309 | ip = (gf1_instrument_t *)KINSTR_DATA(instr); | ||
310 | snd_seq_gf1_instr_free(ops, ip, atomic); | ||
311 | return 0; | ||
312 | } | ||
313 | |||
314 | static void snd_seq_gf1_notify(void *private_data, | ||
315 | snd_seq_kinstr_t *instr, | ||
316 | int what) | ||
317 | { | ||
318 | snd_gf1_ops_t *ops = (snd_gf1_ops_t *)private_data; | ||
319 | |||
320 | if (ops->notify) | ||
321 | ops->notify(ops->private_data, instr, what); | ||
322 | } | ||
323 | |||
324 | int snd_seq_gf1_init(snd_gf1_ops_t *ops, | ||
325 | void *private_data, | ||
326 | snd_seq_kinstr_ops_t *next) | ||
327 | { | ||
328 | memset(ops, 0, sizeof(*ops)); | ||
329 | ops->private_data = private_data; | ||
330 | ops->kops.private_data = ops; | ||
331 | ops->kops.add_len = sizeof(gf1_instrument_t); | ||
332 | ops->kops.instr_type = SNDRV_SEQ_INSTR_ID_GUS_PATCH; | ||
333 | ops->kops.put = snd_seq_gf1_put; | ||
334 | ops->kops.get = snd_seq_gf1_get; | ||
335 | ops->kops.get_size = snd_seq_gf1_get_size; | ||
336 | ops->kops.remove = snd_seq_gf1_remove; | ||
337 | ops->kops.notify = snd_seq_gf1_notify; | ||
338 | ops->kops.next = next; | ||
339 | return 0; | ||
340 | } | ||
341 | |||
342 | /* | ||
343 | * Init part | ||
344 | */ | ||
345 | |||
346 | static int __init alsa_ainstr_gf1_init(void) | ||
347 | { | ||
348 | return 0; | ||
349 | } | ||
350 | |||
351 | static void __exit alsa_ainstr_gf1_exit(void) | ||
352 | { | ||
353 | } | ||
354 | |||
355 | module_init(alsa_ainstr_gf1_init) | ||
356 | module_exit(alsa_ainstr_gf1_exit) | ||
357 | |||
358 | EXPORT_SYMBOL(snd_seq_gf1_init); | ||
diff --git a/sound/core/seq/instr/ainstr_iw.c b/sound/core/seq/instr/ainstr_iw.c new file mode 100644 index 00000000000..39ff72b2aab --- /dev/null +++ b/sound/core/seq/instr/ainstr_iw.c | |||
@@ -0,0 +1,622 @@ | |||
1 | /* | ||
2 | * IWFFFF - AMD InterWave (tm) - Instrument routines | ||
3 | * Copyright (c) 1999 by Jaroslav Kysela <perex@suse.cz> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | * | ||
19 | */ | ||
20 | |||
21 | #include <sound/driver.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/sched.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <sound/core.h> | ||
26 | #include <sound/ainstr_iw.h> | ||
27 | #include <sound/initval.h> | ||
28 | #include <asm/uaccess.h> | ||
29 | |||
30 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); | ||
31 | MODULE_DESCRIPTION("Advanced Linux Sound Architecture IWFFFF support."); | ||
32 | MODULE_LICENSE("GPL"); | ||
33 | |||
34 | static unsigned int snd_seq_iwffff_size(unsigned int size, unsigned int format) | ||
35 | { | ||
36 | unsigned int result = size; | ||
37 | |||
38 | if (format & IWFFFF_WAVE_16BIT) | ||
39 | result <<= 1; | ||
40 | if (format & IWFFFF_WAVE_STEREO) | ||
41 | result <<= 1; | ||
42 | return result; | ||
43 | } | ||
44 | |||
45 | static void snd_seq_iwffff_copy_lfo_from_stream(iwffff_lfo_t *fp, | ||
46 | iwffff_xlfo_t *fx) | ||
47 | { | ||
48 | fp->freq = le16_to_cpu(fx->freq); | ||
49 | fp->depth = le16_to_cpu(fx->depth); | ||
50 | fp->sweep = le16_to_cpu(fx->sweep); | ||
51 | fp->shape = fx->shape; | ||
52 | fp->delay = fx->delay; | ||
53 | } | ||
54 | |||
55 | static int snd_seq_iwffff_copy_env_from_stream(__u32 req_stype, | ||
56 | iwffff_layer_t *lp, | ||
57 | iwffff_env_t *ep, | ||
58 | iwffff_xenv_t *ex, | ||
59 | char __user **data, | ||
60 | long *len, | ||
61 | int gfp_mask) | ||
62 | { | ||
63 | __u32 stype; | ||
64 | iwffff_env_record_t *rp, *rp_last; | ||
65 | iwffff_xenv_record_t rx; | ||
66 | iwffff_env_point_t *pp; | ||
67 | iwffff_xenv_point_t px; | ||
68 | int points_size, idx; | ||
69 | |||
70 | ep->flags = ex->flags; | ||
71 | ep->mode = ex->mode; | ||
72 | ep->index = ex->index; | ||
73 | rp_last = NULL; | ||
74 | while (1) { | ||
75 | if (*len < (long)sizeof(__u32)) | ||
76 | return -EINVAL; | ||
77 | if (copy_from_user(&stype, *data, sizeof(stype))) | ||
78 | return -EFAULT; | ||
79 | if (stype == IWFFFF_STRU_WAVE) | ||
80 | return 0; | ||
81 | if (req_stype != stype) { | ||
82 | if (stype == IWFFFF_STRU_ENV_RECP || | ||
83 | stype == IWFFFF_STRU_ENV_RECV) | ||
84 | return 0; | ||
85 | } | ||
86 | if (*len < (long)sizeof(rx)) | ||
87 | return -EINVAL; | ||
88 | if (copy_from_user(&rx, *data, sizeof(rx))) | ||
89 | return -EFAULT; | ||
90 | *data += sizeof(rx); | ||
91 | *len -= sizeof(rx); | ||
92 | points_size = (le16_to_cpu(rx.nattack) + le16_to_cpu(rx.nrelease)) * 2 * sizeof(__u16); | ||
93 | if (points_size > *len) | ||
94 | return -EINVAL; | ||
95 | rp = kcalloc(1, sizeof(*rp) + points_size, gfp_mask); | ||
96 | if (rp == NULL) | ||
97 | return -ENOMEM; | ||
98 | rp->nattack = le16_to_cpu(rx.nattack); | ||
99 | rp->nrelease = le16_to_cpu(rx.nrelease); | ||
100 | rp->sustain_offset = le16_to_cpu(rx.sustain_offset); | ||
101 | rp->sustain_rate = le16_to_cpu(rx.sustain_rate); | ||
102 | rp->release_rate = le16_to_cpu(rx.release_rate); | ||
103 | rp->hirange = rx.hirange; | ||
104 | pp = (iwffff_env_point_t *)(rp + 1); | ||
105 | for (idx = 0; idx < rp->nattack + rp->nrelease; idx++) { | ||
106 | if (copy_from_user(&px, *data, sizeof(px))) | ||
107 | return -EFAULT; | ||
108 | *data += sizeof(px); | ||
109 | *len -= sizeof(px); | ||
110 | pp->offset = le16_to_cpu(px.offset); | ||
111 | pp->rate = le16_to_cpu(px.rate); | ||
112 | } | ||
113 | if (ep->record == NULL) { | ||
114 | ep->record = rp; | ||
115 | } else { | ||
116 | rp_last = rp; | ||
117 | } | ||
118 | rp_last = rp; | ||
119 | } | ||
120 | return 0; | ||
121 | } | ||
122 | |||
123 | static int snd_seq_iwffff_copy_wave_from_stream(snd_iwffff_ops_t *ops, | ||
124 | iwffff_layer_t *lp, | ||
125 | char __user **data, | ||
126 | long *len, | ||
127 | int atomic) | ||
128 | { | ||
129 | iwffff_wave_t *wp, *prev; | ||
130 | iwffff_xwave_t xp; | ||
131 | int err, gfp_mask; | ||
132 | unsigned int real_size; | ||
133 | |||
134 | gfp_mask = atomic ? GFP_ATOMIC : GFP_KERNEL; | ||
135 | if (*len < (long)sizeof(xp)) | ||
136 | return -EINVAL; | ||
137 | if (copy_from_user(&xp, *data, sizeof(xp))) | ||
138 | return -EFAULT; | ||
139 | *data += sizeof(xp); | ||
140 | *len -= sizeof(xp); | ||
141 | wp = kcalloc(1, sizeof(*wp), gfp_mask); | ||
142 | if (wp == NULL) | ||
143 | return -ENOMEM; | ||
144 | wp->share_id[0] = le32_to_cpu(xp.share_id[0]); | ||
145 | wp->share_id[1] = le32_to_cpu(xp.share_id[1]); | ||
146 | wp->share_id[2] = le32_to_cpu(xp.share_id[2]); | ||
147 | wp->share_id[3] = le32_to_cpu(xp.share_id[3]); | ||
148 | wp->format = le32_to_cpu(xp.format); | ||
149 | wp->address.memory = le32_to_cpu(xp.offset); | ||
150 | wp->size = le32_to_cpu(xp.size); | ||
151 | wp->start = le32_to_cpu(xp.start); | ||
152 | wp->loop_start = le32_to_cpu(xp.loop_start); | ||
153 | wp->loop_end = le32_to_cpu(xp.loop_end); | ||
154 | wp->loop_repeat = le16_to_cpu(xp.loop_repeat); | ||
155 | wp->sample_ratio = le32_to_cpu(xp.sample_ratio); | ||
156 | wp->attenuation = xp.attenuation; | ||
157 | wp->low_note = xp.low_note; | ||
158 | wp->high_note = xp.high_note; | ||
159 | real_size = snd_seq_iwffff_size(wp->size, wp->format); | ||
160 | if (!(wp->format & IWFFFF_WAVE_ROM)) { | ||
161 | if ((long)real_size > *len) { | ||
162 | kfree(wp); | ||
163 | return -ENOMEM; | ||
164 | } | ||
165 | } | ||
166 | if (ops->put_sample) { | ||
167 | err = ops->put_sample(ops->private_data, wp, | ||
168 | *data, real_size, atomic); | ||
169 | if (err < 0) { | ||
170 | kfree(wp); | ||
171 | return err; | ||
172 | } | ||
173 | } | ||
174 | if (!(wp->format & IWFFFF_WAVE_ROM)) { | ||
175 | *data += real_size; | ||
176 | *len -= real_size; | ||
177 | } | ||
178 | prev = lp->wave; | ||
179 | if (prev) { | ||
180 | while (prev->next) prev = prev->next; | ||
181 | prev->next = wp; | ||
182 | } else { | ||
183 | lp->wave = wp; | ||
184 | } | ||
185 | return 0; | ||
186 | } | ||
187 | |||
188 | static void snd_seq_iwffff_env_free(snd_iwffff_ops_t *ops, | ||
189 | iwffff_env_t *env, | ||
190 | int atomic) | ||
191 | { | ||
192 | iwffff_env_record_t *rec; | ||
193 | |||
194 | while ((rec = env->record) != NULL) { | ||
195 | env->record = rec->next; | ||
196 | kfree(rec); | ||
197 | } | ||
198 | } | ||
199 | |||
200 | static void snd_seq_iwffff_wave_free(snd_iwffff_ops_t *ops, | ||
201 | iwffff_wave_t *wave, | ||
202 | int atomic) | ||
203 | { | ||
204 | if (ops->remove_sample) | ||
205 | ops->remove_sample(ops->private_data, wave, atomic); | ||
206 | kfree(wave); | ||
207 | } | ||
208 | |||
209 | static void snd_seq_iwffff_instr_free(snd_iwffff_ops_t *ops, | ||
210 | iwffff_instrument_t *ip, | ||
211 | int atomic) | ||
212 | { | ||
213 | iwffff_layer_t *layer; | ||
214 | iwffff_wave_t *wave; | ||
215 | |||
216 | while ((layer = ip->layer) != NULL) { | ||
217 | ip->layer = layer->next; | ||
218 | snd_seq_iwffff_env_free(ops, &layer->penv, atomic); | ||
219 | snd_seq_iwffff_env_free(ops, &layer->venv, atomic); | ||
220 | while ((wave = layer->wave) != NULL) { | ||
221 | layer->wave = wave->next; | ||
222 | snd_seq_iwffff_wave_free(ops, wave, atomic); | ||
223 | } | ||
224 | kfree(layer); | ||
225 | } | ||
226 | } | ||
227 | |||
228 | static int snd_seq_iwffff_put(void *private_data, snd_seq_kinstr_t *instr, | ||
229 | char __user *instr_data, long len, int atomic, | ||
230 | int cmd) | ||
231 | { | ||
232 | snd_iwffff_ops_t *ops = (snd_iwffff_ops_t *)private_data; | ||
233 | iwffff_instrument_t *ip; | ||
234 | iwffff_xinstrument_t ix; | ||
235 | iwffff_layer_t *lp, *prev_lp; | ||
236 | iwffff_xlayer_t lx; | ||
237 | int err, gfp_mask; | ||
238 | |||
239 | if (cmd != SNDRV_SEQ_INSTR_PUT_CMD_CREATE) | ||
240 | return -EINVAL; | ||
241 | gfp_mask = atomic ? GFP_ATOMIC : GFP_KERNEL; | ||
242 | /* copy instrument data */ | ||
243 | if (len < (long)sizeof(ix)) | ||
244 | return -EINVAL; | ||
245 | if (copy_from_user(&ix, instr_data, sizeof(ix))) | ||
246 | return -EFAULT; | ||
247 | if (ix.stype != IWFFFF_STRU_INSTR) | ||
248 | return -EINVAL; | ||
249 | instr_data += sizeof(ix); | ||
250 | len -= sizeof(ix); | ||
251 | ip = (iwffff_instrument_t *)KINSTR_DATA(instr); | ||
252 | ip->exclusion = le16_to_cpu(ix.exclusion); | ||
253 | ip->layer_type = le16_to_cpu(ix.layer_type); | ||
254 | ip->exclusion_group = le16_to_cpu(ix.exclusion_group); | ||
255 | ip->effect1 = ix.effect1; | ||
256 | ip->effect1_depth = ix.effect1_depth; | ||
257 | ip->effect2 = ix.effect2; | ||
258 | ip->effect2_depth = ix.effect2_depth; | ||
259 | /* copy layers */ | ||
260 | prev_lp = NULL; | ||
261 | while (len > 0) { | ||
262 | if (len < (long)sizeof(iwffff_xlayer_t)) { | ||
263 | snd_seq_iwffff_instr_free(ops, ip, atomic); | ||
264 | return -EINVAL; | ||
265 | } | ||
266 | if (copy_from_user(&lx, instr_data, sizeof(lx))) | ||
267 | return -EFAULT; | ||
268 | instr_data += sizeof(lx); | ||
269 | len -= sizeof(lx); | ||
270 | if (lx.stype != IWFFFF_STRU_LAYER) { | ||
271 | snd_seq_iwffff_instr_free(ops, ip, atomic); | ||
272 | return -EINVAL; | ||
273 | } | ||
274 | lp = kcalloc(1, sizeof(*lp), gfp_mask); | ||
275 | if (lp == NULL) { | ||
276 | snd_seq_iwffff_instr_free(ops, ip, atomic); | ||
277 | return -ENOMEM; | ||
278 | } | ||
279 | if (prev_lp) { | ||
280 | prev_lp->next = lp; | ||
281 | } else { | ||
282 | ip->layer = lp; | ||
283 | } | ||
284 | prev_lp = lp; | ||
285 | lp->flags = lx.flags; | ||
286 | lp->velocity_mode = lx.velocity_mode; | ||
287 | lp->layer_event = lx.layer_event; | ||
288 | lp->low_range = lx.low_range; | ||
289 | lp->high_range = lx.high_range; | ||
290 | lp->pan = lx.pan; | ||
291 | lp->pan_freq_scale = lx.pan_freq_scale; | ||
292 | lp->attenuation = lx.attenuation; | ||
293 | snd_seq_iwffff_copy_lfo_from_stream(&lp->tremolo, &lx.tremolo); | ||
294 | snd_seq_iwffff_copy_lfo_from_stream(&lp->vibrato, &lx.vibrato); | ||
295 | lp->freq_scale = le16_to_cpu(lx.freq_scale); | ||
296 | lp->freq_center = lx.freq_center; | ||
297 | err = snd_seq_iwffff_copy_env_from_stream(IWFFFF_STRU_ENV_RECP, | ||
298 | lp, | ||
299 | &lp->penv, &lx.penv, | ||
300 | &instr_data, &len, | ||
301 | gfp_mask); | ||
302 | if (err < 0) { | ||
303 | snd_seq_iwffff_instr_free(ops, ip, atomic); | ||
304 | return err; | ||
305 | } | ||
306 | err = snd_seq_iwffff_copy_env_from_stream(IWFFFF_STRU_ENV_RECV, | ||
307 | lp, | ||
308 | &lp->venv, &lx.venv, | ||
309 | &instr_data, &len, | ||
310 | gfp_mask); | ||
311 | if (err < 0) { | ||
312 | snd_seq_iwffff_instr_free(ops, ip, atomic); | ||
313 | return err; | ||
314 | } | ||
315 | while (len > (long)sizeof(__u32)) { | ||
316 | __u32 stype; | ||
317 | |||
318 | if (copy_from_user(&stype, instr_data, sizeof(stype))) | ||
319 | return -EFAULT; | ||
320 | if (stype != IWFFFF_STRU_WAVE) | ||
321 | break; | ||
322 | err = snd_seq_iwffff_copy_wave_from_stream(ops, | ||
323 | lp, | ||
324 | &instr_data, | ||
325 | &len, | ||
326 | atomic); | ||
327 | if (err < 0) { | ||
328 | snd_seq_iwffff_instr_free(ops, ip, atomic); | ||
329 | return err; | ||
330 | } | ||
331 | } | ||
332 | } | ||
333 | return 0; | ||
334 | } | ||
335 | |||
336 | static void snd_seq_iwffff_copy_lfo_to_stream(iwffff_xlfo_t *fx, | ||
337 | iwffff_lfo_t *fp) | ||
338 | { | ||
339 | fx->freq = cpu_to_le16(fp->freq); | ||
340 | fx->depth = cpu_to_le16(fp->depth); | ||
341 | fx->sweep = cpu_to_le16(fp->sweep); | ||
342 | fp->shape = fx->shape; | ||
343 | fp->delay = fx->delay; | ||
344 | } | ||
345 | |||
346 | static int snd_seq_iwffff_copy_env_to_stream(__u32 req_stype, | ||
347 | iwffff_layer_t *lp, | ||
348 | iwffff_xenv_t *ex, | ||
349 | iwffff_env_t *ep, | ||
350 | char __user **data, | ||
351 | long *len) | ||
352 | { | ||
353 | iwffff_env_record_t *rp; | ||
354 | iwffff_xenv_record_t rx; | ||
355 | iwffff_env_point_t *pp; | ||
356 | iwffff_xenv_point_t px; | ||
357 | int points_size, idx; | ||
358 | |||
359 | ex->flags = ep->flags; | ||
360 | ex->mode = ep->mode; | ||
361 | ex->index = ep->index; | ||
362 | for (rp = ep->record; rp; rp = rp->next) { | ||
363 | if (*len < (long)sizeof(rx)) | ||
364 | return -ENOMEM; | ||
365 | memset(&rx, 0, sizeof(rx)); | ||
366 | rx.stype = req_stype; | ||
367 | rx.nattack = cpu_to_le16(rp->nattack); | ||
368 | rx.nrelease = cpu_to_le16(rp->nrelease); | ||
369 | rx.sustain_offset = cpu_to_le16(rp->sustain_offset); | ||
370 | rx.sustain_rate = cpu_to_le16(rp->sustain_rate); | ||
371 | rx.release_rate = cpu_to_le16(rp->release_rate); | ||
372 | rx.hirange = cpu_to_le16(rp->hirange); | ||
373 | if (copy_to_user(*data, &rx, sizeof(rx))) | ||
374 | return -EFAULT; | ||
375 | *data += sizeof(rx); | ||
376 | *len -= sizeof(rx); | ||
377 | points_size = (rp->nattack + rp->nrelease) * 2 * sizeof(__u16); | ||
378 | if (*len < points_size) | ||
379 | return -ENOMEM; | ||
380 | pp = (iwffff_env_point_t *)(rp + 1); | ||
381 | for (idx = 0; idx < rp->nattack + rp->nrelease; idx++) { | ||
382 | px.offset = cpu_to_le16(pp->offset); | ||
383 | px.rate = cpu_to_le16(pp->rate); | ||
384 | if (copy_to_user(*data, &px, sizeof(px))) | ||
385 | return -EFAULT; | ||
386 | *data += sizeof(px); | ||
387 | *len -= sizeof(px); | ||
388 | } | ||
389 | } | ||
390 | return 0; | ||
391 | } | ||
392 | |||
393 | static int snd_seq_iwffff_copy_wave_to_stream(snd_iwffff_ops_t *ops, | ||
394 | iwffff_layer_t *lp, | ||
395 | char __user **data, | ||
396 | long *len, | ||
397 | int atomic) | ||
398 | { | ||
399 | iwffff_wave_t *wp; | ||
400 | iwffff_xwave_t xp; | ||
401 | int err; | ||
402 | unsigned int real_size; | ||
403 | |||
404 | for (wp = lp->wave; wp; wp = wp->next) { | ||
405 | if (*len < (long)sizeof(xp)) | ||
406 | return -ENOMEM; | ||
407 | memset(&xp, 0, sizeof(xp)); | ||
408 | xp.stype = IWFFFF_STRU_WAVE; | ||
409 | xp.share_id[0] = cpu_to_le32(wp->share_id[0]); | ||
410 | xp.share_id[1] = cpu_to_le32(wp->share_id[1]); | ||
411 | xp.share_id[2] = cpu_to_le32(wp->share_id[2]); | ||
412 | xp.share_id[3] = cpu_to_le32(wp->share_id[3]); | ||
413 | xp.format = cpu_to_le32(wp->format); | ||
414 | if (wp->format & IWFFFF_WAVE_ROM) | ||
415 | xp.offset = cpu_to_le32(wp->address.memory); | ||
416 | xp.size = cpu_to_le32(wp->size); | ||
417 | xp.start = cpu_to_le32(wp->start); | ||
418 | xp.loop_start = cpu_to_le32(wp->loop_start); | ||
419 | xp.loop_end = cpu_to_le32(wp->loop_end); | ||
420 | xp.loop_repeat = cpu_to_le32(wp->loop_repeat); | ||
421 | xp.sample_ratio = cpu_to_le32(wp->sample_ratio); | ||
422 | xp.attenuation = wp->attenuation; | ||
423 | xp.low_note = wp->low_note; | ||
424 | xp.high_note = wp->high_note; | ||
425 | if (copy_to_user(*data, &xp, sizeof(xp))) | ||
426 | return -EFAULT; | ||
427 | *data += sizeof(xp); | ||
428 | *len -= sizeof(xp); | ||
429 | real_size = snd_seq_iwffff_size(wp->size, wp->format); | ||
430 | if (!(wp->format & IWFFFF_WAVE_ROM)) { | ||
431 | if (*len < (long)real_size) | ||
432 | return -ENOMEM; | ||
433 | } | ||
434 | if (ops->get_sample) { | ||
435 | err = ops->get_sample(ops->private_data, wp, | ||
436 | *data, real_size, atomic); | ||
437 | if (err < 0) | ||
438 | return err; | ||
439 | } | ||
440 | if (!(wp->format & IWFFFF_WAVE_ROM)) { | ||
441 | *data += real_size; | ||
442 | *len -= real_size; | ||
443 | } | ||
444 | } | ||
445 | return 0; | ||
446 | } | ||
447 | |||
448 | static int snd_seq_iwffff_get(void *private_data, snd_seq_kinstr_t *instr, | ||
449 | char __user *instr_data, long len, int atomic, int cmd) | ||
450 | { | ||
451 | snd_iwffff_ops_t *ops = (snd_iwffff_ops_t *)private_data; | ||
452 | iwffff_instrument_t *ip; | ||
453 | iwffff_xinstrument_t ix; | ||
454 | iwffff_layer_t *lp; | ||
455 | iwffff_xlayer_t lx; | ||
456 | char __user *layer_instr_data; | ||
457 | int err; | ||
458 | |||
459 | if (cmd != SNDRV_SEQ_INSTR_GET_CMD_FULL) | ||
460 | return -EINVAL; | ||
461 | if (len < (long)sizeof(ix)) | ||
462 | return -ENOMEM; | ||
463 | memset(&ix, 0, sizeof(ix)); | ||
464 | ip = (iwffff_instrument_t *)KINSTR_DATA(instr); | ||
465 | ix.stype = IWFFFF_STRU_INSTR; | ||
466 | ix.exclusion = cpu_to_le16(ip->exclusion); | ||
467 | ix.layer_type = cpu_to_le16(ip->layer_type); | ||
468 | ix.exclusion_group = cpu_to_le16(ip->exclusion_group); | ||
469 | ix.effect1 = cpu_to_le16(ip->effect1); | ||
470 | ix.effect1_depth = cpu_to_le16(ip->effect1_depth); | ||
471 | ix.effect2 = ip->effect2; | ||
472 | ix.effect2_depth = ip->effect2_depth; | ||
473 | if (copy_to_user(instr_data, &ix, sizeof(ix))) | ||
474 | return -EFAULT; | ||
475 | instr_data += sizeof(ix); | ||
476 | len -= sizeof(ix); | ||
477 | for (lp = ip->layer; lp; lp = lp->next) { | ||
478 | if (len < (long)sizeof(lx)) | ||
479 | return -ENOMEM; | ||
480 | memset(&lx, 0, sizeof(lx)); | ||
481 | lx.stype = IWFFFF_STRU_LAYER; | ||
482 | lx.flags = lp->flags; | ||
483 | lx.velocity_mode = lp->velocity_mode; | ||
484 | lx.layer_event = lp->layer_event; | ||
485 | lx.low_range = lp->low_range; | ||
486 | lx.high_range = lp->high_range; | ||
487 | lx.pan = lp->pan; | ||
488 | lx.pan_freq_scale = lp->pan_freq_scale; | ||
489 | lx.attenuation = lp->attenuation; | ||
490 | snd_seq_iwffff_copy_lfo_to_stream(&lx.tremolo, &lp->tremolo); | ||
491 | snd_seq_iwffff_copy_lfo_to_stream(&lx.vibrato, &lp->vibrato); | ||
492 | layer_instr_data = instr_data; | ||
493 | instr_data += sizeof(lx); | ||
494 | len -= sizeof(lx); | ||
495 | err = snd_seq_iwffff_copy_env_to_stream(IWFFFF_STRU_ENV_RECP, | ||
496 | lp, | ||
497 | &lx.penv, &lp->penv, | ||
498 | &instr_data, &len); | ||
499 | if (err < 0) | ||
500 | return err; | ||
501 | err = snd_seq_iwffff_copy_env_to_stream(IWFFFF_STRU_ENV_RECV, | ||
502 | lp, | ||
503 | &lx.venv, &lp->venv, | ||
504 | &instr_data, &len); | ||
505 | if (err < 0) | ||
506 | return err; | ||
507 | /* layer structure updating is now finished */ | ||
508 | if (copy_to_user(layer_instr_data, &lx, sizeof(lx))) | ||
509 | return -EFAULT; | ||
510 | err = snd_seq_iwffff_copy_wave_to_stream(ops, | ||
511 | lp, | ||
512 | &instr_data, | ||
513 | &len, | ||
514 | atomic); | ||
515 | if (err < 0) | ||
516 | return err; | ||
517 | } | ||
518 | return 0; | ||
519 | } | ||
520 | |||
521 | static long snd_seq_iwffff_env_size_in_stream(iwffff_env_t *ep) | ||
522 | { | ||
523 | long result = 0; | ||
524 | iwffff_env_record_t *rp; | ||
525 | |||
526 | for (rp = ep->record; rp; rp = rp->next) { | ||
527 | result += sizeof(iwffff_xenv_record_t); | ||
528 | result += (rp->nattack + rp->nrelease) * 2 * sizeof(__u16); | ||
529 | } | ||
530 | return 0; | ||
531 | } | ||
532 | |||
533 | static long snd_seq_iwffff_wave_size_in_stream(iwffff_layer_t *lp) | ||
534 | { | ||
535 | long result = 0; | ||
536 | iwffff_wave_t *wp; | ||
537 | |||
538 | for (wp = lp->wave; wp; wp = wp->next) { | ||
539 | result += sizeof(iwffff_xwave_t); | ||
540 | if (!(wp->format & IWFFFF_WAVE_ROM)) | ||
541 | result += wp->size; | ||
542 | } | ||
543 | return result; | ||
544 | } | ||
545 | |||
546 | static int snd_seq_iwffff_get_size(void *private_data, snd_seq_kinstr_t *instr, | ||
547 | long *size) | ||
548 | { | ||
549 | long result; | ||
550 | iwffff_instrument_t *ip; | ||
551 | iwffff_layer_t *lp; | ||
552 | |||
553 | *size = 0; | ||
554 | ip = (iwffff_instrument_t *)KINSTR_DATA(instr); | ||
555 | result = sizeof(iwffff_xinstrument_t); | ||
556 | for (lp = ip->layer; lp; lp = lp->next) { | ||
557 | result += sizeof(iwffff_xlayer_t); | ||
558 | result += snd_seq_iwffff_env_size_in_stream(&lp->penv); | ||
559 | result += snd_seq_iwffff_env_size_in_stream(&lp->venv); | ||
560 | result += snd_seq_iwffff_wave_size_in_stream(lp); | ||
561 | } | ||
562 | *size = result; | ||
563 | return 0; | ||
564 | } | ||
565 | |||
566 | static int snd_seq_iwffff_remove(void *private_data, | ||
567 | snd_seq_kinstr_t *instr, | ||
568 | int atomic) | ||
569 | { | ||
570 | snd_iwffff_ops_t *ops = (snd_iwffff_ops_t *)private_data; | ||
571 | iwffff_instrument_t *ip; | ||
572 | |||
573 | ip = (iwffff_instrument_t *)KINSTR_DATA(instr); | ||
574 | snd_seq_iwffff_instr_free(ops, ip, atomic); | ||
575 | return 0; | ||
576 | } | ||
577 | |||
578 | static void snd_seq_iwffff_notify(void *private_data, | ||
579 | snd_seq_kinstr_t *instr, | ||
580 | int what) | ||
581 | { | ||
582 | snd_iwffff_ops_t *ops = (snd_iwffff_ops_t *)private_data; | ||
583 | |||
584 | if (ops->notify) | ||
585 | ops->notify(ops->private_data, instr, what); | ||
586 | } | ||
587 | |||
588 | int snd_seq_iwffff_init(snd_iwffff_ops_t *ops, | ||
589 | void *private_data, | ||
590 | snd_seq_kinstr_ops_t *next) | ||
591 | { | ||
592 | memset(ops, 0, sizeof(*ops)); | ||
593 | ops->private_data = private_data; | ||
594 | ops->kops.private_data = ops; | ||
595 | ops->kops.add_len = sizeof(iwffff_instrument_t); | ||
596 | ops->kops.instr_type = SNDRV_SEQ_INSTR_ID_INTERWAVE; | ||
597 | ops->kops.put = snd_seq_iwffff_put; | ||
598 | ops->kops.get = snd_seq_iwffff_get; | ||
599 | ops->kops.get_size = snd_seq_iwffff_get_size; | ||
600 | ops->kops.remove = snd_seq_iwffff_remove; | ||
601 | ops->kops.notify = snd_seq_iwffff_notify; | ||
602 | ops->kops.next = next; | ||
603 | return 0; | ||
604 | } | ||
605 | |||
606 | /* | ||
607 | * Init part | ||
608 | */ | ||
609 | |||
610 | static int __init alsa_ainstr_iw_init(void) | ||
611 | { | ||
612 | return 0; | ||
613 | } | ||
614 | |||
615 | static void __exit alsa_ainstr_iw_exit(void) | ||
616 | { | ||
617 | } | ||
618 | |||
619 | module_init(alsa_ainstr_iw_init) | ||
620 | module_exit(alsa_ainstr_iw_exit) | ||
621 | |||
622 | EXPORT_SYMBOL(snd_seq_iwffff_init); | ||
diff --git a/sound/core/seq/instr/ainstr_simple.c b/sound/core/seq/instr/ainstr_simple.c new file mode 100644 index 00000000000..6183d215103 --- /dev/null +++ b/sound/core/seq/instr/ainstr_simple.c | |||
@@ -0,0 +1,215 @@ | |||
1 | /* | ||
2 | * Simple (MOD player) - Instrument routines | ||
3 | * Copyright (c) 1999 by Jaroslav Kysela <perex@suse.cz> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | * | ||
19 | */ | ||
20 | |||
21 | #include <sound/driver.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/sched.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <sound/core.h> | ||
26 | #include <sound/ainstr_simple.h> | ||
27 | #include <sound/initval.h> | ||
28 | #include <asm/uaccess.h> | ||
29 | |||
30 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); | ||
31 | MODULE_DESCRIPTION("Advanced Linux Sound Architecture Simple Instrument support."); | ||
32 | MODULE_LICENSE("GPL"); | ||
33 | |||
34 | static unsigned int snd_seq_simple_size(unsigned int size, unsigned int format) | ||
35 | { | ||
36 | unsigned int result = size; | ||
37 | |||
38 | if (format & SIMPLE_WAVE_16BIT) | ||
39 | result <<= 1; | ||
40 | if (format & SIMPLE_WAVE_STEREO) | ||
41 | result <<= 1; | ||
42 | return result; | ||
43 | } | ||
44 | |||
45 | static void snd_seq_simple_instr_free(snd_simple_ops_t *ops, | ||
46 | simple_instrument_t *ip, | ||
47 | int atomic) | ||
48 | { | ||
49 | if (ops->remove_sample) | ||
50 | ops->remove_sample(ops->private_data, ip, atomic); | ||
51 | } | ||
52 | |||
53 | static int snd_seq_simple_put(void *private_data, snd_seq_kinstr_t *instr, | ||
54 | char __user *instr_data, long len, | ||
55 | int atomic, int cmd) | ||
56 | { | ||
57 | snd_simple_ops_t *ops = (snd_simple_ops_t *)private_data; | ||
58 | simple_instrument_t *ip; | ||
59 | simple_xinstrument_t ix; | ||
60 | int err, gfp_mask; | ||
61 | unsigned int real_size; | ||
62 | |||
63 | if (cmd != SNDRV_SEQ_INSTR_PUT_CMD_CREATE) | ||
64 | return -EINVAL; | ||
65 | gfp_mask = atomic ? GFP_ATOMIC : GFP_KERNEL; | ||
66 | /* copy instrument data */ | ||
67 | if (len < (long)sizeof(ix)) | ||
68 | return -EINVAL; | ||
69 | if (copy_from_user(&ix, instr_data, sizeof(ix))) | ||
70 | return -EFAULT; | ||
71 | if (ix.stype != SIMPLE_STRU_INSTR) | ||
72 | return -EINVAL; | ||
73 | instr_data += sizeof(ix); | ||
74 | len -= sizeof(ix); | ||
75 | ip = (simple_instrument_t *)KINSTR_DATA(instr); | ||
76 | ip->share_id[0] = le32_to_cpu(ix.share_id[0]); | ||
77 | ip->share_id[1] = le32_to_cpu(ix.share_id[1]); | ||
78 | ip->share_id[2] = le32_to_cpu(ix.share_id[2]); | ||
79 | ip->share_id[3] = le32_to_cpu(ix.share_id[3]); | ||
80 | ip->format = le32_to_cpu(ix.format); | ||
81 | ip->size = le32_to_cpu(ix.size); | ||
82 | ip->start = le32_to_cpu(ix.start); | ||
83 | ip->loop_start = le32_to_cpu(ix.loop_start); | ||
84 | ip->loop_end = le32_to_cpu(ix.loop_end); | ||
85 | ip->loop_repeat = le16_to_cpu(ix.loop_repeat); | ||
86 | ip->effect1 = ix.effect1; | ||
87 | ip->effect1_depth = ix.effect1_depth; | ||
88 | ip->effect2 = ix.effect2; | ||
89 | ip->effect2_depth = ix.effect2_depth; | ||
90 | real_size = snd_seq_simple_size(ip->size, ip->format); | ||
91 | if (len < (long)real_size) | ||
92 | return -EINVAL; | ||
93 | if (ops->put_sample) { | ||
94 | err = ops->put_sample(ops->private_data, ip, | ||
95 | instr_data, real_size, atomic); | ||
96 | if (err < 0) | ||
97 | return err; | ||
98 | } | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | static int snd_seq_simple_get(void *private_data, snd_seq_kinstr_t *instr, | ||
103 | char __user *instr_data, long len, | ||
104 | int atomic, int cmd) | ||
105 | { | ||
106 | snd_simple_ops_t *ops = (snd_simple_ops_t *)private_data; | ||
107 | simple_instrument_t *ip; | ||
108 | simple_xinstrument_t ix; | ||
109 | int err; | ||
110 | unsigned int real_size; | ||
111 | |||
112 | if (cmd != SNDRV_SEQ_INSTR_GET_CMD_FULL) | ||
113 | return -EINVAL; | ||
114 | if (len < (long)sizeof(ix)) | ||
115 | return -ENOMEM; | ||
116 | memset(&ix, 0, sizeof(ix)); | ||
117 | ip = (simple_instrument_t *)KINSTR_DATA(instr); | ||
118 | ix.stype = SIMPLE_STRU_INSTR; | ||
119 | ix.share_id[0] = cpu_to_le32(ip->share_id[0]); | ||
120 | ix.share_id[1] = cpu_to_le32(ip->share_id[1]); | ||
121 | ix.share_id[2] = cpu_to_le32(ip->share_id[2]); | ||
122 | ix.share_id[3] = cpu_to_le32(ip->share_id[3]); | ||
123 | ix.format = cpu_to_le32(ip->format); | ||
124 | ix.size = cpu_to_le32(ip->size); | ||
125 | ix.start = cpu_to_le32(ip->start); | ||
126 | ix.loop_start = cpu_to_le32(ip->loop_start); | ||
127 | ix.loop_end = cpu_to_le32(ip->loop_end); | ||
128 | ix.loop_repeat = cpu_to_le32(ip->loop_repeat); | ||
129 | ix.effect1 = cpu_to_le16(ip->effect1); | ||
130 | ix.effect1_depth = cpu_to_le16(ip->effect1_depth); | ||
131 | ix.effect2 = ip->effect2; | ||
132 | ix.effect2_depth = ip->effect2_depth; | ||
133 | if (copy_to_user(instr_data, &ix, sizeof(ix))) | ||
134 | return -EFAULT; | ||
135 | instr_data += sizeof(ix); | ||
136 | len -= sizeof(ix); | ||
137 | real_size = snd_seq_simple_size(ip->size, ip->format); | ||
138 | if (len < (long)real_size) | ||
139 | return -ENOMEM; | ||
140 | if (ops->get_sample) { | ||
141 | err = ops->get_sample(ops->private_data, ip, | ||
142 | instr_data, real_size, atomic); | ||
143 | if (err < 0) | ||
144 | return err; | ||
145 | } | ||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | static int snd_seq_simple_get_size(void *private_data, snd_seq_kinstr_t *instr, | ||
150 | long *size) | ||
151 | { | ||
152 | simple_instrument_t *ip; | ||
153 | |||
154 | ip = (simple_instrument_t *)KINSTR_DATA(instr); | ||
155 | *size = sizeof(simple_xinstrument_t) + snd_seq_simple_size(ip->size, ip->format); | ||
156 | return 0; | ||
157 | } | ||
158 | |||
159 | static int snd_seq_simple_remove(void *private_data, | ||
160 | snd_seq_kinstr_t *instr, | ||
161 | int atomic) | ||
162 | { | ||
163 | snd_simple_ops_t *ops = (snd_simple_ops_t *)private_data; | ||
164 | simple_instrument_t *ip; | ||
165 | |||
166 | ip = (simple_instrument_t *)KINSTR_DATA(instr); | ||
167 | snd_seq_simple_instr_free(ops, ip, atomic); | ||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | static void snd_seq_simple_notify(void *private_data, | ||
172 | snd_seq_kinstr_t *instr, | ||
173 | int what) | ||
174 | { | ||
175 | snd_simple_ops_t *ops = (snd_simple_ops_t *)private_data; | ||
176 | |||
177 | if (ops->notify) | ||
178 | ops->notify(ops->private_data, instr, what); | ||
179 | } | ||
180 | |||
181 | int snd_seq_simple_init(snd_simple_ops_t *ops, | ||
182 | void *private_data, | ||
183 | snd_seq_kinstr_ops_t *next) | ||
184 | { | ||
185 | memset(ops, 0, sizeof(*ops)); | ||
186 | ops->private_data = private_data; | ||
187 | ops->kops.private_data = ops; | ||
188 | ops->kops.add_len = sizeof(simple_instrument_t); | ||
189 | ops->kops.instr_type = SNDRV_SEQ_INSTR_ID_SIMPLE; | ||
190 | ops->kops.put = snd_seq_simple_put; | ||
191 | ops->kops.get = snd_seq_simple_get; | ||
192 | ops->kops.get_size = snd_seq_simple_get_size; | ||
193 | ops->kops.remove = snd_seq_simple_remove; | ||
194 | ops->kops.notify = snd_seq_simple_notify; | ||
195 | ops->kops.next = next; | ||
196 | return 0; | ||
197 | } | ||
198 | |||
199 | /* | ||
200 | * Init part | ||
201 | */ | ||
202 | |||
203 | static int __init alsa_ainstr_simple_init(void) | ||
204 | { | ||
205 | return 0; | ||
206 | } | ||
207 | |||
208 | static void __exit alsa_ainstr_simple_exit(void) | ||
209 | { | ||
210 | } | ||
211 | |||
212 | module_init(alsa_ainstr_simple_init) | ||
213 | module_exit(alsa_ainstr_simple_exit) | ||
214 | |||
215 | EXPORT_SYMBOL(snd_seq_simple_init); | ||