emux.c 4.12 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 *  Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
 *
 *  Routines for control of EMU WaveTable chip
 *
 *   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
 */

#include <linux/wait.h>
#include <linux/slab.h>
23
#include <linux/string.h>
Linus Torvalds's avatar
Linus Torvalds committed
24 25 26
#include <sound/core.h>
#include <sound/emux_synth.h>
#include <linux/init.h>
27
#include <linux/module.h>
Linus Torvalds's avatar
Linus Torvalds committed
28 29 30 31 32 33 34 35 36
#include "emux_voice.h"

MODULE_AUTHOR("Takashi Iwai");
MODULE_DESCRIPTION("Routines for control of EMU WaveTable chip");
MODULE_LICENSE("GPL");

/*
 * create a new hardware dependent device for Emu8000/Emu10k1
 */
37
int snd_emux_new(struct snd_emux **remu)
Linus Torvalds's avatar
Linus Torvalds committed
38
{
39
	struct snd_emux *emu;
Linus Torvalds's avatar
Linus Torvalds committed
40 41

	*remu = NULL;
42
	emu = kzalloc(sizeof(*emu), GFP_KERNEL);
Linus Torvalds's avatar
Linus Torvalds committed
43 44 45 46
	if (emu == NULL)
		return -ENOMEM;

	spin_lock_init(&emu->voice_lock);
47
	mutex_init(&emu->register_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
48 49

	emu->client = -1;
50
#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
Linus Torvalds's avatar
Linus Torvalds committed
51 52 53 54 55
	emu->oss_synth = NULL;
#endif
	emu->max_voices = 0;
	emu->use_time = 0;

56
	timer_setup(&emu->tlist, snd_emux_timer_callback, 0);
Linus Torvalds's avatar
Linus Torvalds committed
57 58 59 60 61 62
	emu->timer_active = 0;

	*remu = emu;
	return 0;
}

63
EXPORT_SYMBOL(snd_emux_new);
Linus Torvalds's avatar
Linus Torvalds committed
64 65 66

/*
 */
67 68 69
static int sf_sample_new(void *private_data, struct snd_sf_sample *sp,
				  struct snd_util_memhdr *hdr,
				  const void __user *buf, long count)
70
{
71
	struct snd_emux *emu = private_data;
72 73 74 75
	return emu->ops.sample_new(emu, sp, hdr, buf, count);
	
}

76 77
static int sf_sample_free(void *private_data, struct snd_sf_sample *sp,
				   struct snd_util_memhdr *hdr)
78
{
79
	struct snd_emux *emu = private_data;
80 81 82 83 84 85
	return emu->ops.sample_free(emu, sp, hdr);
	
}

static void sf_sample_reset(void *private_data)
{
86
	struct snd_emux *emu = private_data;
87 88 89
	emu->ops.sample_reset(emu);
}

90
int snd_emux_register(struct snd_emux *emu, struct snd_card *card, int index, char *name)
Linus Torvalds's avatar
Linus Torvalds committed
91 92
{
	int err;
93
	struct snd_sf_callback sf_cb;
Linus Torvalds's avatar
Linus Torvalds committed
94

95 96 97 98
	if (snd_BUG_ON(!emu->hw || emu->max_voices <= 0))
		return -EINVAL;
	if (snd_BUG_ON(!card || !name))
		return -EINVAL;
Linus Torvalds's avatar
Linus Torvalds committed
99 100

	emu->card = card;
101
	emu->name = kstrdup(name, GFP_KERNEL);
102 103
	emu->voices = kcalloc(emu->max_voices, sizeof(struct snd_emux_voice),
			      GFP_KERNEL);
Linus Torvalds's avatar
Linus Torvalds committed
104 105 106 107 108 109
	if (emu->voices == NULL)
		return -ENOMEM;

	/* create soundfont list */
	memset(&sf_cb, 0, sizeof(sf_cb));
	sf_cb.private_data = emu;
110 111 112 113 114 115
	if (emu->ops.sample_new)
		sf_cb.sample_new = sf_sample_new;
	if (emu->ops.sample_free)
		sf_cb.sample_free = sf_sample_free;
	if (emu->ops.sample_reset)
		sf_cb.sample_reset = sf_sample_reset;
Linus Torvalds's avatar
Linus Torvalds committed
116 117 118 119 120 121 122 123 124 125
	emu->sflist = snd_sf_new(&sf_cb, emu->memhdr);
	if (emu->sflist == NULL)
		return -ENOMEM;

	if ((err = snd_emux_init_hwdep(emu)) < 0)
		return err;

	snd_emux_init_voices(emu);

	snd_emux_init_seq(emu, card, index);
126
#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
Linus Torvalds's avatar
Linus Torvalds committed
127 128 129 130 131 132 133 134
	snd_emux_init_seq_oss(emu);
#endif
	snd_emux_init_virmidi(emu, card);

	snd_emux_proc_init(emu, card, index);
	return 0;
}

135
EXPORT_SYMBOL(snd_emux_register);
Linus Torvalds's avatar
Linus Torvalds committed
136 137 138

/*
 */
139
int snd_emux_free(struct snd_emux *emu)
Linus Torvalds's avatar
Linus Torvalds committed
140 141 142 143 144 145 146 147 148 149 150 151 152
{
	unsigned long flags;

	if (! emu)
		return -EINVAL;

	spin_lock_irqsave(&emu->voice_lock, flags);
	if (emu->timer_active)
		del_timer(&emu->tlist);
	spin_unlock_irqrestore(&emu->voice_lock, flags);

	snd_emux_proc_free(emu);
	snd_emux_delete_virmidi(emu);
153
#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
Linus Torvalds's avatar
Linus Torvalds committed
154 155 156 157
	snd_emux_detach_seq_oss(emu);
#endif
	snd_emux_detach_seq(emu);
	snd_emux_delete_hwdep(emu);
158
	snd_sf_free(emu->sflist);
Linus Torvalds's avatar
Linus Torvalds committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
	kfree(emu->voices);
	kfree(emu->name);
	kfree(emu);
	return 0;
}

EXPORT_SYMBOL(snd_emux_free);


/*
 *  INIT part
 */

static int __init alsa_emux_init(void)
{
	return 0;
}

static void __exit alsa_emux_exit(void)
{
}

module_init(alsa_emux_init)
module_exit(alsa_emux_exit)