blob: 19a0cb561ffc1c4921e7ac138fc88850b41d4ba0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __SOUND_EMUX_SYNTH_H
2#define __SOUND_EMUX_SYNTH_H
3
4/*
5 * Defines for the Emu-series WaveTable chip
6 *
7 * Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
David Howellsa1ce3922012-10-02 18:01:25 +010024#include <sound/seq_kernel.h>
25#include <sound/seq_device.h>
26#include <sound/soundfont.h>
27#include <sound/seq_midi_emul.h>
David Howellsa1ce3922012-10-02 18:01:25 +010028#include <sound/seq_oss.h>
David Howellsa1ce3922012-10-02 18:01:25 +010029#include <sound/emux_legacy.h>
30#include <sound/seq_virmidi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32/*
33 * compile flags
34 */
35#define SNDRV_EMUX_USE_RAW_EFFECT
36
Takashi Iwai03da3122005-11-17 14:24:47 +010037struct snd_emux;
38struct snd_emux_port;
39struct snd_emux_voice;
40struct snd_emux_effect_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42/*
43 * operators
44 */
Takashi Iwai03da3122005-11-17 14:24:47 +010045struct snd_emux_operators {
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 struct module *owner;
Takashi Iwai03da3122005-11-17 14:24:47 +010047 struct snd_emux_voice *(*get_voice)(struct snd_emux *emu,
48 struct snd_emux_port *port);
49 int (*prepare)(struct snd_emux_voice *vp);
50 void (*trigger)(struct snd_emux_voice *vp);
51 void (*release)(struct snd_emux_voice *vp);
52 void (*update)(struct snd_emux_voice *vp, int update);
53 void (*terminate)(struct snd_emux_voice *vp);
54 void (*free_voice)(struct snd_emux_voice *vp);
55 void (*reset)(struct snd_emux *emu, int ch);
56 /* the first parameters are struct snd_emux */
57 int (*sample_new)(struct snd_emux *emu, struct snd_sf_sample *sp,
58 struct snd_util_memhdr *hdr,
59 const void __user *data, long count);
60 int (*sample_free)(struct snd_emux *emu, struct snd_sf_sample *sp,
61 struct snd_util_memhdr *hdr);
62 void (*sample_reset)(struct snd_emux *emu);
63 int (*load_fx)(struct snd_emux *emu, int type, int arg,
64 const void __user *data, long count);
65 void (*sysex)(struct snd_emux *emu, char *buf, int len, int parsed,
66 struct snd_midi_channel_set *chset);
Takashi Iwai3d774d52017-06-09 14:06:46 +020067#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
Takashi Iwai03da3122005-11-17 14:24:47 +010068 int (*oss_ioctl)(struct snd_emux *emu, int cmd, int p1, int p2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#endif
Takashi Iwai03da3122005-11-17 14:24:47 +010070};
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72
73/*
74 * constant values
75 */
76#define SNDRV_EMUX_MAX_PORTS 32 /* max # of sequencer ports */
77#define SNDRV_EMUX_MAX_VOICES 64 /* max # of voices */
78#define SNDRV_EMUX_MAX_MULTI_VOICES 16 /* max # of playable voices
79 * simultineously
80 */
81
82/*
83 * flags
84 */
85#define SNDRV_EMUX_ACCEPT_ROM (1<<0)
86
87/*
88 * emuX wavetable
89 */
90struct snd_emux {
91
Takashi Iwai03da3122005-11-17 14:24:47 +010092 struct snd_card *card; /* assigned card */
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 /* following should be initialized before registration */
95 int max_voices; /* Number of voices */
96 int mem_size; /* memory size (in byte) */
97 int num_ports; /* number of ports to be created */
98 int pitch_shift; /* pitch shift value (for Emu10k1) */
Takashi Iwai03da3122005-11-17 14:24:47 +010099 struct snd_emux_operators ops; /* operators */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 void *hw; /* hardware */
101 unsigned long flags; /* other conditions */
102 int midi_ports; /* number of virtual midi devices */
103 int midi_devidx; /* device offset of virtual midi */
104 unsigned int linear_panning: 1; /* panning is linear (sbawe = 1, emu10k1 = 0) */
105 int hwdep_idx; /* hwdep device index */
Takashi Iwai03da3122005-11-17 14:24:47 +0100106 struct snd_hwdep *hwdep; /* hwdep device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 /* private */
109 int num_voices; /* current number of voices */
Takashi Iwai03da3122005-11-17 14:24:47 +0100110 struct snd_sf_list *sflist; /* root of SoundFont list */
111 struct snd_emux_voice *voices; /* Voices (EMU 'channel') */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 int use_time; /* allocation counter */
113 spinlock_t voice_lock; /* Lock for voice access */
Ingo Molnaref9f0a42006-01-16 16:31:42 +0100114 struct mutex register_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 int client; /* For the sequencer client */
116 int ports[SNDRV_EMUX_MAX_PORTS]; /* The ports for this device */
Takashi Iwai03da3122005-11-17 14:24:47 +0100117 struct snd_emux_port *portptrs[SNDRV_EMUX_MAX_PORTS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 int used; /* use counter */
119 char *name; /* name of the device (internal) */
Takashi Iwai03da3122005-11-17 14:24:47 +0100120 struct snd_rawmidi **vmidi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 struct timer_list tlist; /* for pending note-offs */
122 int timer_active;
123
Takashi Iwai03da3122005-11-17 14:24:47 +0100124 struct snd_util_memhdr *memhdr; /* memory chunk information */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Takashi Iwai52262b42015-05-29 07:58:11 +0200126#ifdef CONFIG_SND_PROC_FS
Takashi Iwai03da3122005-11-17 14:24:47 +0100127 struct snd_info_entry *proc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#endif
129
Takashi Iwai3d774d52017-06-09 14:06:46 +0200130#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
Takashi Iwai03da3122005-11-17 14:24:47 +0100131 struct snd_seq_device *oss_synth;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#endif
133};
134
135
136/*
137 * sequencer port information
138 */
139struct snd_emux_port {
140
Takashi Iwai03da3122005-11-17 14:24:47 +0100141 struct snd_midi_channel_set chset;
142 struct snd_emux *emu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 char port_mode; /* operation mode */
145 int volume_atten; /* emuX raw attenuation */
146 unsigned long drum_flags; /* drum bitmaps */
147 int ctrls[EMUX_MD_END]; /* control parameters */
148#ifdef SNDRV_EMUX_USE_RAW_EFFECT
Takashi Iwai03da3122005-11-17 14:24:47 +0100149 struct snd_emux_effect_table *effect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#endif
Takashi Iwai3d774d52017-06-09 14:06:46 +0200151#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
Takashi Iwai03da3122005-11-17 14:24:47 +0100152 struct snd_seq_oss_arg *oss_arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#endif
154};
155
156/* port_mode */
157#define SNDRV_EMUX_PORT_MODE_MIDI 0 /* normal MIDI port */
158#define SNDRV_EMUX_PORT_MODE_OSS_SYNTH 1 /* OSS synth port */
159#define SNDRV_EMUX_PORT_MODE_OSS_MIDI 2 /* OSS multi channel synth port */
160
161/*
162 * A structure to keep track of each hardware voice
163 */
164struct snd_emux_voice {
165 int ch; /* Hardware channel number */
166
167 int state; /* status */
168#define SNDRV_EMUX_ST_OFF 0x00 /* Not playing, and inactive */
169#define SNDRV_EMUX_ST_ON 0x01 /* Note on */
170#define SNDRV_EMUX_ST_RELEASED (0x02|SNDRV_EMUX_ST_ON) /* Note released */
171#define SNDRV_EMUX_ST_SUSTAINED (0x04|SNDRV_EMUX_ST_ON) /* Note sustained */
172#define SNDRV_EMUX_ST_STANDBY (0x08|SNDRV_EMUX_ST_ON) /* Waiting to be triggered */
173#define SNDRV_EMUX_ST_PENDING (0x10|SNDRV_EMUX_ST_ON) /* Note will be released */
174#define SNDRV_EMUX_ST_LOCKED 0x100 /* Not accessible */
175
176 unsigned int time; /* An allocation time */
177 unsigned char note; /* Note currently assigned to this voice */
178 unsigned char key;
179 unsigned char velocity; /* Velocity of current note */
180
Takashi Iwai03da3122005-11-17 14:24:47 +0100181 struct snd_sf_zone *zone; /* Zone assigned to this note */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 void *block; /* sample block pointer (optional) */
Takashi Iwai03da3122005-11-17 14:24:47 +0100183 struct snd_midi_channel *chan; /* Midi channel for this note */
184 struct snd_emux_port *port; /* associated port */
185 struct snd_emux *emu; /* assigned root info */
186 void *hw; /* hardware pointer (emu8000 or emu10k1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 unsigned long ontime; /* jiffies at note triggered */
188
189 /* Emu8k/Emu10k1 registers */
Takashi Iwai03da3122005-11-17 14:24:47 +0100190 struct soundfont_voice_info reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 /* additional registers */
193 int avol; /* volume attenuation */
194 int acutoff; /* cutoff target */
195 int apitch; /* pitch offset */
196 int apan; /* pan/aux pair */
197 int aaux;
198 int ptarget; /* pitch target */
199 int vtarget; /* volume target */
200 int ftarget; /* filter target */
201
202};
203
204/*
205 * update flags (can be combined)
206 */
207#define SNDRV_EMUX_UPDATE_VOLUME (1<<0)
208#define SNDRV_EMUX_UPDATE_PITCH (1<<1)
209#define SNDRV_EMUX_UPDATE_PAN (1<<2)
210#define SNDRV_EMUX_UPDATE_FMMOD (1<<3)
211#define SNDRV_EMUX_UPDATE_TREMFREQ (1<<4)
212#define SNDRV_EMUX_UPDATE_FM2FRQ2 (1<<5)
213#define SNDRV_EMUX_UPDATE_Q (1<<6)
214
215
216#ifdef SNDRV_EMUX_USE_RAW_EFFECT
217/*
218 * effect table
219 */
220struct snd_emux_effect_table {
221 /* Emu8000 specific effects */
222 short val[EMUX_NUM_EFFECTS];
223 unsigned char flag[EMUX_NUM_EFFECTS];
224};
225#endif /* SNDRV_EMUX_USE_RAW_EFFECT */
226
227
228/*
229 * prototypes - interface to Emu10k1 and Emu8k routines
230 */
Takashi Iwai03da3122005-11-17 14:24:47 +0100231int snd_emux_new(struct snd_emux **remu);
232int snd_emux_register(struct snd_emux *emu, struct snd_card *card, int index, char *name);
233int snd_emux_free(struct snd_emux *emu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235/*
236 * exported functions
237 */
Takashi Iwai03da3122005-11-17 14:24:47 +0100238void snd_emux_terminate_all(struct snd_emux *emu);
239void snd_emux_lock_voice(struct snd_emux *emu, int voice);
240void snd_emux_unlock_voice(struct snd_emux *emu, int voice);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242#endif /* __SOUND_EMUX_SYNTH_H */