1 | /*
|
---|
2 | * Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
|
---|
3 | *
|
---|
4 | * Routines for control of EMU WaveTable chip
|
---|
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 | #include <sound/driver.h>
|
---|
22 | #include <linux/wait.h>
|
---|
23 | #include <linux/sched.h>
|
---|
24 | #include <linux/slab.h>
|
---|
25 | #include <sound/core.h>
|
---|
26 | #include <sound/emux_synth.h>
|
---|
27 | #include <linux/init.h>
|
---|
28 | #include "emux_voice.h"
|
---|
29 |
|
---|
30 | MODULE_AUTHOR("Takashi Iwai");
|
---|
31 | MODULE_DESCRIPTION("Routines for control of EMU WaveTable chip");
|
---|
32 | MODULE_LICENSE("GPL");
|
---|
33 |
|
---|
34 | /*
|
---|
35 | * create a new hardware dependent device for Emu8000/Emu10k1
|
---|
36 | */
|
---|
37 | int snd_emux_new(snd_emux_t **remu)
|
---|
38 | {
|
---|
39 | snd_emux_t *emu;
|
---|
40 |
|
---|
41 | *remu = NULL;
|
---|
42 | emu = kcalloc(1, sizeof(*emu), GFP_KERNEL);
|
---|
43 | if (emu == NULL)
|
---|
44 | return -ENOMEM;
|
---|
45 |
|
---|
46 | spin_lock_init(&emu->voice_lock);
|
---|
47 | init_MUTEX(&emu->register_mutex);
|
---|
48 |
|
---|
49 | emu->client = -1;
|
---|
50 | #ifdef CONFIG_SND_OSSEMUL
|
---|
51 | emu->oss_synth = NULL;
|
---|
52 | #endif
|
---|
53 | emu->max_voices = 0;
|
---|
54 | emu->use_time = 0;
|
---|
55 |
|
---|
56 | emu->tlist.function = snd_emux_timer_callback;
|
---|
57 | emu->tlist.data = (unsigned long)emu;
|
---|
58 | emu->timer_active = 0;
|
---|
59 |
|
---|
60 | *remu = emu;
|
---|
61 | return 0;
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | /*
|
---|
66 | */
|
---|
67 | int snd_emux_register(snd_emux_t *emu, snd_card_t *card, int index, char *name)
|
---|
68 | {
|
---|
69 | snd_sf_callback_t sf_cb;
|
---|
70 |
|
---|
71 | snd_assert(emu->hw != NULL, return -EINVAL);
|
---|
72 | snd_assert(emu->max_voices > 0, return -EINVAL);
|
---|
73 | snd_assert(card != NULL, return -EINVAL);
|
---|
74 | snd_assert(name != NULL, return -EINVAL);
|
---|
75 |
|
---|
76 | emu->card = card;
|
---|
77 | emu->name = snd_kmalloc_strdup(name, GFP_KERNEL);
|
---|
78 | emu->voices = kcalloc(emu->max_voices, sizeof(snd_emux_voice_t), GFP_KERNEL);
|
---|
79 | if (emu->voices == NULL)
|
---|
80 | return -ENOMEM;
|
---|
81 |
|
---|
82 | /* create soundfont list */
|
---|
83 | memset(&sf_cb, 0, sizeof(sf_cb));
|
---|
84 | sf_cb.private_data = emu;
|
---|
85 | sf_cb.sample_new = (snd_sf_sample_new_t)emu->ops.sample_new;
|
---|
86 | sf_cb.sample_free = (snd_sf_sample_free_t)emu->ops.sample_free;
|
---|
87 | sf_cb.sample_reset = (snd_sf_sample_reset_t)emu->ops.sample_reset;
|
---|
88 | emu->sflist = snd_sf_new(&sf_cb, emu->memhdr);
|
---|
89 | if (emu->sflist == NULL)
|
---|
90 | return -ENOMEM;
|
---|
91 |
|
---|
92 | snd_emux_init_voices(emu);
|
---|
93 |
|
---|
94 | snd_emux_init_seq(emu, card, index);
|
---|
95 | #ifdef CONFIG_SND_OSSEMUL
|
---|
96 | snd_emux_init_seq_oss(emu);
|
---|
97 | #endif
|
---|
98 | snd_emux_init_virmidi(emu, card);
|
---|
99 |
|
---|
100 | #ifdef CONFIG_PROC_FS
|
---|
101 | snd_emux_proc_init(emu, card, index);
|
---|
102 | #endif
|
---|
103 | return 0;
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | /*
|
---|
108 | */
|
---|
109 | int snd_emux_free(snd_emux_t *emu)
|
---|
110 | {
|
---|
111 | unsigned long flags;
|
---|
112 |
|
---|
113 | if (! emu)
|
---|
114 | return -EINVAL;
|
---|
115 |
|
---|
116 | spin_lock_irqsave(&emu->voice_lock, flags);
|
---|
117 | if (emu->timer_active)
|
---|
118 | del_timer(&emu->tlist);
|
---|
119 | spin_unlock_irqrestore(&emu->voice_lock, flags);
|
---|
120 |
|
---|
121 | #ifdef CONFIG_PROC_FS
|
---|
122 | snd_emux_proc_free(emu);
|
---|
123 | #endif
|
---|
124 | snd_emux_delete_virmidi(emu);
|
---|
125 | #ifdef CONFIG_SND_OSSEMUL
|
---|
126 | snd_emux_detach_seq_oss(emu);
|
---|
127 | #endif
|
---|
128 | snd_emux_detach_seq(emu);
|
---|
129 |
|
---|
130 | if (emu->sflist)
|
---|
131 | snd_sf_free(emu->sflist);
|
---|
132 |
|
---|
133 | if (emu->voices)
|
---|
134 | kfree(emu->voices);
|
---|
135 |
|
---|
136 | if (emu->name)
|
---|
137 | kfree(emu->name);
|
---|
138 |
|
---|
139 | kfree(emu);
|
---|
140 | return 0;
|
---|
141 | }
|
---|
142 |
|
---|
143 |
|
---|
144 | EXPORT_SYMBOL(snd_emux_new);
|
---|
145 | EXPORT_SYMBOL(snd_emux_register);
|
---|
146 | EXPORT_SYMBOL(snd_emux_free);
|
---|
147 |
|
---|
148 | EXPORT_SYMBOL(snd_emux_terminate_all);
|
---|
149 | EXPORT_SYMBOL(snd_emux_lock_voice);
|
---|
150 | EXPORT_SYMBOL(snd_emux_unlock_voice);
|
---|
151 |
|
---|
152 |
|
---|
153 | /*
|
---|
154 | * INIT part
|
---|
155 | */
|
---|
156 |
|
---|
157 | static int __init alsa_emux_init(void)
|
---|
158 | {
|
---|
159 | return 0;
|
---|
160 | }
|
---|
161 |
|
---|
162 | static void __exit alsa_emux_exit(void)
|
---|
163 | {
|
---|
164 | }
|
---|
165 |
|
---|
166 | module_init(alsa_emux_init)
|
---|
167 | module_exit(alsa_emux_exit)
|
---|