Home | History | Annotate | Download | only in sound
      1 /*
      2  *  Advanced Linux Sound Architecture
      3  *
      4  *  InterWave FFFF Instrument Format
      5  *  Copyright (c) 1994-99 by Jaroslav Kysela <perex (at) perex.cz>
      6  *
      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 #include "type_compat.h"
     28 
     29 /*
     30  *  share types (share ID 1)
     31  */
     32 
     33 #define IWFFFF_SHARE_FILE		0
     34 
     35 /*
     36  *  wave formats
     37  */
     38 
     39 #define IWFFFF_WAVE_16BIT		0x0001  /* 16-bit wave */
     40 #define IWFFFF_WAVE_UNSIGNED		0x0002  /* unsigned wave */
     41 #define IWFFFF_WAVE_INVERT		0x0002  /* same as unsigned wave */
     42 #define IWFFFF_WAVE_BACKWARD		0x0004  /* backward mode (maybe used for reverb or ping-ping loop) */
     43 #define IWFFFF_WAVE_LOOP		0x0008  /* loop mode */
     44 #define IWFFFF_WAVE_BIDIR		0x0010  /* bidirectional mode */
     45 #define IWFFFF_WAVE_ULAW		0x0020  /* uLaw compressed wave */
     46 #define IWFFFF_WAVE_RAM			0x0040  /* wave is _preloaded_ in RAM (it is used for ROM simulation) */
     47 #define IWFFFF_WAVE_ROM			0x0080  /* wave is in ROM */
     48 #define IWFFFF_WAVE_STEREO		0x0100	/* wave is stereo */
     49 
     50 /*
     51  *  Wavetable definitions
     52  */
     53 
     54 typedef struct iwffff_wave {
     55 	unsigned int share_id[4];	/* share id - zero = no sharing */
     56 	unsigned int format;		/* wave format */
     57 
     58 	struct {
     59 		unsigned int number;	/* some other ID for this wave */
     60 		unsigned int memory;	/* begin of waveform in onboard memory */
     61 		unsigned char *ptr;	/* pointer to waveform in system memory */
     62 	} address;
     63 
     64 	unsigned int size;		/* size of waveform in samples */
     65 	unsigned int start;		/* start offset in samples * 16 (lowest 4 bits - fraction) */
     66 	unsigned int loop_start;	/* bits loop start offset in samples * 16 (lowest 4 bits - fraction) */
     67 	unsigned int loop_end;		/* loop start offset in samples * 16 (lowest 4 bits - fraction) */
     68 	unsigned short loop_repeat;	/* loop repeat - 0 = forever */
     69 	unsigned int sample_ratio;	/* sample ratio (44100 * 1024 / rate) */
     70 	unsigned char attenuation;	/* 0 - 127 (no corresponding midi controller) */
     71 	unsigned char low_note;		/* lower frequency range for this waveform */
     72 	unsigned char high_note;	/* higher frequency range for this waveform */
     73 	unsigned char pad;
     74 
     75 	struct iwffff_wave *next;
     76 } iwffff_wave_t;
     77 
     78 /*
     79  *  Layer
     80  */
     81 
     82 #define IWFFFF_LFO_SHAPE_TRIANGLE	0
     83 #define IWFFFF_LFO_SHAPE_POSTRIANGLE	1
     84 
     85 typedef struct iwffff_lfo {
     86 	unsigned short freq;		/* (0-2047) 0.01Hz - 21.5Hz */
     87 	signed short depth;		/* volume +- (0-255) 0.48675dB/step */
     88 	signed short sweep;		/* 0 - 950 deciseconds */
     89 	unsigned char shape;		/* see to IWFFFF_LFO_SHAPE_XXXX */
     90 	unsigned char delay;		/* 0 - 255 deciseconds */
     91 } iwffff_lfo_t;
     92 
     93 #define IWFFFF_ENV_FLAG_RETRIGGER	0x0001	/* flag - retrigger */
     94 
     95 #define IWFFFF_ENV_MODE_ONE_SHOT	0x0001	/* mode - one shot */
     96 #define IWFFFF_ENV_MODE_SUSTAIN		0x0002	/* mode - sustain */
     97 #define IWFFFF_ENV_MODE_NO_SUSTAIN	0x0003	/* mode - no sustain */
     98 
     99 #define IWFFFF_ENV_INDEX_VELOCITY	0x0001	/* index - velocity */
    100 #define IWFFFF_ENV_INDEX_FREQUENCY	0x0002	/* index - frequency */
    101 
    102 typedef struct iwffff_env_point {
    103 	unsigned short offset;
    104 	unsigned short rate;
    105 } iwffff_env_point_t;
    106 
    107 typedef struct iwffff_env_record {
    108 	unsigned short nattack;
    109 	unsigned short nrelease;
    110 	unsigned short sustain_offset;
    111 	unsigned short sustain_rate;
    112 	unsigned short release_rate;
    113 	unsigned char hirange;
    114 	unsigned char pad;
    115 	struct iwffff_env_record *next;
    116 	/* points are stored here */
    117 	/* count of points = nattack + nrelease */
    118 } iwffff_env_record_t;
    119 
    120 typedef struct iwffff_env {
    121 	unsigned char flags;
    122   	unsigned char mode;
    123   	unsigned char index;
    124 	unsigned char pad;
    125 	struct iwffff_env_record *record;
    126 } iwffff_env_t;
    127 
    128 #define IWFFFF_LAYER_FLAG_RETRIGGER	0x0001	/* retrigger */
    129 
    130 #define IWFFFF_LAYER_VELOCITY_TIME	0x0000	/* velocity mode = time */
    131 #define IWFFFF_LAYER_VELOCITY_RATE	0x0001	/* velocity mode = rate */
    132 
    133 #define IWFFFF_LAYER_EVENT_KUP		0x0000	/* layer event - key up */
    134 #define IWFFFF_LAYER_EVENT_KDOWN	0x0001	/* layer event - key down */
    135 #define IWFFFF_LAYER_EVENT_RETRIG	0x0002	/* layer event - retrigger */
    136 #define IWFFFF_LAYER_EVENT_LEGATO	0x0003	/* layer event - legato */
    137 
    138 typedef struct iwffff_layer {
    139 	unsigned char flags;
    140 	unsigned char velocity_mode;
    141       	unsigned char layer_event;
    142 	unsigned char low_range;	/* range for layer based */
    143 	unsigned char high_range;	/* on either velocity or frequency */
    144 	unsigned char pan;		/* pan offset from CC1 (0 left - 127 right) */
    145 	unsigned char pan_freq_scale;	/* position based on frequency (0-127) */
    146 	unsigned char attenuation;	/* 0-127 (no corresponding midi controller) */
    147 	iwffff_lfo_t tremolo;		/* tremolo effect */
    148 	iwffff_lfo_t vibrato;		/* vibrato effect */
    149 	unsigned short freq_scale;	/* 0-2048, 1024 is equal to semitone scaling */
    150 	unsigned char freq_center;	/* center for keyboard frequency scaling */
    151 	unsigned char pad;
    152 	iwffff_env_t penv;		/* pitch envelope */
    153 	iwffff_env_t venv;		/* volume envelope */
    154 
    155 	iwffff_wave_t *wave;
    156 	struct iwffff_layer *next;
    157 } iwffff_layer_t;
    158 
    159 /*
    160  *  Instrument
    161  */
    162 
    163 #define IWFFFF_EXCLUDE_NONE		0x0000	/* exclusion mode - none */
    164 #define IWFFFF_EXCLUDE_SINGLE		0x0001	/* exclude single - single note from the instrument group */
    165 #define IWFFFF_EXCLUDE_MULTIPLE		0x0002	/* exclude multiple - stop only same note from this instrument */
    166 
    167 #define IWFFFF_LAYER_NONE		0x0000	/* not layered */
    168 #define IWFFFF_LAYER_ON			0x0001	/* layered */
    169 #define IWFFFF_LAYER_VELOCITY		0x0002	/* layered by velocity */
    170 #define IWFFFF_LAYER_FREQUENCY		0x0003	/* layered by frequency */
    171 
    172 #define IWFFFF_EFFECT_NONE		0
    173 #define IWFFFF_EFFECT_REVERB		1
    174 #define IWFFFF_EFFECT_CHORUS		2
    175 #define IWFFFF_EFFECT_ECHO		3
    176 
    177 typedef struct {
    178 	unsigned short exclusion;
    179 	unsigned short layer_type;
    180 	unsigned short exclusion_group;	/* 0 - none, 1-65535 */
    181 
    182 	unsigned char effect1;		/* effect 1 */
    183 	unsigned char effect1_depth;	/* 0-127 */
    184 	unsigned char effect2;		/* effect 2 */
    185 	unsigned char effect2_depth;	/* 0-127 */
    186 
    187 	iwffff_layer_t *layer;		/* first layer */
    188 } iwffff_instrument_t;
    189 
    190 /*
    191  *
    192  *    Kernel <-> user space
    193  *    Hardware (CPU) independent section
    194  *
    195  *    * = zero or more
    196  *    + = one or more
    197  *
    198  *    iwffff_xinstrument		IWFFFF_STRU_INSTR
    199  *      +iwffff_xlayer			IWFFFF_STRU_LAYER
    200  *        *iwffff_xenv_record		IWFFFF_STRU_ENV_RECT (tremolo)
    201  *        *iwffff_xenv_record		IWFFFF_STRU_EVN_RECT (vibrato)
    202  *          +iwffff_xwave		IWFFFF_STRU_WAVE
    203  *
    204  */
    205 
    206 #define IWFFFF_STRU_WAVE	__cpu_to_be32(('W'<<24)|('A'<<16)|('V'<<8)|'E')
    207 #define IWFFFF_STRU_ENV_RECP	__cpu_to_be32(('E'<<24)|('N'<<16)|('R'<<8)|'P')
    208 #define IWFFFF_STRU_ENV_RECV	__cpu_to_be32(('E'<<24)|('N'<<16)|('R'<<8)|'V')
    209 #define IWFFFF_STRU_LAYER 	__cpu_to_be32(('L'<<24)|('A'<<16)|('Y'<<8)|'R')
    210 #define IWFFFF_STRU_INSTR 	__cpu_to_be32(('I'<<24)|('N'<<16)|('S'<<8)|'T')
    211 
    212 /*
    213  *  Wavetable definitions
    214  */
    215 
    216 typedef struct iwffff_xwave {
    217 	__u32 stype;			/* structure type */
    218 
    219 	__u32 share_id[4];		/* share id - zero = no sharing */
    220 
    221 	__u32 format;			/* wave format */
    222 	__u32 offset;			/* offset to ROM (address) */
    223 
    224 	__u32 size;			/* size of waveform in samples */
    225 	__u32 start;			/* start offset in samples * 16 (lowest 4 bits - fraction) */
    226 	__u32 loop_start;		/* bits loop start offset in samples * 16 (lowest 4 bits - fraction) */
    227 	__u32 loop_end;			/* loop start offset in samples * 16 (lowest 4 bits - fraction) */
    228 	__u16 loop_repeat;		/* loop repeat - 0 = forever */
    229 	__u32 sample_ratio;		/* sample ratio (44100 * 1024 / rate) */
    230 	__u8 attenuation;		/* 0 - 127 (no corresponding midi controller) */
    231 	__u8 low_note;			/* lower frequency range for this waveform */
    232 	__u8 high_note;			/* higher frequency range for this waveform */
    233 	__u8 pad;
    234 } iwffff_xwave_t;
    235 
    236 /*
    237  *  Layer
    238  */
    239 
    240 typedef struct iwffff_xlfo {
    241 	__u16 freq;			/* (0-2047) 0.01Hz - 21.5Hz */
    242 	__s16 depth;			/* volume +- (0-255) 0.48675dB/step */
    243 	__s16 sweep;			/* 0 - 950 deciseconds */
    244 	__u8 shape;			/* see to ULTRA_IW_LFO_SHAPE_XXXX */
    245 	__u8 delay;			/* 0 - 255 deciseconds */
    246 } iwffff_xlfo_t;
    247 
    248 typedef struct iwffff_xenv_point {
    249 	__u16 offset;
    250 	__u16 rate;
    251 } iwffff_xenv_point_t;
    252 
    253 typedef struct iwffff_xenv_record {
    254 	__u32 stype;
    255 	__u16 nattack;
    256 	__u16 nrelease;
    257 	__u16 sustain_offset;
    258 	__u16 sustain_rate;
    259 	__u16 release_rate;
    260 	__u8 hirange;
    261 	__u8 pad;
    262 	/* points are stored here.. */
    263 	/* count of points = nattack + nrelease */
    264 } iwffff_xenv_record_t;
    265 
    266 typedef struct iwffff_xenv {
    267 	__u8 flags;
    268   	__u8 mode;
    269   	__u8 index;
    270 	__u8 pad;
    271 } iwffff_xenv_t;
    272 
    273 typedef struct iwffff_xlayer {
    274 	__u32 stype;
    275 	__u8 flags;
    276 	__u8 velocity_mode;
    277       	__u8 layer_event;
    278 	__u8 low_range;			/* range for layer based */
    279 	__u8 high_range;		/* on either velocity or frequency */
    280 	__u8 pan;			/* pan offset from CC1 (0 left - 127 right) */
    281 	__u8 pan_freq_scale;		/* position based on frequency (0-127) */
    282 	__u8 attenuation;		/* 0-127 (no corresponding midi controller) */
    283 	iwffff_xlfo_t tremolo;		/* tremolo effect */
    284 	iwffff_xlfo_t vibrato;		/* vibrato effect */
    285 	__u16 freq_scale;		/* 0-2048, 1024 is equal to semitone scaling */
    286 	__u8 freq_center;		/* center for keyboard frequency scaling */
    287 	__u8 pad;
    288 	iwffff_xenv_t penv;		/* pitch envelope */
    289 	iwffff_xenv_t venv;		/* volume envelope */
    290 } iwffff_xlayer_t;
    291 
    292 /*
    293  *  Instrument
    294  */
    295 
    296 typedef struct iwffff_xinstrument {
    297 	__u32 stype;
    298 
    299 	__u16 exclusion;
    300 	__u16 layer_type;
    301 	__u16 exclusion_group;		/* 0 - none, 1-65535 */
    302 
    303 	__u8 effect1;			/* effect 1 */
    304 	__u8 effect1_depth;		/* 0-127 */
    305 	__u8 effect2;			/* effect 2 */
    306 	__u8 effect2_depth;		/* 0-127 */
    307 } iwffff_xinstrument_t;
    308 
    309 /*
    310  *  ROM support
    311  *    InterWave ROMs are Little-Endian (x86)
    312  */
    313 
    314 #define IWFFFF_ROM_HDR_SIZE	512
    315 
    316 typedef struct {
    317 	__u8 iwave[8];
    318 	__u8 revision;
    319 	__u8 series_number;
    320 	__u8 series_name[16];
    321 	__u8 date[10];
    322 	__u16 vendor_revision_major;
    323 	__u16 vendor_revision_minor;
    324 	__u32 rom_size;
    325 	__u8 copyright[128];
    326 	__u8 vendor_name[64];
    327 	__u8 description[128];
    328 } iwffff_rom_header_t;
    329 
    330 /*
    331  *  Instrument info
    332  */
    333 
    334 #define IWFFFF_INFO_LFO_VIBRATO		(1<<0)
    335 #define IWFFFF_INFO_LFO_VIBRATO_SHAPE	(1<<1)
    336 #define IWFFFF_INFO_LFO_TREMOLO		(1<<2)
    337 #define IWFFFF_INFO_LFO_TREMOLO_SHAPE	(1<<3)
    338 
    339 typedef struct iwffff_info {
    340 	unsigned int format;		/* supported format bits */
    341 	unsigned int effects;		/* supported effects (1 << IWFFFF_EFFECT*) */
    342 	unsigned int lfos;		/* LFO effects */
    343 	unsigned int max8_len;		/* maximum 8-bit wave length */
    344 	unsigned int max16_len;		/* maximum 16-bit wave length */
    345 } iwffff_info_t;
    346 
    347 #ifdef __KERNEL__
    348 
    349 #include "seq_instr.h"
    350 
    351 extern char *snd_seq_iwffff_id;
    352 
    353 typedef struct {
    354 	void *private_data;
    355 	int (*info)(void *private_data, iwffff_info_t *info);
    356 	int (*put_sample)(void *private_data, iwffff_wave_t *wave,
    357 	                  char *data, long len, int atomic);
    358 	int (*get_sample)(void *private_data, iwffff_wave_t *wave,
    359 			  char *data, long len, int atomic);
    360 	int (*remove_sample)(void *private_data, iwffff_wave_t *wave,
    361 			     int atomic);
    362 	void (*notify)(void *private_data, snd_seq_kinstr_t *instr, int what);
    363 	snd_seq_kinstr_ops_t kops;
    364 } snd_iwffff_ops_t;
    365 
    366 int snd_seq_iwffff_init(snd_iwffff_ops_t *ops,
    367 			void *private_data,
    368                         snd_seq_kinstr_ops_t *next);
    369 
    370 #endif
    371 
    372 #endif /* __SOUND_AINSTR_IW_H */
    373