Linux Audio

Check our new training course

Loading...
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2#ifndef __SOUND_WAVEFRONT_H__
  3#define __SOUND_WAVEFRONT_H__
  4
  5/*
  6 *  Driver for Turtle Beach Wavefront cards (Maui,Tropez,Tropez+)
  7 *
  8 *  Copyright (c) by Paul Barton-Davis <pbd@op.net>
  9 */
 10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 11#ifndef NUM_MIDIKEYS 
 12#define NUM_MIDIKEYS 128
 13#endif  /* NUM_MIDIKEYS */
 14
 15#ifndef NUM_MIDICHANNELS
 16#define NUM_MIDICHANNELS 16
 17#endif  /* NUM_MIDICHANNELS */
 18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 19/* Pseudo-commands not part of the WaveFront command set.
 20   These are used for various driver controls and direct
 21   hardware control.
 22 */
 23
 24#define WFC_DEBUG_DRIVER                0
 25#define WFC_FX_IOCTL                    1
 26#define WFC_PATCH_STATUS                2
 27#define WFC_PROGRAM_STATUS              3
 28#define WFC_SAMPLE_STATUS               4
 29#define WFC_DISABLE_INTERRUPTS          5
 30#define WFC_ENABLE_INTERRUPTS           6
 31#define WFC_INTERRUPT_STATUS            7
 32#define WFC_ROMSAMPLES_RDONLY           8
 33#define WFC_IDENTIFY_SLOT_TYPE          9
 34
 35/* Wavefront synth commands
 36 */
 37
 38#define WFC_DOWNLOAD_SAMPLE		0x80
 39#define WFC_DOWNLOAD_BLOCK		0x81
 40#define WFC_DOWNLOAD_MULTISAMPLE	0x82
 41#define WFC_DOWNLOAD_SAMPLE_ALIAS	0x83
 42#define WFC_DELETE_SAMPLE		0x84
 43#define WFC_REPORT_FREE_MEMORY		0x85
 44#define WFC_DOWNLOAD_PATCH		0x86
 45#define WFC_DOWNLOAD_PROGRAM		0x87
 46#define WFC_SET_SYNTHVOL		0x89
 47#define WFC_SET_NVOICES			0x8B
 48#define WFC_DOWNLOAD_DRUM		0x90
 49#define WFC_GET_SYNTHVOL		0x92
 50#define WFC_GET_NVOICES			0x94
 51#define WFC_DISABLE_CHANNEL		0x9A
 52#define WFC_ENABLE_CHANNEL		0x9B
 53#define WFC_MISYNTH_OFF			0x9D
 54#define WFC_MISYNTH_ON			0x9E
 55#define WFC_FIRMWARE_VERSION		0x9F
 56#define WFC_GET_NSAMPLES		0xA0
 57#define WFC_DISABLE_DRUM_PROGRAM	0xA2
 58#define WFC_UPLOAD_PATCH		0xA3
 59#define WFC_UPLOAD_PROGRAM		0xA4
 60#define WFC_SET_TUNING			0xA6
 61#define WFC_GET_TUNING			0xA7
 62#define WFC_VMIDI_ON			0xA8
 63#define WFC_VMIDI_OFF			0xA9
 64#define WFC_MIDI_STATUS			0xAA
 65#define WFC_GET_CHANNEL_STATUS		0xAB
 66#define WFC_DOWNLOAD_SAMPLE_HEADER	0xAC
 67#define WFC_UPLOAD_SAMPLE_HEADER	0xAD
 68#define WFC_UPLOAD_MULTISAMPLE		0xAE
 69#define WFC_UPLOAD_SAMPLE_ALIAS		0xAF
 70#define WFC_IDENTIFY_SAMPLE_TYPE	0xB0
 71#define WFC_DOWNLOAD_EDRUM_PROGRAM	0xB1
 72#define WFC_UPLOAD_EDRUM_PROGRAM	0xB2
 73#define WFC_SET_EDRUM_CHANNEL		0xB3
 74#define WFC_INSTOUT_LEVELS		0xB4
 75#define WFC_PEAKOUT_LEVELS		0xB5
 76#define WFC_REPORT_CHANNEL_PROGRAMS	0xB6
 77#define WFC_HARDWARE_VERSION		0xCF
 78#define WFC_UPLOAD_SAMPLE_PARAMS	0xD7
 79#define WFC_DOWNLOAD_OS			0xF1
 80#define WFC_NOOP                        0xFF
 81
 82#define WF_MAX_SAMPLE   512
 83#define WF_MAX_PATCH    256
 84#define WF_MAX_PROGRAM  128
 85
 86#define WF_SECTION_MAX  44   /* longest OS section length */
 87
 88/* # of bytes we send to the board when sending it various kinds of
 89   substantive data, such as samples, patches and programs.
 90*/
 91
 92#define WF_PROGRAM_BYTES 32
 93#define WF_PATCH_BYTES 132
 94#define WF_SAMPLE_BYTES 27
 95#define WF_SAMPLE_HDR_BYTES 25
 96#define WF_ALIAS_BYTES 25
 97#define WF_DRUM_BYTES 9
 98#define WF_MSAMPLE_BYTES 259 /* (MIDI_KEYS * 2) + 3 */
 99
100#define WF_ACK     0x80
101#define WF_DMA_ACK 0x81
102
103/* OR-values for MIDI status bits */
104
105#define WF_MIDI_VIRTUAL_ENABLED 0x1
106#define WF_MIDI_VIRTUAL_IS_EXTERNAL 0x2
107#define WF_MIDI_IN_TO_SYNTH_DISABLED 0x4
108
109/* slot indexes for struct address_info: makes code a little more mnemonic */
110
111#define WF_SYNTH_SLOT         0
112#define WF_INTERNAL_MIDI_SLOT 1
113#define WF_EXTERNAL_MIDI_SLOT 2
114
115/* Magic MIDI bytes used to switch I/O streams on the ICS2115 MPU401
116   emulation. Note these NEVER show up in output from the device and
117   should NEVER be used in input unless Virtual MIDI mode has been 
118   disabled. If they do show up as input, the results are unpredictable.
119*/
120
121#define WF_EXTERNAL_SWITCH  0xFD
122#define WF_INTERNAL_SWITCH  0xF9
123
124/* Debugging flags */
125
126#define WF_DEBUG_CMD 0x1
127#define WF_DEBUG_DATA 0x2
128#define WF_DEBUG_LOAD_PATCH 0x4
129#define WF_DEBUG_IO 0x8
130
131/* WavePatch file format stuff */
132
133#define WF_WAVEPATCH_VERSION     120;  /*  Current version number (1.2)  */
134#define WF_MAX_COMMENT           64    /*  Comment length */
135#define WF_NUM_LAYERS            4
136#define WF_NAME_LENGTH           32
137#define WF_SOURCE_LENGTH         260
138
139#define BankFileID     "Bank"
140#define DrumkitFileID  "DrumKit"
141#define ProgramFileID  "Program"
142
143struct wf_envelope
144{
145    u8 attack_time:7;
146    u8 Unused1:1;
147
148    u8 decay1_time:7;
149    u8 Unused2:1;
150
151    u8 decay2_time:7;
152    u8 Unused3:1;
153
154    u8 sustain_time:7;
155    u8 Unused4:1;
156
157    u8 release_time:7;
158    u8 Unused5:1;
159
160    u8 release2_time:7;
161    u8 Unused6:1;
162
163    s8 attack_level;
164    s8 decay1_level;
165    s8 decay2_level;
166    s8 sustain_level;
167    s8 release_level;
168
169    u8 attack_velocity:7;
170    u8 Unused7:1;
171
172    u8 volume_velocity:7;
173    u8 Unused8:1;
174
175    u8 keyboard_scaling:7;
176    u8 Unused9:1;
177};
178typedef struct wf_envelope wavefront_envelope;
179
180struct wf_lfo
181{
182    u8 sample_number;
183
184    u8 frequency:7;
185    u8 Unused1:1;
186
187    u8 am_src:4;
188    u8 fm_src:4;
189
190    s8 fm_amount;
191    s8 am_amount;
192    s8 start_level;
193    s8 end_level;
194
195    u8 ramp_delay:7;
196    u8 wave_restart:1; /* for LFO2 only */
197
198    u8 ramp_time:7;
199    u8 Unused2:1;
200};
201typedef struct wf_lfo wavefront_lfo;
202
203struct wf_patch
204{
205    s16  frequency_bias;         /*  ** THIS IS IN MOTOROLA FORMAT!! ** */
206
207    u8 amplitude_bias:7;
208    u8 Unused1:1;
209
210    u8 portamento:7;
211    u8 Unused2:1;
212
213    u8 sample_number;
214
215    u8 pitch_bend:4;
216    u8 sample_msb:1;
217    u8 Unused3:3;
218
219    u8 mono:1;
220    u8 retrigger:1;
221    u8 nohold:1;
222    u8 restart:1;
223    u8 filterconfig:2; /* SDK says "not used" */
224    u8 reuse:1;
225    u8 reset_lfo:1;    
226
227    u8 fm_src2:4;
228    u8 fm_src1:4;   
229
230    s8 fm_amount1;
231    s8 fm_amount2;
232
233    u8 am_src:4;
234    u8 Unused4:4;
235
236    s8 am_amount;
237
238    u8 fc1_mode:4;
239    u8 fc2_mode:4;
240
241    s8 fc1_mod_amount;
242    s8 fc1_keyboard_scaling;
243    s8 fc1_bias;
244    s8 fc2_mod_amount;
245    s8 fc2_keyboard_scaling;
246    s8 fc2_bias;
247
248    u8 randomizer:7;
249    u8 Unused5:1;
250
251    struct wf_envelope envelope1;
252    struct wf_envelope envelope2;
253    struct wf_lfo lfo1;
254    struct wf_lfo lfo2;
255};
256typedef struct wf_patch wavefront_patch;
257
258struct wf_layer
259{
260    u8 patch_number;
261
262    u8 mix_level:7;
263    u8 mute:1;
264
265    u8 split_point:7;
266    u8 play_below:1;
267
268    u8 pan_mod_src:2;
269    u8 pan_or_mod:1;
270    u8 pan:4;
271    u8 split_type:1;
272};
273typedef struct wf_layer wavefront_layer;
274
275struct wf_program
276{
277    struct wf_layer layer[WF_NUM_LAYERS];
278};
279typedef struct wf_program wavefront_program;
280
281struct wf_sample_offset
282{
283    s32 Fraction:4;
284    s32 Integer:20;
285    s32 Unused:8;
286};
287typedef struct wf_sample_offset wavefront_sample_offset;          
288     
289/* Sample slot types */
290
291#define WF_ST_SAMPLE      0
292#define WF_ST_MULTISAMPLE 1
293#define WF_ST_ALIAS       2
294#define WF_ST_EMPTY       3
295
296/* pseudo's */
297
298#define WF_ST_DRUM        4
299#define WF_ST_PROGRAM     5
300#define WF_ST_PATCH       6
301#define WF_ST_SAMPLEHDR   7
302
303#define WF_ST_MASK        0xf
304
305/* Flags for slot status. These occupy the upper bits of the same byte
306   as a sample type.
307*/
308
309#define WF_SLOT_USED      0x80   /* XXX don't rely on this being accurate */
310#define WF_SLOT_FILLED    0x40
311#define WF_SLOT_ROM       0x20
312
313#define WF_SLOT_MASK      0xf0
314
315/* channel constants */
316
317#define WF_CH_MONO  0
318#define WF_CH_LEFT  1
319#define WF_CH_RIGHT 2
320
321/* Sample formats */
322
323#define LINEAR_16BIT 0
324#define WHITE_NOISE  1
325#define LINEAR_8BIT  2
326#define MULAW_8BIT   3
327
328#define WF_SAMPLE_IS_8BIT(smpl) ((smpl)->SampleResolution&2)
329
330
331/* 
332
333  Because most/all of the sample data we pass in via pointers has
334  never been copied (just mmap-ed into user space straight from the
335  disk), it would be nice to allow handling of multi-channel sample
336  data without forcing user-level extraction of the relevant bytes.
337  
338  So, we need a way of specifying which channel to use (the WaveFront
339  only handles mono samples in a given slot), and the only way to do
340  this without using some struct other than wavefront_sample as the
341  interface is the awful hack of using the unused bits in a
342  wavefront_sample:
343  
344  Val      Meaning
345  ---      -------
346  0        no channel selection (use channel 1, sample is MONO)
347  1        use first channel, and skip one
348  2        use second channel, and skip one
349  3        use third channel, and skip two
350  4        use fourth channel, skip three
351  5        use fifth channel, skip four
352  6        use six channel, skip five
353
354
355  This can handle up to 4 channels, and anyone downloading >4 channels
356  of sample data just to select one of them needs to find some tools
357  like sox ...
358
359  NOTE: values 0, 1 and 2 correspond to WF_CH_* above. This is 
360  important.
361
362*/
363
364#define WF_SET_CHANNEL(samp,chn) \
365 (samp)->Unused1 = chn & 0x1; \
366 (samp)->Unused2 = chn & 0x2; \
367 (samp)->Unused3 = chn & 0x4 
368  
369#define WF_GET_CHANNEL(samp) \
370  (((samp)->Unused3 << 2)|((samp)->Unused2<<1)|(samp)->Unused1)
371  
372typedef struct wf_sample {
373    struct wf_sample_offset sampleStartOffset;
374    struct wf_sample_offset loopStartOffset;
375    struct wf_sample_offset loopEndOffset;
376    struct wf_sample_offset sampleEndOffset;
377    s16 FrequencyBias;
378    u8 SampleResolution:2;  /* sample_format */
379    u8 Unused1:1;
380    u8 Loop:1;
381    u8 Bidirectional:1;
382    u8 Unused2:1;
383    u8 Reverse:1;
384    u8 Unused3:1;
385} wavefront_sample;
386
387typedef struct wf_multisample {
388    s16 NumberOfSamples;   /* log2 of the number of samples */
389    s16 SampleNumber[NUM_MIDIKEYS];
390} wavefront_multisample;
391
392typedef struct wf_alias {
393    s16 OriginalSample;
394
395    struct wf_sample_offset sampleStartOffset;
396    struct wf_sample_offset loopStartOffset;
397    struct wf_sample_offset sampleEndOffset;
398    struct wf_sample_offset loopEndOffset;
399
400    s16  FrequencyBias;
401
402    u8 SampleResolution:2;
403    u8 Unused1:1;
404    u8 Loop:1;
405    u8 Bidirectional:1;
406    u8 Unused2:1;
407    u8 Reverse:1;
408    u8 Unused3:1;
409    
410    /* This structure is meant to be padded only to 16 bits on their
411       original. Of course, whoever wrote their documentation didn't
412       realize that sizeof(struct) can be >=
413       sum(sizeof(struct-fields)) and so thought that giving a C level
414       description of the structs used in WavePatch files was
415       sufficient. I suppose it was, as long as you remember the 
416       standard 16->32 bit issues.
417    */
418
419    u8 sixteen_bit_padding;
420} __packed wavefront_alias;
421
422typedef struct wf_drum {
423    u8 PatchNumber;
424    u8 MixLevel:7;
425    u8 Unmute:1;
426    u8 Group:4;
427    u8 Unused1:4;
428    u8 PanModSource:2;
429    u8 PanModulated:1;
430    u8 PanAmount:4;
431    u8 Unused2:1;
432} wavefront_drum;
433
434typedef struct wf_drumkit {
435    struct wf_drum drum[NUM_MIDIKEYS];
436} wavefront_drumkit;
437
438typedef struct wf_channel_programs {
439    u8 Program[NUM_MIDICHANNELS];
440} wavefront_channel_programs;
441
442/* How to get MIDI channel status from the data returned by
443   a WFC_GET_CHANNEL_STATUS command (a struct wf_channel_programs)
444*/
445
446#define WF_CHANNEL_STATUS(ch,wcp) (wcp)[(ch/7)] & (1<<((ch)%7))
447
448typedef union wf_any {
449    wavefront_sample s;
450    wavefront_multisample ms;
451    wavefront_alias a;
452    wavefront_program pr;
453    wavefront_patch p;
454    wavefront_drum d;
455} wavefront_any;
456
457/* Hannu Solvainen hoped that his "patch_info" struct in soundcard.h
458   might work for other wave-table based patch loading situations.
459   Alas, his fears were correct. The WaveFront doesn't even come with
460   just "patches", but several different kind of structures that
461   control the sound generation process.
462 */
463
464typedef struct wf_patch_info {
465    
466    /* the first two fields are used by the OSS "patch loading" interface
467       only, and are unused by the current user-level library.
468    */
469
470    s16   key;               /* Use WAVEFRONT_PATCH here */
471    u16  devno;             /* fill in when sending */
472    u8  subkey;            /* WF_ST_{SAMPLE,ALIAS,etc.} */
473
474#define WAVEFRONT_FIND_FREE_SAMPLE_SLOT 999
475
476    u16  number;            /* patch/sample/prog number */
477
478    u32  size;              /* size of any data included in 
479				  one of the fields in `hdrptr', or
480				  as `dataptr'.
481
482				  NOTE: for actual samples, this is
483				  the size of the *SELECTED CHANNEL*
484				  even if more data is actually available.
485				  
486				  So, a stereo sample (2 channels) of
487				  6000 bytes total has `size' = 3000.
488
489				  See the macros and comments for
490				  WF_{GET,SET}_CHANNEL above.
491
492			       */
493    wavefront_any __user *hdrptr;      /* user-space ptr to hdr bytes */
494    u16 __user *dataptr;            /* actual sample data */
495
496    wavefront_any hdr;          /* kernel-space copy of hdr bytes */         
497} wavefront_patch_info;
498
499/* The maximum number of bytes we will ever move to or from user space
500   in response to a WFC_* command.  This obviously doesn't cover
501   actual sample data.
502*/
503
504#define WF_MAX_READ sizeof(wavefront_multisample)
505#define WF_MAX_WRITE sizeof(wavefront_multisample)
506
507/*
508   This allows us to execute any WF command except the download/upload
509   ones, which are handled differently due to copyin/copyout issues as
510   well as data-nybbling to/from the card.
511 */
512
513typedef struct wavefront_control {
514    int cmd;                           /* WFC_* */
515    char status;                       /* return status to user-space */
516    unsigned char rbuf[WF_MAX_READ];   /* bytes read from card */
517    unsigned char wbuf[WF_MAX_WRITE];  /* bytes written to card */
518} wavefront_control;
519
520#define WFCTL_WFCMD    0x1
521#define WFCTL_LOAD_SPP 0x2
522
523/* Modulator table */
524
525#define WF_MOD_LFO1      0
526#define WF_MOD_LFO2      1
527#define WF_MOD_ENV1      2
528#define WF_MOD_ENV2      3
529#define WF_MOD_KEYBOARD  4
530#define WF_MOD_LOGKEY    5
531#define WF_MOD_VELOCITY  6
532#define WF_MOD_LOGVEL    7
533#define WF_MOD_RANDOM    8
534#define WF_MOD_PRESSURE  9
535#define WF_MOD_MOD_WHEEL 10
536#define WF_MOD_1         WF_MOD_MOD_WHEEL 
537#define WF_MOD_BREATH    11
538#define WF_MOD_2         WF_MOD_BREATH
539#define WF_MOD_FOOT      12
540#define WF_MOD_4         WF_MOD_FOOT
541#define WF_MOD_VOLUME    13
542#define WF_MOD_7         WF_MOD_VOLUME
543#define WF_MOD_PAN       14
544#define WF_MOD_10        WF_MOD_PAN
545#define WF_MOD_EXPR      15
546#define WF_MOD_11        WF_MOD_EXPR
547
548/* FX-related material */
549
550typedef struct wf_fx_info {
551    int request;             /* see list below */
552    long data[4];             /* we don't need much */
553} wavefront_fx_info;
554
555/* support for each of these will be forthcoming once I or someone 
556   else has figured out which of the addresses on page 6 and page 7 of 
557   the YSS225 control each parameter. Incidentally, these come from
558   the Windows driver interface, but again, Turtle Beach didn't
559   document the API to use them.
560*/
561
562#define WFFX_SETOUTGAIN		        0
563#define WFFX_SETSTEREOOUTGAIN		1
564#define WFFX_SETREVERBIN1GAIN		2
565#define WFFX_SETREVERBIN2GAIN		3
566#define WFFX_SETREVERBIN3GAIN		4
567#define WFFX_SETCHORUSINPORT		5
568#define WFFX_SETREVERBIN1PORT		6
569#define WFFX_SETREVERBIN2PORT		7
570#define WFFX_SETREVERBIN3PORT		8
571#define WFFX_SETEFFECTPORT		9
572#define WFFX_SETAUXPORT		        10
573#define WFFX_SETREVERBTYPE		11
574#define WFFX_SETREVERBDELAY		12
575#define WFFX_SETCHORUSLFO		13
576#define WFFX_SETCHORUSPMD		14
577#define WFFX_SETCHORUSAMD		15
578#define WFFX_SETEFFECT		        16
579#define WFFX_SETBASEALL		        17
580#define WFFX_SETREVERBALL		18
581#define WFFX_SETCHORUSALL		20
582#define WFFX_SETREVERBDEF		22
583#define WFFX_SETCHORUSDEF		23
584#define WFFX_DELAYSETINGAIN		24
585#define WFFX_DELAYSETFBGAIN	        25
586#define WFFX_DELAYSETFBLPF		26
587#define WFFX_DELAYSETGAIN		27
588#define WFFX_DELAYSETTIME		28
589#define WFFX_DELAYSETFBTIME		29
590#define WFFX_DELAYSETALL		30
591#define WFFX_DELAYSETDEF		32
592#define WFFX_SDELAYSETINGAIN		33
593#define WFFX_SDELAYSETFBGAIN		34
594#define WFFX_SDELAYSETFBLPF		35
595#define WFFX_SDELAYSETGAIN		36
596#define WFFX_SDELAYSETTIME		37
597#define WFFX_SDELAYSETFBTIME		38
598#define WFFX_SDELAYSETALL		39
599#define WFFX_SDELAYSETDEF		41
600#define WFFX_DEQSETINGAIN		42
601#define WFFX_DEQSETFILTER		43
602#define WFFX_DEQSETALL		        44
603#define WFFX_DEQSETDEF		        46
604#define WFFX_MUTE		        47
605#define WFFX_FLANGESETBALANCE	        48	
606#define WFFX_FLANGESETDELAY		49
607#define WFFX_FLANGESETDWFFX_TH		50
608#define WFFX_FLANGESETFBGAIN		51
609#define WFFX_FLANGESETINGAIN		52
610#define WFFX_FLANGESETLFO		53
611#define WFFX_FLANGESETALL		54
612#define WFFX_FLANGESETDEF		56
613#define WFFX_PITCHSETSHIFT		57
614#define WFFX_PITCHSETBALANCE		58
615#define WFFX_PITCHSETALL		59
616#define WFFX_PITCHSETDEF		61
617#define WFFX_SRSSETINGAIN		62
618#define WFFX_SRSSETSPACE		63
619#define WFFX_SRSSETCENTER		64
620#define WFFX_SRSSETGAIN		        65
621#define WFFX_SRSSETMODE	        	66
622#define WFFX_SRSSETDEF		        68
623
624/* Allow direct user-space control over FX memory/coefficient data.
625   In theory this could be used to download the FX microprogram,
626   but it would be a little slower, and involve some weird code.
627 */
628
629#define WFFX_MEMSET              69
630
631#endif /* __SOUND_WAVEFRONT_H__ */
v5.4
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2#ifndef __SOUND_WAVEFRONT_H__
  3#define __SOUND_WAVEFRONT_H__
  4
  5/*
  6 *  Driver for Turtle Beach Wavefront cards (Maui,Tropez,Tropez+)
  7 *
  8 *  Copyright (c) by Paul Barton-Davis <pbd@op.net>
  9 */
 10
 11#if (!defined(__GNUC__) && !defined(__GNUG__))
 12
 13     You will not be able to compile this file correctly without gcc, because
 14     it is necessary to pack the "wavefront_alias" structure to a size
 15     of 22 bytes, corresponding to 16-bit alignment (as would have been
 16     the case on the original platform, MS-DOS). If this is not done,
 17     then WavePatch-format files cannot be read/written correctly.
 18     The method used to do this here ("__attribute__((packed)") is
 19     completely compiler dependent.
 20     
 21     All other wavefront_* types end up aligned to 32 bit values and
 22     still have the same (correct) size.
 23
 24#else
 25
 26     /* However, note that as of G++ 2.7.3.2, g++ was unable to
 27	correctly parse *type* __attribute__ tags. It will do the
 28	right thing if we use the "packed" attribute on each struct
 29	member, which has the same semantics anyway. 
 30     */
 31
 32#endif /* __GNUC__ */
 33
 34/***************************** WARNING ********************************
 35  PLEASE DO NOT MODIFY THIS FILE IN ANY WAY THAT AFFECTS ITS ABILITY TO 
 36  BE USED WITH EITHER C *OR* C++.
 37 **********************************************************************/
 38
 39#ifndef NUM_MIDIKEYS 
 40#define NUM_MIDIKEYS 128
 41#endif  /* NUM_MIDIKEYS */
 42
 43#ifndef NUM_MIDICHANNELS
 44#define NUM_MIDICHANNELS 16
 45#endif  /* NUM_MIDICHANNELS */
 46
 47/* These are very useful/important. the original wavefront interface
 48   was developed on a 16 bit system, where sizeof(int) = 2
 49   bytes. Defining things like this makes the code much more portable, and
 50   easier to understand without having to toggle back and forth
 51   between a 16-bit view of the world and a 32-bit one. 
 52 */   
 53
 54#ifndef __KERNEL__
 55/* keep them for compatibility */
 56typedef short s16;
 57typedef unsigned short u16;
 58typedef int s32;
 59typedef unsigned int u32;
 60typedef char s8;
 61typedef unsigned char u8;
 62typedef s16 INT16;
 63typedef u16 UINT16;
 64typedef s32 INT32;
 65typedef u32 UINT32;
 66typedef s8 CHAR8;
 67typedef u8 UCHAR8;
 68#endif
 69
 70/* Pseudo-commands not part of the WaveFront command set.
 71   These are used for various driver controls and direct
 72   hardware control.
 73 */
 74
 75#define WFC_DEBUG_DRIVER                0
 76#define WFC_FX_IOCTL                    1
 77#define WFC_PATCH_STATUS                2
 78#define WFC_PROGRAM_STATUS              3
 79#define WFC_SAMPLE_STATUS               4
 80#define WFC_DISABLE_INTERRUPTS          5
 81#define WFC_ENABLE_INTERRUPTS           6
 82#define WFC_INTERRUPT_STATUS            7
 83#define WFC_ROMSAMPLES_RDONLY           8
 84#define WFC_IDENTIFY_SLOT_TYPE          9
 85
 86/* Wavefront synth commands
 87 */
 88
 89#define WFC_DOWNLOAD_SAMPLE		0x80
 90#define WFC_DOWNLOAD_BLOCK		0x81
 91#define WFC_DOWNLOAD_MULTISAMPLE	0x82
 92#define WFC_DOWNLOAD_SAMPLE_ALIAS	0x83
 93#define WFC_DELETE_SAMPLE		0x84
 94#define WFC_REPORT_FREE_MEMORY		0x85
 95#define WFC_DOWNLOAD_PATCH		0x86
 96#define WFC_DOWNLOAD_PROGRAM		0x87
 97#define WFC_SET_SYNTHVOL		0x89
 98#define WFC_SET_NVOICES			0x8B
 99#define WFC_DOWNLOAD_DRUM		0x90
100#define WFC_GET_SYNTHVOL		0x92
101#define WFC_GET_NVOICES			0x94
102#define WFC_DISABLE_CHANNEL		0x9A
103#define WFC_ENABLE_CHANNEL		0x9B
104#define WFC_MISYNTH_OFF			0x9D
105#define WFC_MISYNTH_ON			0x9E
106#define WFC_FIRMWARE_VERSION		0x9F
107#define WFC_GET_NSAMPLES		0xA0
108#define WFC_DISABLE_DRUM_PROGRAM	0xA2
109#define WFC_UPLOAD_PATCH		0xA3
110#define WFC_UPLOAD_PROGRAM		0xA4
111#define WFC_SET_TUNING			0xA6
112#define WFC_GET_TUNING			0xA7
113#define WFC_VMIDI_ON			0xA8
114#define WFC_VMIDI_OFF			0xA9
115#define WFC_MIDI_STATUS			0xAA
116#define WFC_GET_CHANNEL_STATUS		0xAB
117#define WFC_DOWNLOAD_SAMPLE_HEADER	0xAC
118#define WFC_UPLOAD_SAMPLE_HEADER	0xAD
119#define WFC_UPLOAD_MULTISAMPLE		0xAE
120#define WFC_UPLOAD_SAMPLE_ALIAS		0xAF
121#define WFC_IDENTIFY_SAMPLE_TYPE	0xB0
122#define WFC_DOWNLOAD_EDRUM_PROGRAM	0xB1
123#define WFC_UPLOAD_EDRUM_PROGRAM	0xB2
124#define WFC_SET_EDRUM_CHANNEL		0xB3
125#define WFC_INSTOUT_LEVELS		0xB4
126#define WFC_PEAKOUT_LEVELS		0xB5
127#define WFC_REPORT_CHANNEL_PROGRAMS	0xB6
128#define WFC_HARDWARE_VERSION		0xCF
129#define WFC_UPLOAD_SAMPLE_PARAMS	0xD7
130#define WFC_DOWNLOAD_OS			0xF1
131#define WFC_NOOP                        0xFF
132
133#define WF_MAX_SAMPLE   512
134#define WF_MAX_PATCH    256
135#define WF_MAX_PROGRAM  128
136
137#define WF_SECTION_MAX  44   /* longest OS section length */
138
139/* # of bytes we send to the board when sending it various kinds of
140   substantive data, such as samples, patches and programs.
141*/
142
143#define WF_PROGRAM_BYTES 32
144#define WF_PATCH_BYTES 132
145#define WF_SAMPLE_BYTES 27
146#define WF_SAMPLE_HDR_BYTES 25
147#define WF_ALIAS_BYTES 25
148#define WF_DRUM_BYTES 9
149#define WF_MSAMPLE_BYTES 259 /* (MIDI_KEYS * 2) + 3 */
150
151#define WF_ACK     0x80
152#define WF_DMA_ACK 0x81
153
154/* OR-values for MIDI status bits */
155
156#define WF_MIDI_VIRTUAL_ENABLED 0x1
157#define WF_MIDI_VIRTUAL_IS_EXTERNAL 0x2
158#define WF_MIDI_IN_TO_SYNTH_DISABLED 0x4
159
160/* slot indexes for struct address_info: makes code a little more mnemonic */
161
162#define WF_SYNTH_SLOT         0
163#define WF_INTERNAL_MIDI_SLOT 1
164#define WF_EXTERNAL_MIDI_SLOT 2
165
166/* Magic MIDI bytes used to switch I/O streams on the ICS2115 MPU401
167   emulation. Note these NEVER show up in output from the device and
168   should NEVER be used in input unless Virtual MIDI mode has been 
169   disabled. If they do show up as input, the results are unpredictable.
170*/
171
172#define WF_EXTERNAL_SWITCH  0xFD
173#define WF_INTERNAL_SWITCH  0xF9
174
175/* Debugging flags */
176
177#define WF_DEBUG_CMD 0x1
178#define WF_DEBUG_DATA 0x2
179#define WF_DEBUG_LOAD_PATCH 0x4
180#define WF_DEBUG_IO 0x8
181
182/* WavePatch file format stuff */
183
184#define WF_WAVEPATCH_VERSION     120;  /*  Current version number (1.2)  */
185#define WF_MAX_COMMENT           64    /*  Comment length */
186#define WF_NUM_LAYERS            4
187#define WF_NAME_LENGTH           32
188#define WF_SOURCE_LENGTH         260
189
190#define BankFileID     "Bank"
191#define DrumkitFileID  "DrumKit"
192#define ProgramFileID  "Program"
193
194struct wf_envelope
195{
196    u8 attack_time:7;
197    u8 Unused1:1;
198
199    u8 decay1_time:7;
200    u8 Unused2:1;
201
202    u8 decay2_time:7;
203    u8 Unused3:1;
204
205    u8 sustain_time:7;
206    u8 Unused4:1;
207
208    u8 release_time:7;
209    u8 Unused5:1;
210
211    u8 release2_time:7;
212    u8 Unused6:1;
213
214    s8 attack_level;
215    s8 decay1_level;
216    s8 decay2_level;
217    s8 sustain_level;
218    s8 release_level;
219
220    u8 attack_velocity:7;
221    u8 Unused7:1;
222
223    u8 volume_velocity:7;
224    u8 Unused8:1;
225
226    u8 keyboard_scaling:7;
227    u8 Unused9:1;
228};
229typedef struct wf_envelope wavefront_envelope;
230
231struct wf_lfo
232{
233    u8 sample_number;
234
235    u8 frequency:7;
236    u8 Unused1:1;
237
238    u8 am_src:4;
239    u8 fm_src:4;
240
241    s8 fm_amount;
242    s8 am_amount;
243    s8 start_level;
244    s8 end_level;
245
246    u8 ramp_delay:7;
247    u8 wave_restart:1; /* for LFO2 only */
248
249    u8 ramp_time:7;
250    u8 Unused2:1;
251};
252typedef struct wf_lfo wavefront_lfo;
253
254struct wf_patch
255{
256    s16  frequency_bias;         /*  ** THIS IS IN MOTOROLA FORMAT!! ** */
257
258    u8 amplitude_bias:7;
259    u8 Unused1:1;
260
261    u8 portamento:7;
262    u8 Unused2:1;
263
264    u8 sample_number;
265
266    u8 pitch_bend:4;
267    u8 sample_msb:1;
268    u8 Unused3:3;
269
270    u8 mono:1;
271    u8 retrigger:1;
272    u8 nohold:1;
273    u8 restart:1;
274    u8 filterconfig:2; /* SDK says "not used" */
275    u8 reuse:1;
276    u8 reset_lfo:1;    
277
278    u8 fm_src2:4;
279    u8 fm_src1:4;   
280
281    s8 fm_amount1;
282    s8 fm_amount2;
283
284    u8 am_src:4;
285    u8 Unused4:4;
286
287    s8 am_amount;
288
289    u8 fc1_mode:4;
290    u8 fc2_mode:4;
291
292    s8 fc1_mod_amount;
293    s8 fc1_keyboard_scaling;
294    s8 fc1_bias;
295    s8 fc2_mod_amount;
296    s8 fc2_keyboard_scaling;
297    s8 fc2_bias;
298
299    u8 randomizer:7;
300    u8 Unused5:1;
301
302    struct wf_envelope envelope1;
303    struct wf_envelope envelope2;
304    struct wf_lfo lfo1;
305    struct wf_lfo lfo2;
306};
307typedef struct wf_patch wavefront_patch;
308
309struct wf_layer
310{
311    u8 patch_number;
312
313    u8 mix_level:7;
314    u8 mute:1;
315
316    u8 split_point:7;
317    u8 play_below:1;
318
319    u8 pan_mod_src:2;
320    u8 pan_or_mod:1;
321    u8 pan:4;
322    u8 split_type:1;
323};
324typedef struct wf_layer wavefront_layer;
325
326struct wf_program
327{
328    struct wf_layer layer[WF_NUM_LAYERS];
329};
330typedef struct wf_program wavefront_program;
331
332struct wf_sample_offset
333{
334    s32 Fraction:4;
335    s32 Integer:20;
336    s32 Unused:8;
337};
338typedef struct wf_sample_offset wavefront_sample_offset;          
339     
340/* Sample slot types */
341
342#define WF_ST_SAMPLE      0
343#define WF_ST_MULTISAMPLE 1
344#define WF_ST_ALIAS       2
345#define WF_ST_EMPTY       3
346
347/* pseudo's */
348
349#define WF_ST_DRUM        4
350#define WF_ST_PROGRAM     5
351#define WF_ST_PATCH       6
352#define WF_ST_SAMPLEHDR   7
353
354#define WF_ST_MASK        0xf
355
356/* Flags for slot status. These occupy the upper bits of the same byte
357   as a sample type.
358*/
359
360#define WF_SLOT_USED      0x80   /* XXX don't rely on this being accurate */
361#define WF_SLOT_FILLED    0x40
362#define WF_SLOT_ROM       0x20
363
364#define WF_SLOT_MASK      0xf0
365
366/* channel constants */
367
368#define WF_CH_MONO  0
369#define WF_CH_LEFT  1
370#define WF_CH_RIGHT 2
371
372/* Sample formats */
373
374#define LINEAR_16BIT 0
375#define WHITE_NOISE  1
376#define LINEAR_8BIT  2
377#define MULAW_8BIT   3
378
379#define WF_SAMPLE_IS_8BIT(smpl) ((smpl)->SampleResolution&2)
380
381
382/* 
383
384  Because most/all of the sample data we pass in via pointers has
385  never been copied (just mmap-ed into user space straight from the
386  disk), it would be nice to allow handling of multi-channel sample
387  data without forcing user-level extraction of the relevant bytes.
388  
389  So, we need a way of specifying which channel to use (the WaveFront
390  only handles mono samples in a given slot), and the only way to do
391  this without using some struct other than wavefront_sample as the
392  interface is the awful hack of using the unused bits in a
393  wavefront_sample:
394  
395  Val      Meaning
396  ---      -------
397  0        no channel selection (use channel 1, sample is MONO)
398  1        use first channel, and skip one
399  2        use second channel, and skip one
400  3        use third channel, and skip two
401  4        use fourth channel, skip three
402  5        use fifth channel, skip four
403  6        use six channel, skip five
404
405
406  This can handle up to 4 channels, and anyone downloading >4 channels
407  of sample data just to select one of them needs to find some tools
408  like sox ...
409
410  NOTE: values 0, 1 and 2 correspond to WF_CH_* above. This is 
411  important.
412
413*/
414
415#define WF_SET_CHANNEL(samp,chn) \
416 (samp)->Unused1 = chn & 0x1; \
417 (samp)->Unused2 = chn & 0x2; \
418 (samp)->Unused3 = chn & 0x4 
419  
420#define WF_GET_CHANNEL(samp) \
421  (((samp)->Unused3 << 2)|((samp)->Unused2<<1)|(samp)->Unused1)
422  
423typedef struct wf_sample {
424    struct wf_sample_offset sampleStartOffset;
425    struct wf_sample_offset loopStartOffset;
426    struct wf_sample_offset loopEndOffset;
427    struct wf_sample_offset sampleEndOffset;
428    s16 FrequencyBias;
429    u8 SampleResolution:2;  /* sample_format */
430    u8 Unused1:1;
431    u8 Loop:1;
432    u8 Bidirectional:1;
433    u8 Unused2:1;
434    u8 Reverse:1;
435    u8 Unused3:1;
436} wavefront_sample;
437
438typedef struct wf_multisample {
439    s16 NumberOfSamples;   /* log2 of the number of samples */
440    s16 SampleNumber[NUM_MIDIKEYS];
441} wavefront_multisample;
442
443typedef struct wf_alias {
444    s16 OriginalSample;
445
446    struct wf_sample_offset sampleStartOffset;
447    struct wf_sample_offset loopStartOffset;
448    struct wf_sample_offset sampleEndOffset;
449    struct wf_sample_offset loopEndOffset;
450
451    s16  FrequencyBias;
452
453    u8 SampleResolution:2;
454    u8 Unused1:1;
455    u8 Loop:1;
456    u8 Bidirectional:1;
457    u8 Unused2:1;
458    u8 Reverse:1;
459    u8 Unused3:1;
460    
461    /* This structure is meant to be padded only to 16 bits on their
462       original. Of course, whoever wrote their documentation didn't
463       realize that sizeof(struct) can be >=
464       sum(sizeof(struct-fields)) and so thought that giving a C level
465       description of the structs used in WavePatch files was
466       sufficient. I suppose it was, as long as you remember the 
467       standard 16->32 bit issues.
468    */
469
470    u8 sixteen_bit_padding;
471} __attribute__((packed)) wavefront_alias;
472
473typedef struct wf_drum {
474    u8 PatchNumber;
475    u8 MixLevel:7;
476    u8 Unmute:1;
477    u8 Group:4;
478    u8 Unused1:4;
479    u8 PanModSource:2;
480    u8 PanModulated:1;
481    u8 PanAmount:4;
482    u8 Unused2:1;
483} wavefront_drum;
484
485typedef struct wf_drumkit {
486    struct wf_drum drum[NUM_MIDIKEYS];
487} wavefront_drumkit;
488
489typedef struct wf_channel_programs {
490    u8 Program[NUM_MIDICHANNELS];
491} wavefront_channel_programs;
492
493/* How to get MIDI channel status from the data returned by
494   a WFC_GET_CHANNEL_STATUS command (a struct wf_channel_programs)
495*/
496
497#define WF_CHANNEL_STATUS(ch,wcp) (wcp)[(ch/7)] & (1<<((ch)%7))
498
499typedef union wf_any {
500    wavefront_sample s;
501    wavefront_multisample ms;
502    wavefront_alias a;
503    wavefront_program pr;
504    wavefront_patch p;
505    wavefront_drum d;
506} wavefront_any;
507
508/* Hannu Solvainen hoped that his "patch_info" struct in soundcard.h
509   might work for other wave-table based patch loading situations.
510   Alas, his fears were correct. The WaveFront doesn't even come with
511   just "patches", but several different kind of structures that
512   control the sound generation process.
513 */
514
515typedef struct wf_patch_info {
516    
517    /* the first two fields are used by the OSS "patch loading" interface
518       only, and are unused by the current user-level library.
519    */
520
521    s16   key;               /* Use WAVEFRONT_PATCH here */
522    u16  devno;             /* fill in when sending */
523    u8  subkey;            /* WF_ST_{SAMPLE,ALIAS,etc.} */
524
525#define WAVEFRONT_FIND_FREE_SAMPLE_SLOT 999
526
527    u16  number;            /* patch/sample/prog number */
528
529    u32  size;              /* size of any data included in 
530				  one of the fields in `hdrptr', or
531				  as `dataptr'.
532
533				  NOTE: for actual samples, this is
534				  the size of the *SELECTED CHANNEL*
535				  even if more data is actually available.
536				  
537				  So, a stereo sample (2 channels) of
538				  6000 bytes total has `size' = 3000.
539
540				  See the macros and comments for
541				  WF_{GET,SET}_CHANNEL above.
542
543			       */
544    wavefront_any __user *hdrptr;      /* user-space ptr to hdr bytes */
545    u16 __user *dataptr;            /* actual sample data */
546
547    wavefront_any hdr;          /* kernel-space copy of hdr bytes */         
548} wavefront_patch_info;
549
550/* The maximum number of bytes we will ever move to or from user space
551   in response to a WFC_* command.  This obviously doesn't cover
552   actual sample data.
553*/
554
555#define WF_MAX_READ sizeof(wavefront_multisample)
556#define WF_MAX_WRITE sizeof(wavefront_multisample)
557
558/*
559   This allows us to execute any WF command except the download/upload
560   ones, which are handled differently due to copyin/copyout issues as
561   well as data-nybbling to/from the card.
562 */
563
564typedef struct wavefront_control {
565    int cmd;                           /* WFC_* */
566    char status;                       /* return status to user-space */
567    unsigned char rbuf[WF_MAX_READ];   /* bytes read from card */
568    unsigned char wbuf[WF_MAX_WRITE];  /* bytes written to card */
569} wavefront_control;
570
571#define WFCTL_WFCMD    0x1
572#define WFCTL_LOAD_SPP 0x2
573
574/* Modulator table */
575
576#define WF_MOD_LFO1      0
577#define WF_MOD_LFO2      1
578#define WF_MOD_ENV1      2
579#define WF_MOD_ENV2      3
580#define WF_MOD_KEYBOARD  4
581#define WF_MOD_LOGKEY    5
582#define WF_MOD_VELOCITY  6
583#define WF_MOD_LOGVEL    7
584#define WF_MOD_RANDOM    8
585#define WF_MOD_PRESSURE  9
586#define WF_MOD_MOD_WHEEL 10
587#define WF_MOD_1         WF_MOD_MOD_WHEEL 
588#define WF_MOD_BREATH    11
589#define WF_MOD_2         WF_MOD_BREATH
590#define WF_MOD_FOOT      12
591#define WF_MOD_4         WF_MOD_FOOT
592#define WF_MOD_VOLUME    13
593#define WF_MOD_7         WF_MOD_VOLUME
594#define WF_MOD_PAN       14
595#define WF_MOD_10        WF_MOD_PAN
596#define WF_MOD_EXPR      15
597#define WF_MOD_11        WF_MOD_EXPR
598
599/* FX-related material */
600
601typedef struct wf_fx_info {
602    int request;             /* see list below */
603    long data[4];             /* we don't need much */
604} wavefront_fx_info;
605
606/* support for each of these will be forthcoming once I or someone 
607   else has figured out which of the addresses on page 6 and page 7 of 
608   the YSS225 control each parameter. Incidentally, these come from
609   the Windows driver interface, but again, Turtle Beach didn't
610   document the API to use them.
611*/
612
613#define WFFX_SETOUTGAIN		        0
614#define WFFX_SETSTEREOOUTGAIN		1
615#define WFFX_SETREVERBIN1GAIN		2
616#define WFFX_SETREVERBIN2GAIN		3
617#define WFFX_SETREVERBIN3GAIN		4
618#define WFFX_SETCHORUSINPORT		5
619#define WFFX_SETREVERBIN1PORT		6
620#define WFFX_SETREVERBIN2PORT		7
621#define WFFX_SETREVERBIN3PORT		8
622#define WFFX_SETEFFECTPORT		9
623#define WFFX_SETAUXPORT		        10
624#define WFFX_SETREVERBTYPE		11
625#define WFFX_SETREVERBDELAY		12
626#define WFFX_SETCHORUSLFO		13
627#define WFFX_SETCHORUSPMD		14
628#define WFFX_SETCHORUSAMD		15
629#define WFFX_SETEFFECT		        16
630#define WFFX_SETBASEALL		        17
631#define WFFX_SETREVERBALL		18
632#define WFFX_SETCHORUSALL		20
633#define WFFX_SETREVERBDEF		22
634#define WFFX_SETCHORUSDEF		23
635#define WFFX_DELAYSETINGAIN		24
636#define WFFX_DELAYSETFBGAIN	        25
637#define WFFX_DELAYSETFBLPF		26
638#define WFFX_DELAYSETGAIN		27
639#define WFFX_DELAYSETTIME		28
640#define WFFX_DELAYSETFBTIME		29
641#define WFFX_DELAYSETALL		30
642#define WFFX_DELAYSETDEF		32
643#define WFFX_SDELAYSETINGAIN		33
644#define WFFX_SDELAYSETFBGAIN		34
645#define WFFX_SDELAYSETFBLPF		35
646#define WFFX_SDELAYSETGAIN		36
647#define WFFX_SDELAYSETTIME		37
648#define WFFX_SDELAYSETFBTIME		38
649#define WFFX_SDELAYSETALL		39
650#define WFFX_SDELAYSETDEF		41
651#define WFFX_DEQSETINGAIN		42
652#define WFFX_DEQSETFILTER		43
653#define WFFX_DEQSETALL		        44
654#define WFFX_DEQSETDEF		        46
655#define WFFX_MUTE		        47
656#define WFFX_FLANGESETBALANCE	        48	
657#define WFFX_FLANGESETDELAY		49
658#define WFFX_FLANGESETDWFFX_TH		50
659#define WFFX_FLANGESETFBGAIN		51
660#define WFFX_FLANGESETINGAIN		52
661#define WFFX_FLANGESETLFO		53
662#define WFFX_FLANGESETALL		54
663#define WFFX_FLANGESETDEF		56
664#define WFFX_PITCHSETSHIFT		57
665#define WFFX_PITCHSETBALANCE		58
666#define WFFX_PITCHSETALL		59
667#define WFFX_PITCHSETDEF		61
668#define WFFX_SRSSETINGAIN		62
669#define WFFX_SRSSETSPACE		63
670#define WFFX_SRSSETCENTER		64
671#define WFFX_SRSSETGAIN		        65
672#define WFFX_SRSSETMODE	        	66
673#define WFFX_SRSSETDEF		        68
674
675/* Allow direct user-space control over FX memory/coefficient data.
676   In theory this could be used to download the FX microprogram,
677   but it would be a little slower, and involve some weird code.
678 */
679
680#define WFFX_MEMSET              69
681
682#endif /* __SOUND_WAVEFRONT_H__ */