summaryrefslogtreecommitdiffstats
path: root/arm-wt-22k/lib_src/eas_sndlib.h
blob: 416be6e859c05d43051e099cb540c4c730b02aba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/*----------------------------------------------------------------------------
 *
 * File:
 * eas_sndlib.h
 *
 * Contents and purpose:
 * Declarations for the sound library
 *
 * Copyright Sonic Network Inc. 2005

 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *----------------------------------------------------------------------------
 * Revision Control:
 *   $Revision: 550 $
 *   $Date: 2007-02-02 09:37:03 -0800 (Fri, 02 Feb 2007) $
 *----------------------------------------------------------------------------
*/

#ifndef _EAS_SNDLIB_H
#define _EAS_SNDLIB_H

#include "eas_types.h"
#include "eas_synthcfg.h"

#ifdef _WT_SYNTH
#include "eas_wtengine.h"
#endif

/*----------------------------------------------------------------------------
 * This is bit of a hack to allow us to keep the same structure
 * declarations for the DLS parser. Normally, the data is located
 * in read-only memory, but for DLS, we store the data in RW
 * memory.
 *----------------------------------------------------------------------------
*/
#ifndef SCNST
#define SCNST const
#endif

/*----------------------------------------------------------------------------
 * sample size
 *----------------------------------------------------------------------------
*/
#ifdef _16_BIT_SAMPLES
typedef EAS_I16 EAS_SAMPLE;
#else
typedef EAS_I8 EAS_SAMPLE;
#endif

/*----------------------------------------------------------------------------
 * EAS Library ID - quick check for valid library and version
 *----------------------------------------------------------------------------
*/
#define _EAS_LIBRARY_VERSION        0x01534145

#define NUM_PROGRAMS_IN_BANK        128
#define INVALID_REGION_INDEX        0xffff

/* this bit in region index indicates that region is for secondary synth */
#define FLAG_RGN_IDX_FM_SYNTH       0x8000
#define FLAG_RGN_IDX_DLS_SYNTH      0x4000
#define REGION_INDEX_MASK           0x3fff

/*----------------------------------------------------------------------------
 * Generic region data structure
 *
 * This must be the first element in each region structure
 *----------------------------------------------------------------------------
*/
typedef struct s_region_tag
{
    EAS_U16     keyGroupAndFlags;
    EAS_U8      rangeLow;
    EAS_U8      rangeHigh;
} S_REGION;

/*
 * Bit fields for m_nKeyGroupAndFlags
 * Bits 0-2 are mode bits in FM synth
 * Bits 8-11 are the key group
 */
#define REGION_FLAG_IS_LOOPED                   0x01
#define REGION_FLAG_USE_WAVE_GENERATOR          0x02
#define REGION_FLAG_USE_ADPCM                   0x04
#define REGION_FLAG_ONE_SHOT                    0x08
#define REGION_FLAG_SQUARE_WAVE                 0x10
#define REGION_FLAG_OFF_CHIP                    0x20
#define REGION_FLAG_NON_SELF_EXCLUSIVE          0x40
#define REGION_FLAG_LAST_REGION                 0x8000

/*----------------------------------------------------------------------------
 * Envelope data structure
 *----------------------------------------------------------------------------
*/
typedef struct s_envelope_tag
{
    EAS_I16     attackTime;
    EAS_I16     decayTime;
    EAS_I16     sustainLevel;
    EAS_I16     releaseTime;
} S_ENVELOPE;

/*----------------------------------------------------------------------------
 * DLS envelope data structure
 *----------------------------------------------------------------------------
*/
typedef struct s_dls_envelope_tag
{
    EAS_I16         delayTime;
    EAS_I16         attackTime;
    EAS_I16         holdTime;
    EAS_I16         decayTime;
    EAS_I16         sustainLevel;
    EAS_I16         releaseTime;
    EAS_I16         velToAttack;
    EAS_I16         keyNumToDecay;
    EAS_I16         keyNumToHold;
} S_DLS_ENVELOPE;

/*----------------------------------------------------------------------------
 * LFO data structure
 *----------------------------------------------------------------------------
*/
typedef struct s_lfo_params_tag
{
    EAS_I16     lfoFreq;
    EAS_I16     lfoDelay;
} S_LFO_PARAMS;

/*----------------------------------------------------------------------------
 * Articulation data structure
 *----------------------------------------------------------------------------
*/
typedef struct s_articulation_tag
{
    S_ENVELOPE  eg1;
    S_ENVELOPE  eg2;
    EAS_I16     lfoToPitch;
    EAS_I16     lfoDelay;
    EAS_I16     lfoFreq;
    EAS_I16     eg2ToPitch;
    EAS_I16     eg2ToFc;
    EAS_I16     filterCutoff;
    EAS_I8      lfoToGain;
    EAS_U8      filterQ;
    EAS_I8      pan;
} S_ARTICULATION;

/*----------------------------------------------------------------------------
 * DLS articulation data structure
 *----------------------------------------------------------------------------
*/

typedef struct s_dls_articulation_tag
{
    S_LFO_PARAMS    modLFO;
    S_LFO_PARAMS    vibLFO;

    S_DLS_ENVELOPE  eg1;
    S_DLS_ENVELOPE  eg2;

    EAS_I16         eg1ShutdownTime;

    EAS_I16         filterCutoff;
    EAS_I16         modLFOToFc;
    EAS_I16         modLFOCC1ToFc;
    EAS_I16         modLFOChanPressToFc;
    EAS_I16         eg2ToFc;
    EAS_I16         velToFc;
    EAS_I16         keyNumToFc;

    EAS_I16         modLFOToGain;
    EAS_I16         modLFOCC1ToGain;
    EAS_I16         modLFOChanPressToGain;

    EAS_I16         tuning;
    EAS_I16         keyNumToPitch;
    EAS_I16         vibLFOToPitch;
    EAS_I16         vibLFOCC1ToPitch;
    EAS_I16         vibLFOChanPressToPitch;
    EAS_I16         modLFOToPitch;
    EAS_I16         modLFOCC1ToPitch;
    EAS_I16         modLFOChanPressToPitch;
    EAS_I16         eg2ToPitch;

    /* pad to 4-byte boundary */
    EAS_U16         pad;

    EAS_I8          pan;
    EAS_U8          filterQandFlags;

#ifdef _REVERB
    EAS_I16         reverbSend;
    EAS_I16         cc91ToReverbSend;
#endif

#ifdef _CHORUS
    EAS_I16         chorusSend;
    EAS_I16         cc93ToChorusSend;
#endif
} S_DLS_ARTICULATION;

/* flags in filterQandFlags
 * NOTE: Q is stored in bottom 5 bits
 */
#define FLAG_DLS_VELOCITY_SENSITIVE     0x80
#define FILTER_Q_MASK                   0x1f

/*----------------------------------------------------------------------------
 * Wavetable region data structure
 *----------------------------------------------------------------------------
*/
typedef struct s_wt_region_tag
{
    S_REGION    region;
    EAS_I16     tuning;
    EAS_I16     gain;
    EAS_U32     loopStart;
    EAS_U32     loopEnd;
    EAS_U16     waveIndex;
    EAS_U16     artIndex;
} S_WT_REGION;

/*----------------------------------------------------------------------------
 * DLS region data structure
 *----------------------------------------------------------------------------
*/
typedef struct s_dls_region_tag
{
    S_WT_REGION     wtRegion;
    EAS_U8          velLow;
    EAS_U8          velHigh;
} S_DLS_REGION;

/*----------------------------------------------------------------------------
 * FM synthesizer data structures
 *----------------------------------------------------------------------------
*/
typedef struct s_fm_oper_tag
{
    EAS_I16     tuning;
    EAS_U8      attackDecay;
    EAS_U8      velocityRelease;
    EAS_U8      egKeyScale;
    EAS_U8      sustain;
    EAS_U8      gain;
    EAS_U8      flags;
} S_FM_OPER;

/* defines for S_FM_OPER.m_nFlags */
#define FM_OPER_FLAG_MONOTONE           0x01
#define FM_OPER_FLAG_NO_VIBRATO         0x02
#define FM_OPER_FLAG_NOISE              0x04
#define FM_OPER_FLAG_LINEAR_VELOCITY    0x08

/* NOTE: The first two structure elements are common with S_WT_REGION
 * and we will rely on that in the voice management code and must
 * remain there unless the voice management code is revisited.
 */
typedef struct s_fm_region_tag
{
    S_REGION        region;
    EAS_U8          vibTrem;
    EAS_U8          lfoFreqDelay;
    EAS_U8          feedback;
    EAS_I8          pan;
    S_FM_OPER       oper[4];
} S_FM_REGION;

/*----------------------------------------------------------------------------
 * Common data structures
 *----------------------------------------------------------------------------
*/

/*----------------------------------------------------------------------------
 * Program data structure
 * Used for individual programs not stored as a complete bank.
 *----------------------------------------------------------------------------
*/
typedef struct s_program_tag
{
    EAS_U32 locale;
    EAS_U16 regionIndex;
} S_PROGRAM;

/*----------------------------------------------------------------------------
 * Bank data structure
 *
 * A bank always consists of 128 programs. If a bank is less than 128
 * programs, it should be stored as a spare matrix in the pPrograms
 * array.
 *
 * bankNum:     MSB/LSB of MIDI bank select controller
 * regionIndex: Index of first region in program
 *----------------------------------------------------------------------------
*/
typedef struct s_bank_tag
{
    EAS_U16 locale;
    EAS_U16 regionIndex[NUM_PROGRAMS_IN_BANK];
} S_BANK;


/* defines for libFormat field
 * bits 0-17 are the sample rate
 * bit 18 is true if wavetable is present
 * bit 19 is true if FM is present
 * bit 20 is true if filter is enabled
 * bit 21 is sample depth (0 = 8-bits, 1 = 16-bits)
 * bits 22-31 are reserved
 */
#define LIBFORMAT_SAMPLE_RATE_MASK      0x0003ffff
#define LIB_FORMAT_TYPE_MASK            0x000c0000
#define LIB_FORMAT_WAVETABLE            0x00000000
#define LIB_FORMAT_FM                   0x00040000
#define LIB_FORMAT_HYBRID               0x00080000
#define LIB_FORMAT_FILTER_ENABLED       0x00100000
#define LIB_FORMAT_16_BIT_SAMPLES       0x00200000

#ifdef DLS_SYNTHESIZER
/*----------------------------------------------------------------------------
 * DLS data structure
 *
 * pDLSPrograms         pointer to array of DLS programs
 * pDLSRegions          pointer to array of DLS regions
 * pDLSArticulations    pointer to array of DLS articulations
 * pSampleLen           pointer to array of sample lengths
 * ppSamples            pointer to array of sample pointers
 * numDLSPrograms       number of DLS programs
 * numDLSRegions        number of DLS regions
 * numDLSArticulations  number of DLS articulations
 * numDLSSamples        number of DLS samples
 *----------------------------------------------------------------------------
*/
typedef struct s_eas_dls_tag
{
    S_PROGRAM           *pDLSPrograms;
    S_DLS_REGION        *pDLSRegions;
    S_DLS_ARTICULATION  *pDLSArticulations;
    EAS_U32             *pDLSSampleLen;
    EAS_U32             *pDLSSampleOffsets;
    EAS_SAMPLE          *pDLSSamples;
    EAS_U16             numDLSPrograms;
    EAS_U16             numDLSRegions;
    EAS_U16             numDLSArticulations;
    EAS_U16             numDLSSamples;
    EAS_U8              refCount;
} S_DLS;
#endif

/*----------------------------------------------------------------------------
 * Sound library data structure
 *
 * pBanks           pointer to array of banks
 * pPrograms        pointer to array of programs
 * pWTRegions       pointer to array of wavetable regions
 * pFMRegions       pointer to array of FM regions
 * pArticulations   pointer to array of articulations
 * pSampleLen       pointer to array of sample lengths
 * ppSamples        pointer to array of sample pointers
 * numBanks         number of banks
 * numPrograms      number of individual program
 * numRegions       number of regions
 * numArticulations number of articulations
 * numSamples       number of samples
 *----------------------------------------------------------------------------
*/
typedef struct s_eas_sndlib_tag
{
    SCNST EAS_U32               identifier;
    SCNST EAS_U32               libAttr;

    SCNST S_BANK                *pBanks;
    SCNST S_PROGRAM             *pPrograms;

    SCNST S_WT_REGION           *pWTRegions;
    SCNST S_ARTICULATION        *pArticulations;
    SCNST EAS_U32               *pSampleLen;
    SCNST EAS_U32               *pSampleOffsets;
    SCNST EAS_SAMPLE            *pSamples;

    SCNST S_FM_REGION           *pFMRegions;

    SCNST EAS_U16               numBanks;
    SCNST EAS_U16               numPrograms;

    SCNST EAS_U16               numWTRegions;
    SCNST EAS_U16               numArticulations;
    SCNST EAS_U16               numSamples;

    SCNST EAS_U16               numFMRegions;
} S_EAS;

#endif