blob: 11bd250826006213b33e23fbaadeda035587618c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Advanced Linux Sound Architecture
3 *
4 * InterWave FFFF Instrument Format
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02005 * Copyright (c) 1994-99 by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#ifndef __SOUND_AINSTR_IW_H
25#define __SOUND_AINSTR_IW_H
26
27#ifndef __KERNEL__
28#include <asm/types.h>
29#include <asm/byteorder.h>
30#endif
31
32/*
33 * share types (share ID 1)
34 */
35
36#define IWFFFF_SHARE_FILE 0
37
38/*
39 * wave formats
40 */
41
42#define IWFFFF_WAVE_16BIT 0x0001 /* 16-bit wave */
43#define IWFFFF_WAVE_UNSIGNED 0x0002 /* unsigned wave */
44#define IWFFFF_WAVE_INVERT 0x0002 /* same as unsigned wave */
45#define IWFFFF_WAVE_BACKWARD 0x0004 /* backward mode (maybe used for reverb or ping-ping loop) */
46#define IWFFFF_WAVE_LOOP 0x0008 /* loop mode */
47#define IWFFFF_WAVE_BIDIR 0x0010 /* bidirectional mode */
48#define IWFFFF_WAVE_ULAW 0x0020 /* uLaw compressed wave */
49#define IWFFFF_WAVE_RAM 0x0040 /* wave is _preloaded_ in RAM (it is used for ROM simulation) */
50#define IWFFFF_WAVE_ROM 0x0080 /* wave is in ROM */
51#define IWFFFF_WAVE_STEREO 0x0100 /* wave is stereo */
52
53/*
54 * Wavetable definitions
55 */
56
Takashi Iwai19ac31e2005-11-17 14:04:44 +010057struct iwffff_wave {
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 unsigned int share_id[4]; /* share id - zero = no sharing */
59 unsigned int format; /* wave format */
60
61 struct {
62 unsigned int number; /* some other ID for this wave */
63 unsigned int memory; /* begin of waveform in onboard memory */
64 unsigned char *ptr; /* pointer to waveform in system memory */
65 } address;
66
67 unsigned int size; /* size of waveform in samples */
68 unsigned int start; /* start offset in samples * 16 (lowest 4 bits - fraction) */
69 unsigned int loop_start; /* bits loop start offset in samples * 16 (lowest 4 bits - fraction) */
70 unsigned int loop_end; /* loop start offset in samples * 16 (lowest 4 bits - fraction) */
71 unsigned short loop_repeat; /* loop repeat - 0 = forever */
72 unsigned int sample_ratio; /* sample ratio (44100 * 1024 / rate) */
73 unsigned char attenuation; /* 0 - 127 (no corresponding midi controller) */
74 unsigned char low_note; /* lower frequency range for this waveform */
75 unsigned char high_note; /* higher frequency range for this waveform */
76 unsigned char pad;
77
78 struct iwffff_wave *next;
Takashi Iwai19ac31e2005-11-17 14:04:44 +010079};
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81/*
82 * Layer
83 */
84
85#define IWFFFF_LFO_SHAPE_TRIANGLE 0
86#define IWFFFF_LFO_SHAPE_POSTRIANGLE 1
87
Takashi Iwai19ac31e2005-11-17 14:04:44 +010088struct iwffff_lfo {
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 unsigned short freq; /* (0-2047) 0.01Hz - 21.5Hz */
90 signed short depth; /* volume +- (0-255) 0.48675dB/step */
91 signed short sweep; /* 0 - 950 deciseconds */
92 unsigned char shape; /* see to IWFFFF_LFO_SHAPE_XXXX */
93 unsigned char delay; /* 0 - 255 deciseconds */
Takashi Iwai19ac31e2005-11-17 14:04:44 +010094};
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96#define IWFFFF_ENV_FLAG_RETRIGGER 0x0001 /* flag - retrigger */
97
98#define IWFFFF_ENV_MODE_ONE_SHOT 0x0001 /* mode - one shot */
99#define IWFFFF_ENV_MODE_SUSTAIN 0x0002 /* mode - sustain */
100#define IWFFFF_ENV_MODE_NO_SUSTAIN 0x0003 /* mode - no sustain */
101
102#define IWFFFF_ENV_INDEX_VELOCITY 0x0001 /* index - velocity */
103#define IWFFFF_ENV_INDEX_FREQUENCY 0x0002 /* index - frequency */
104
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100105struct iwffff_env_point {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 unsigned short offset;
107 unsigned short rate;
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100108};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100110struct iwffff_env_record {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 unsigned short nattack;
112 unsigned short nrelease;
113 unsigned short sustain_offset;
114 unsigned short sustain_rate;
115 unsigned short release_rate;
116 unsigned char hirange;
117 unsigned char pad;
118 struct iwffff_env_record *next;
119 /* points are stored here */
120 /* count of points = nattack + nrelease */
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100121};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100123struct iwffff_env {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 unsigned char flags;
125 unsigned char mode;
126 unsigned char index;
127 unsigned char pad;
128 struct iwffff_env_record *record;
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100129};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131#define IWFFFF_LAYER_FLAG_RETRIGGER 0x0001 /* retrigger */
132
133#define IWFFFF_LAYER_VELOCITY_TIME 0x0000 /* velocity mode = time */
134#define IWFFFF_LAYER_VELOCITY_RATE 0x0001 /* velocity mode = rate */
135
136#define IWFFFF_LAYER_EVENT_KUP 0x0000 /* layer event - key up */
137#define IWFFFF_LAYER_EVENT_KDOWN 0x0001 /* layer event - key down */
138#define IWFFFF_LAYER_EVENT_RETRIG 0x0002 /* layer event - retrigger */
139#define IWFFFF_LAYER_EVENT_LEGATO 0x0003 /* layer event - legato */
140
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100141struct iwffff_layer {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 unsigned char flags;
143 unsigned char velocity_mode;
144 unsigned char layer_event;
145 unsigned char low_range; /* range for layer based */
146 unsigned char high_range; /* on either velocity or frequency */
147 unsigned char pan; /* pan offset from CC1 (0 left - 127 right) */
148 unsigned char pan_freq_scale; /* position based on frequency (0-127) */
149 unsigned char attenuation; /* 0-127 (no corresponding midi controller) */
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100150 struct iwffff_lfo tremolo; /* tremolo effect */
151 struct iwffff_lfo vibrato; /* vibrato effect */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 unsigned short freq_scale; /* 0-2048, 1024 is equal to semitone scaling */
153 unsigned char freq_center; /* center for keyboard frequency scaling */
154 unsigned char pad;
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100155 struct iwffff_env penv; /* pitch envelope */
156 struct iwffff_env venv; /* volume envelope */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100158 struct iwffff_wave *wave;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 struct iwffff_layer *next;
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100160};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162/*
163 * Instrument
164 */
165
166#define IWFFFF_EXCLUDE_NONE 0x0000 /* exclusion mode - none */
167#define IWFFFF_EXCLUDE_SINGLE 0x0001 /* exclude single - single note from the instrument group */
168#define IWFFFF_EXCLUDE_MULTIPLE 0x0002 /* exclude multiple - stop only same note from this instrument */
169
170#define IWFFFF_LAYER_NONE 0x0000 /* not layered */
171#define IWFFFF_LAYER_ON 0x0001 /* layered */
172#define IWFFFF_LAYER_VELOCITY 0x0002 /* layered by velocity */
173#define IWFFFF_LAYER_FREQUENCY 0x0003 /* layered by frequency */
174
175#define IWFFFF_EFFECT_NONE 0
176#define IWFFFF_EFFECT_REVERB 1
177#define IWFFFF_EFFECT_CHORUS 2
178#define IWFFFF_EFFECT_ECHO 3
179
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100180struct iwffff_instrument {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 unsigned short exclusion;
182 unsigned short layer_type;
183 unsigned short exclusion_group; /* 0 - none, 1-65535 */
184
185 unsigned char effect1; /* effect 1 */
186 unsigned char effect1_depth; /* 0-127 */
187 unsigned char effect2; /* effect 2 */
188 unsigned char effect2_depth; /* 0-127 */
189
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100190 struct iwffff_layer *layer; /* first layer */
191};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193/*
194 *
195 * Kernel <-> user space
196 * Hardware (CPU) independent section
197 *
198 * * = zero or more
199 * + = one or more
200 *
201 * iwffff_xinstrument IWFFFF_STRU_INSTR
202 * +iwffff_xlayer IWFFFF_STRU_LAYER
203 * *iwffff_xenv_record IWFFFF_STRU_ENV_RECT (tremolo)
204 * *iwffff_xenv_record IWFFFF_STRU_EVN_RECT (vibrato)
205 * +iwffff_xwave IWFFFF_STRU_WAVE
206 *
207 */
208
209#define IWFFFF_STRU_WAVE __cpu_to_be32(('W'<<24)|('A'<<16)|('V'<<8)|'E')
210#define IWFFFF_STRU_ENV_RECP __cpu_to_be32(('E'<<24)|('N'<<16)|('R'<<8)|'P')
211#define IWFFFF_STRU_ENV_RECV __cpu_to_be32(('E'<<24)|('N'<<16)|('R'<<8)|'V')
212#define IWFFFF_STRU_LAYER __cpu_to_be32(('L'<<24)|('A'<<16)|('Y'<<8)|'R')
213#define IWFFFF_STRU_INSTR __cpu_to_be32(('I'<<24)|('N'<<16)|('S'<<8)|'T')
214
215/*
216 * Wavetable definitions
217 */
218
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100219struct iwffff_xwave {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 __u32 stype; /* structure type */
221
222 __u32 share_id[4]; /* share id - zero = no sharing */
223
224 __u32 format; /* wave format */
225 __u32 offset; /* offset to ROM (address) */
226
227 __u32 size; /* size of waveform in samples */
228 __u32 start; /* start offset in samples * 16 (lowest 4 bits - fraction) */
229 __u32 loop_start; /* bits loop start offset in samples * 16 (lowest 4 bits - fraction) */
230 __u32 loop_end; /* loop start offset in samples * 16 (lowest 4 bits - fraction) */
231 __u16 loop_repeat; /* loop repeat - 0 = forever */
232 __u32 sample_ratio; /* sample ratio (44100 * 1024 / rate) */
233 __u8 attenuation; /* 0 - 127 (no corresponding midi controller) */
234 __u8 low_note; /* lower frequency range for this waveform */
235 __u8 high_note; /* higher frequency range for this waveform */
236 __u8 pad;
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100237};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239/*
240 * Layer
241 */
242
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100243struct iwffff_xlfo {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 __u16 freq; /* (0-2047) 0.01Hz - 21.5Hz */
245 __s16 depth; /* volume +- (0-255) 0.48675dB/step */
246 __s16 sweep; /* 0 - 950 deciseconds */
247 __u8 shape; /* see to ULTRA_IW_LFO_SHAPE_XXXX */
248 __u8 delay; /* 0 - 255 deciseconds */
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100249};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100251struct iwffff_xenv_point {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 __u16 offset;
253 __u16 rate;
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100254};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100256struct iwffff_xenv_record {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 __u32 stype;
258 __u16 nattack;
259 __u16 nrelease;
260 __u16 sustain_offset;
261 __u16 sustain_rate;
262 __u16 release_rate;
263 __u8 hirange;
264 __u8 pad;
265 /* points are stored here.. */
266 /* count of points = nattack + nrelease */
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100267};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100269struct iwffff_xenv {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 __u8 flags;
271 __u8 mode;
272 __u8 index;
273 __u8 pad;
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100274};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100276struct iwffff_xlayer {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 __u32 stype;
278 __u8 flags;
279 __u8 velocity_mode;
280 __u8 layer_event;
281 __u8 low_range; /* range for layer based */
282 __u8 high_range; /* on either velocity or frequency */
283 __u8 pan; /* pan offset from CC1 (0 left - 127 right) */
284 __u8 pan_freq_scale; /* position based on frequency (0-127) */
285 __u8 attenuation; /* 0-127 (no corresponding midi controller) */
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100286 struct iwffff_xlfo tremolo; /* tremolo effect */
287 struct iwffff_xlfo vibrato; /* vibrato effect */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 __u16 freq_scale; /* 0-2048, 1024 is equal to semitone scaling */
289 __u8 freq_center; /* center for keyboard frequency scaling */
290 __u8 pad;
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100291 struct iwffff_xenv penv; /* pitch envelope */
292 struct iwffff_xenv venv; /* volume envelope */
293};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295/*
296 * Instrument
297 */
298
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100299struct iwffff_xinstrument {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 __u32 stype;
301
302 __u16 exclusion;
303 __u16 layer_type;
304 __u16 exclusion_group; /* 0 - none, 1-65535 */
305
306 __u8 effect1; /* effect 1 */
307 __u8 effect1_depth; /* 0-127 */
308 __u8 effect2; /* effect 2 */
309 __u8 effect2_depth; /* 0-127 */
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100310};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312/*
313 * ROM support
314 * InterWave ROMs are Little-Endian (x86)
315 */
316
317#define IWFFFF_ROM_HDR_SIZE 512
318
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100319struct iwffff_rom_header {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 __u8 iwave[8];
321 __u8 revision;
322 __u8 series_number;
323 __u8 series_name[16];
324 __u8 date[10];
325 __u16 vendor_revision_major;
326 __u16 vendor_revision_minor;
327 __u32 rom_size;
328 __u8 copyright[128];
329 __u8 vendor_name[64];
330 __u8 description[128];
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100331};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333/*
334 * Instrument info
335 */
336
337#define IWFFFF_INFO_LFO_VIBRATO (1<<0)
338#define IWFFFF_INFO_LFO_VIBRATO_SHAPE (1<<1)
339#define IWFFFF_INFO_LFO_TREMOLO (1<<2)
340#define IWFFFF_INFO_LFO_TREMOLO_SHAPE (1<<3)
341
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100342struct iwffff_info {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 unsigned int format; /* supported format bits */
344 unsigned int effects; /* supported effects (1 << IWFFFF_EFFECT*) */
345 unsigned int lfos; /* LFO effects */
346 unsigned int max8_len; /* maximum 8-bit wave length */
347 unsigned int max16_len; /* maximum 16-bit wave length */
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100348};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
350#ifdef __KERNEL__
351
352#include "seq_instr.h"
353
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100354struct snd_iwffff_ops {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 void *private_data;
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100356 int (*info)(void *private_data, struct iwffff_info *info);
357 int (*put_sample)(void *private_data, struct iwffff_wave *wave,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 char __user *data, long len, int atomic);
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100359 int (*get_sample)(void *private_data, struct iwffff_wave *wave,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 char __user *data, long len, int atomic);
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100361 int (*remove_sample)(void *private_data, struct iwffff_wave *wave,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 int atomic);
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100363 void (*notify)(void *private_data, struct snd_seq_kinstr *instr, int what);
364 struct snd_seq_kinstr_ops kops;
365};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100367int snd_seq_iwffff_init(struct snd_iwffff_ops *ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 void *private_data,
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100369 struct snd_seq_kinstr_ops *next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371#endif
372
Takashi Iwai19ac31e2005-11-17 14:04:44 +0100373/* typedefs for compatibility to user-space */
374typedef struct iwffff_xwave iwffff_xwave_t;
375typedef struct iwffff_xlfo iwffff_xlfo_t;
376typedef struct iwffff_xenv_point iwffff_xenv_point_t;
377typedef struct iwffff_xenv_record iwffff_xenv_record_t;
378typedef struct iwffff_xenv iwffff_xenv_t;
379typedef struct iwffff_xlayer iwffff_xlayer_t;
380typedef struct iwffff_xinstrument iwffff_xinstrument_t;
381typedef struct iwffff_rom_header iwffff_rom_header_t;
382typedef struct iwffff_info iwffff_info_t;
383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384#endif /* __SOUND_AINSTR_IW_H */