blob: fac698780b51c6a07dd5b721c162cdecfefd6b7e [file] [log] [blame]
The Android Open Source Project7df30102009-03-03 19:30:38 -08001/*----------------------------------------------------------------------------
2 *
Dave Sparks56c99cd2009-08-24 17:35:45 -07003 * File:
The Android Open Source Project7df30102009-03-03 19:30:38 -08004 * eas_mdls.c
5 *
6 * Contents and purpose:
7 * This file contains DLS to EAS converter.
Dave Sparks56c99cd2009-08-24 17:35:45 -07008 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08009 * Copyright (c) 2005 Sonic Network Inc.
10
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 *
23 *----------------------------------------------------------------------------
24 * Revision Control:
25 * $Revision: 818 $
26 * $Date: 2007-08-02 15:19:41 -0700 (Thu, 02 Aug 2007) $
27 *----------------------------------------------------------------------------
28*/
29
30/*
31 * NOTES:
32 *
33 * Processor Endian-ness:
34 *
35 * We use the EAS_HWGetDWord() and EAS_HWGetWord () functions
36 * extensively in this module. It would probably be faster to read
37 * an entire data structure, but this introduces the problem of
38 * sensitivity to processor endian-ness to the parser. By utlilizing
39 * the host wrapper functions, we avoid having to flip bytes around
40 * for big-endian processors. The default host wrapper versions of
41 * these functions are insensitive to processor endian-ness due to
42 * the fact that they read the file as a byte stream.
43 *
44 * Dynamic Memory:
45 *
46 * Dynamic memory allocation is a risky proposition in a mobile
47 * device. The memory can become fragmented, resulting in an
48 * inability to allocate a memory block, or garbage collection
49 * routines can use many CPU cycles. Either can contribute to
50 * failures of critical systems. Therefore, we try to minimize the
51 * number of memory allocations we make.
52 *
53 * We allocate a single large block of memory for the entire
54 * converted DLS collection, including the articulation data and
55 * samples. This block is then sub-allocated for the various
56 * data structures.
57 *
58 * Parser Overview:
59 *
60 * We make two passes through the file, the first pass to count the
61 * number of instruments, regions, etc. and allocate memory for
62 * them. The second pass parses the data into the allocated data
63 * structures.
64 *
65 * Conditional chunks are challenging in that they can occur
66 * anywhere in the list chunk that contains them. To simplify, we
67 * parse the blocks in a list in specific order, no matter which
68 * order they appear in the file. This way we don't allocate memory
69 * and parse a block that we end up throwing away later due to
70 * a conditional chunk.
71 *
72 * Assumptions that may bite us in the future:
73 *
74 * We make some assumptions to simplify things. The most fundamental
75 * assumption is that there will be no more than one of any type of
76 * chunk in a list. While this is consistent with the block diagram
77 * of the file layout in the mDLS spec, there is nothing in the
78 * spec that precludes having mulitple lar2 or rgn2 chunks, with
79 * conditional blocks that dictate their usage.
80 *
81 * DLS -> EAS Conversion Process:
82 *
83 * Another challenge is that the DLS structure does not map well to
84 * the current EAS sound library structure. Not all DLS constructs
85 * are supported, and data from DLS structures must sometimes be
86 * mapped to multiple EAS data structures. To simplify the process,
87 * the EAS region, articulation, and envelopes are treated as a
88 * single combined unit. Thus for each region, there must be one
89 * articulation element and two envelope elements.
90 *
91 * The sample processing is also a multi-step process. First the
92 * ptbl chunk is pre-parsed to determine the number of samples
93 * in the collection. The next step is to parse the instrument data
94 * to determine which samples are actually used by instruments.
95 * Some samples may not be used because they are used only in
96 * conditional blocks that the synthesizer cannot parse, or the
97 * author neglected to remove unused samples from the collection.
98 * In the next step, the active samples are read into memory and
99 * converted to the appropriate playback format. Finally, as the
100 * instruments are processed, the links are made to the samples and
101 * wsmp data is extracted for the region and articulation data
102 * structures.
103*/
104
105#ifndef _FILTER_ENABLED
106#error "Filter must be enabled if DLS_SYNTHESIZER is enabled"
107#endif
108
109/*------------------------------------
110 * includes
111 *------------------------------------
112*/
113
114/* this define allows us to use the sndlib.h structures as RW memory */
115#define SCNST
116
Wei Jia56d15322017-02-07 10:35:31 -0800117#include "log/log.h"
118
The Android Open Source Project7df30102009-03-03 19:30:38 -0800119#include "eas_data.h"
120#include "eas_host.h"
121#include "eas_mdls.h"
122#include "eas_math.h"
123#include "dls.h"
124#include "dls2.h"
125#include "eas_report.h"
taeseok715.kim92585972019-02-12 19:13:29 +0900126#include <string.h>
The Android Open Source Project7df30102009-03-03 19:30:38 -0800127
128//2 we should replace log10() function with fixed point routine in ConvertSampleRate()
129/* lint is choking on the ARM math.h file, so we declare the log10 function here */
130extern double log10(double x);
131
132/*------------------------------------
133 * defines
134 *------------------------------------
135*/
136
137// #define _DEBUG_DLS
138
Dave Sparks56c99cd2009-08-24 17:35:45 -0700139#define DLS_MAX_WAVE_COUNT 1024
140#define DLS_MAX_ART_COUNT 2048
141#define DLS_MAX_REGION_COUNT 2048
142#define DLS_MAX_INST_COUNT 256
143#define MAX_DLS_WAVE_SIZE (1024*1024)
The Android Open Source Project7df30102009-03-03 19:30:38 -0800144
Wei Jia163e00f2015-08-20 16:03:14 -0700145#ifndef EAS_U32_MAX
146#define EAS_U32_MAX (4294967295U)
147#endif
148
149#ifndef EAS_I32_MAX
150#define EAS_I32_MAX (2147483647)
151#endif
152
The Android Open Source Project7df30102009-03-03 19:30:38 -0800153/*------------------------------------
154 * typedefs
155 *------------------------------------
156*/
157
158/* offsets to articulation data */
159typedef enum
160{
Dave Sparks56c99cd2009-08-24 17:35:45 -0700161 PARAM_MODIFIED = 0,
162 PARAM_MOD_LFO_FREQ,
163 PARAM_MOD_LFO_DELAY,
The Android Open Source Project7df30102009-03-03 19:30:38 -0800164
Dave Sparks56c99cd2009-08-24 17:35:45 -0700165 PARAM_VIB_LFO_FREQ,
166 PARAM_VIB_LFO_DELAY,
The Android Open Source Project7df30102009-03-03 19:30:38 -0800167
Dave Sparks56c99cd2009-08-24 17:35:45 -0700168 PARAM_VOL_EG_DELAY,
169 PARAM_VOL_EG_ATTACK,
170 PARAM_VOL_EG_HOLD,
171 PARAM_VOL_EG_DECAY,
172 PARAM_VOL_EG_SUSTAIN,
173 PARAM_VOL_EG_RELEASE,
174 PARAM_VOL_EG_SHUTDOWN,
175 PARAM_VOL_EG_VEL_TO_ATTACK,
176 PARAM_VOL_EG_KEY_TO_DECAY,
177 PARAM_VOL_EG_KEY_TO_HOLD,
The Android Open Source Project7df30102009-03-03 19:30:38 -0800178
Dave Sparks56c99cd2009-08-24 17:35:45 -0700179 PARAM_MOD_EG_DELAY,
180 PARAM_MOD_EG_ATTACK,
181 PARAM_MOD_EG_HOLD,
182 PARAM_MOD_EG_DECAY,
183 PARAM_MOD_EG_SUSTAIN,
184 PARAM_MOD_EG_RELEASE,
185 PARAM_MOD_EG_VEL_TO_ATTACK,
186 PARAM_MOD_EG_KEY_TO_DECAY,
187 PARAM_MOD_EG_KEY_TO_HOLD,
The Android Open Source Project7df30102009-03-03 19:30:38 -0800188
Dave Sparks56c99cd2009-08-24 17:35:45 -0700189 PARAM_INITIAL_FC,
190 PARAM_INITIAL_Q,
191 PARAM_MOD_LFO_TO_FC,
192 PARAM_MOD_LFO_CC1_TO_FC,
193 PARAM_MOD_LFO_CHAN_PRESS_TO_FC,
194 PARAM_MOD_EG_TO_FC,
195 PARAM_VEL_TO_FC,
196 PARAM_KEYNUM_TO_FC,
The Android Open Source Project7df30102009-03-03 19:30:38 -0800197
Dave Sparks56c99cd2009-08-24 17:35:45 -0700198 PARAM_MOD_LFO_TO_GAIN,
199 PARAM_MOD_LFO_CC1_TO_GAIN,
200 PARAM_MOD_LFO_CHAN_PRESS_TO_GAIN,
201 PARAM_VEL_TO_GAIN,
202
203 PARAM_TUNING,
204 PARAM_KEYNUM_TO_PITCH,
205 PARAM_VIB_LFO_TO_PITCH,
206 PARAM_VIB_LFO_CC1_TO_PITCH,
207 PARAM_VIB_LFO_CHAN_PRESS_TO_PITCH,
208 PARAM_MOD_LFO_TO_PITCH,
209 PARAM_MOD_LFO_CC1_TO_PITCH,
210 PARAM_MOD_LFO_CHAN_PRESS_TO_PITCH,
211 PARAM_MOD_EG_TO_PITCH,
212
213 PARAM_DEFAULT_PAN,
214 PARAM_MIDI_CC91_TO_REVERB_SEND,
215 PARAM_DEFAULT_REVERB_SEND,
216 PARAM_MIDI_CC93_TO_CHORUS_SEND,
217 PARAM_DEFAULT_CHORUS_SEND,
218 PARAM_TABLE_SIZE
The Android Open Source Project7df30102009-03-03 19:30:38 -0800219} E_ART_INDEX;
220
221/* temporary data structure combining region, articulation, and envelope data */
222typedef struct s_art_dls_tag
223{
Dave Sparks56c99cd2009-08-24 17:35:45 -0700224 EAS_I16 values[PARAM_TABLE_SIZE];
The Android Open Source Project7df30102009-03-03 19:30:38 -0800225} S_DLS_ART_VALUES;
226
227/* temporary data structure for wlnk chunk data */
228typedef struct
229{
Dave Sparks56c99cd2009-08-24 17:35:45 -0700230 EAS_I32 gain;
231 EAS_U32 loopStart;
232 EAS_U32 loopLength;
233 EAS_U32 sampleRate;
234 EAS_U16 bitsPerSample;
235 EAS_I16 fineTune;
236 EAS_U8 unityNote;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800237} S_WSMP_DATA;
238
239/* temporary data structure used while parsing a DLS file */
240typedef struct
241{
Dave Sparks56c99cd2009-08-24 17:35:45 -0700242 S_DLS *pDLS;
243 EAS_HW_DATA_HANDLE hwInstData;
244 EAS_FILE_HANDLE fileHandle;
245 S_WSMP_DATA *wsmpData;
246 EAS_U32 instCount;
247 EAS_U32 regionCount;
248 EAS_U32 artCount;
249 EAS_U32 waveCount;
250 EAS_U32 wavePoolSize;
251 EAS_U32 wavePoolOffset;
252 EAS_BOOL bigEndian;
253 EAS_BOOL filterUsed;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800254} SDLS_SYNTHESIZER_DATA;
255
256/* connection lookup table */
257typedef struct s_connection_tag
258{
Dave Sparks56c99cd2009-08-24 17:35:45 -0700259 EAS_U16 source;
260 EAS_U16 control;
261 EAS_U16 destination;
262 EAS_U16 connection;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800263} S_CONNECTION;
264
Dave Sparks56c99cd2009-08-24 17:35:45 -0700265static const S_CONNECTION connTable[] =
The Android Open Source Project7df30102009-03-03 19:30:38 -0800266{
Dave Sparks56c99cd2009-08-24 17:35:45 -0700267 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_LFO_FREQUENCY, PARAM_MOD_LFO_FREQ },
268 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_LFO_STARTDELAY, PARAM_MOD_LFO_DELAY},
The Android Open Source Project7df30102009-03-03 19:30:38 -0800269
Dave Sparks56c99cd2009-08-24 17:35:45 -0700270 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_VIB_FREQUENCY, PARAM_VIB_LFO_FREQ },
271 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_VIB_STARTDELAY, PARAM_VIB_LFO_DELAY },
272
273 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_EG1_DELAYTIME, PARAM_VOL_EG_DELAY },
274 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_EG1_ATTACKTIME, PARAM_VOL_EG_ATTACK },
275 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_EG1_HOLDTIME, PARAM_VOL_EG_HOLD },
276 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_EG1_DECAYTIME, PARAM_VOL_EG_DECAY },
277 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_EG1_SUSTAINLEVEL, PARAM_VOL_EG_SUSTAIN },
278 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_EG1_RELEASETIME, PARAM_VOL_EG_RELEASE },
279 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_EG1_SHUTDOWNTIME, PARAM_VOL_EG_SHUTDOWN },
280 { CONN_SRC_KEYONVELOCITY, CONN_SRC_NONE, CONN_DST_EG1_ATTACKTIME, PARAM_VOL_EG_VEL_TO_ATTACK },
281 { CONN_SRC_KEYNUMBER, CONN_SRC_NONE, CONN_DST_EG1_DECAYTIME, PARAM_VOL_EG_KEY_TO_DECAY },
282 { CONN_SRC_KEYNUMBER, CONN_SRC_NONE, CONN_DST_EG1_HOLDTIME, PARAM_VOL_EG_KEY_TO_HOLD },
283
284 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_EG2_DELAYTIME, PARAM_MOD_EG_DELAY },
285 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_EG2_ATTACKTIME, PARAM_MOD_EG_ATTACK },
286 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_EG2_HOLDTIME, PARAM_MOD_EG_HOLD },
287 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_EG2_DECAYTIME, PARAM_MOD_EG_DECAY },
288 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_EG2_SUSTAINLEVEL, PARAM_MOD_EG_SUSTAIN },
289 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_EG2_RELEASETIME, PARAM_MOD_EG_RELEASE },
290 { CONN_SRC_KEYONVELOCITY, CONN_SRC_NONE, CONN_DST_EG2_ATTACKTIME, PARAM_MOD_EG_VEL_TO_ATTACK },
291 { CONN_SRC_KEYNUMBER, CONN_SRC_NONE, CONN_DST_EG2_DECAYTIME, PARAM_MOD_EG_KEY_TO_DECAY },
292 { CONN_SRC_KEYNUMBER, CONN_SRC_NONE, CONN_DST_EG2_HOLDTIME, PARAM_MOD_EG_KEY_TO_HOLD },
293
294 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_FILTER_CUTOFF, PARAM_INITIAL_FC },
295 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_FILTER_Q, PARAM_INITIAL_Q },
296 { CONN_SRC_LFO, CONN_SRC_NONE, CONN_DST_FILTER_CUTOFF, PARAM_MOD_LFO_TO_FC },
297 { CONN_SRC_LFO, CONN_SRC_CC1, CONN_DST_FILTER_CUTOFF, PARAM_MOD_LFO_CC1_TO_FC },
298 { CONN_SRC_LFO, CONN_SRC_CHANNELPRESSURE, CONN_DST_FILTER_CUTOFF, PARAM_MOD_LFO_CHAN_PRESS_TO_FC },
299 { CONN_SRC_EG2, CONN_SRC_NONE, CONN_DST_FILTER_CUTOFF, PARAM_MOD_EG_TO_FC },
300 { CONN_SRC_KEYONVELOCITY, CONN_SRC_NONE, CONN_DST_FILTER_CUTOFF, PARAM_VEL_TO_FC },
301 { CONN_SRC_KEYNUMBER, CONN_SRC_NONE, CONN_DST_FILTER_CUTOFF, PARAM_KEYNUM_TO_FC },
302
303 { CONN_SRC_LFO, CONN_SRC_NONE, CONN_DST_GAIN, PARAM_MOD_LFO_TO_GAIN },
304 { CONN_SRC_LFO, CONN_SRC_CC1, CONN_DST_GAIN, PARAM_MOD_LFO_CC1_TO_GAIN },
305 { CONN_SRC_LFO, CONN_SRC_CHANNELPRESSURE, CONN_DST_GAIN, PARAM_MOD_LFO_CHAN_PRESS_TO_GAIN },
306 { CONN_SRC_KEYONVELOCITY, CONN_SRC_NONE, CONN_DST_GAIN, PARAM_VEL_TO_GAIN },
307
308 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_PITCH, PARAM_TUNING },
309 { CONN_SRC_KEYNUMBER, CONN_SRC_NONE, CONN_DST_PITCH, PARAM_KEYNUM_TO_PITCH },
310 { CONN_SRC_VIBRATO, CONN_SRC_NONE, CONN_DST_PITCH, PARAM_VIB_LFO_TO_PITCH },
311 { CONN_SRC_VIBRATO, CONN_SRC_CC1, CONN_DST_PITCH, PARAM_VIB_LFO_CC1_TO_PITCH },
312 { CONN_SRC_VIBRATO, CONN_SRC_CHANNELPRESSURE, CONN_DST_PITCH, PARAM_VIB_LFO_CHAN_PRESS_TO_PITCH },
313 { CONN_SRC_LFO, CONN_SRC_NONE, CONN_DST_PITCH, PARAM_MOD_LFO_TO_PITCH },
314 { CONN_SRC_LFO, CONN_SRC_CC1, CONN_DST_PITCH, PARAM_MOD_LFO_CC1_TO_PITCH },
315 { CONN_SRC_LFO, CONN_SRC_CHANNELPRESSURE, CONN_DST_PITCH, PARAM_MOD_LFO_CHAN_PRESS_TO_PITCH },
316 { CONN_SRC_EG2, CONN_SRC_NONE, CONN_DST_PITCH, PARAM_MOD_EG_TO_PITCH },
317
318 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_PAN, PARAM_DEFAULT_PAN },
319 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_REVERB, PARAM_DEFAULT_REVERB_SEND },
320 { CONN_SRC_CC91, CONN_SRC_NONE, CONN_DST_REVERB, PARAM_MIDI_CC91_TO_REVERB_SEND },
321 { CONN_SRC_NONE, CONN_SRC_NONE, CONN_DST_CHORUS, PARAM_DEFAULT_CHORUS_SEND },
322 { CONN_SRC_CC93, CONN_SRC_NONE, CONN_DST_REVERB, PARAM_MIDI_CC93_TO_CHORUS_SEND }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800323};
324#define ENTRIES_IN_CONN_TABLE (sizeof(connTable)/sizeof(S_CONNECTION))
325
326static const S_DLS_ART_VALUES defaultArt =
327{
Aurimas Liutikas957372b2016-04-19 13:17:30 -0700328 {
Dave Sparks56c99cd2009-08-24 17:35:45 -0700329 0, /* not modified */
330 -851, /* Mod LFO frequency: 5 Hz */
331 -7973, /* Mod LFO delay: 10 milliseconds */
The Android Open Source Project7df30102009-03-03 19:30:38 -0800332
Dave Sparks56c99cd2009-08-24 17:35:45 -0700333 -851, /* Vib LFO frequency: 5 Hz */
334 -7973, /* Vib LFO delay: 10 milliseconds */
The Android Open Source Project7df30102009-03-03 19:30:38 -0800335
Dave Sparks56c99cd2009-08-24 17:35:45 -0700336 -32768, /* EG1 delay time: 0 secs */
337 -32768, /* EG1 attack time: 0 secs */
338 -32768, /* EG1 hold time: 0 secs */
339 -32768, /* EG1 decay time: 0 secs */
340 1000, /* EG1 sustain level: 100.0% */
341 -32768, /* EG1 release time: 0 secs */
342 -7271, /* EG1 shutdown time: 15 msecs */
343 0, /* EG1 velocity to attack: 0 time cents */
344 0, /* EG1 key number to decay: 0 time cents */
345 0, /* EG1 key number to hold: 0 time cents */
The Android Open Source Project7df30102009-03-03 19:30:38 -0800346
Dave Sparks56c99cd2009-08-24 17:35:45 -0700347 -32768, /* EG2 delay time: 0 secs */
348 -32768, /* EG2 attack time: 0 secs */
349 -32768, /* EG2 hold time: 0 secs */
350 -32768, /* EG2 decay time: 0 secs */
351 1000, /* EG2 sustain level: 100.0% */
352 -32768, /* EG2 release time: 0 secs */
353 0, /* EG2 velocity to attack: 0 time cents */
354 0, /* EG2 key number to decay: 0 time cents */
355 0, /* EG2 key number to hold: 0 time cents */
The Android Open Source Project7df30102009-03-03 19:30:38 -0800356
Dave Sparks56c99cd2009-08-24 17:35:45 -0700357 0x7fff, /* Initial Fc: Disabled */
358 0, /* Initial Q: 0 dB */
359 0, /* Mod LFO to Fc: 0 cents */
360 0, /* Mod LFO CC1 to Fc: 0 cents */
361 0, /* Mod LFO channel pressure to Fc: 0 cents */
362 0, /* EG2 to Fc: 0 cents */
363 0, /* Velocity to Fc: 0 cents */
364 0, /* Key number to Fc: 0 cents */
The Android Open Source Project7df30102009-03-03 19:30:38 -0800365
Dave Sparks56c99cd2009-08-24 17:35:45 -0700366 0, /* Mod LFO to gain: 0 dB */
367 0, /* Mod LFO CC1 to gain: 0 dB */
368 0, /* Mod LFO channel pressure to gain: 0 dB */
369 960, /* Velocity to gain: 96 dB */
The Android Open Source Project7df30102009-03-03 19:30:38 -0800370
Dave Sparks56c99cd2009-08-24 17:35:45 -0700371 0, /* Tuning: 0 cents */
372 12800, /* Key number to pitch: 12,800 cents */
373 0, /* Vibrato to pitch: 0 cents */
374 0, /* Vibrato CC1 to pitch: 0 cents */
375 0, /* Vibrato channel pressure to pitch: 0 cents */
376 0, /* Mod LFO to pitch: 0 cents */
377 0, /* Mod LFO CC1 to pitch: 0 cents */
378 0, /* Mod LFO channel pressure to pitch: 0 cents */
379 0, /* Mod EG to pitch: 0 cents */
380
381 0, /* Default pan: 0.0% */
382 0, /* Default reverb send: 0.0% */
383 1000, /* Default CC91 to reverb send: 100.0% */
384 0, /* Default chorus send: 0.0% */
385 1000 /* Default CC93 to chorus send: 100.0% */
Aurimas Liutikas957372b2016-04-19 13:17:30 -0700386 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800387};
388
389/*------------------------------------
390 * local variables
391 *------------------------------------
392*/
393
394#if defined(_8_BIT_SAMPLES)
395static const EAS_INT bitDepth = 8;
396#elif defined(_16_BIT_SAMPLES)
397static const EAS_INT bitDepth = 16;
398#else
399#error "Must define _8_BIT_SAMPLES or _16_BIT_SAMPLES"
400#endif
401
402static const EAS_U32 outputSampleRate = _OUTPUT_SAMPLE_RATE;
403static const EAS_I32 dlsRateConvert = DLS_RATE_CONVERT;
404static const EAS_I32 dlsLFOFrequencyConvert = DLS_LFO_FREQUENCY_CONVERT;
405
406/*------------------------------------
407 * inline functions
408 *------------------------------------
409*/
410EAS_INLINE void *PtrOfs (void *p, EAS_I32 offset)
411{
Dave Sparks56c99cd2009-08-24 17:35:45 -0700412 return (void*) (((EAS_U8*) p) + offset);
The Android Open Source Project7df30102009-03-03 19:30:38 -0800413}
414
415/*------------------------------------
416 * prototypes
417 *------------------------------------
418*/
419static EAS_RESULT NextChunk (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 *pPos, EAS_U32 *pChunkType, EAS_I32 *pSize);
420static EAS_RESULT Parse_ptbl (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 wsmpPos, EAS_I32 wsmpSize);
421static EAS_RESULT Parse_wave (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_U16 waveIndex);
422static EAS_RESULT Parse_wsmp (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_WSMP_DATA *p);
423static EAS_RESULT Parse_fmt (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_WSMP_DATA *p);
Wei Jia9cf7e872015-08-21 13:41:42 -0700424static EAS_RESULT Parse_data (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, S_WSMP_DATA *p, EAS_SAMPLE *pSample, EAS_U32 sampleLen);
The Android Open Source Project7df30102009-03-03 19:30:38 -0800425static EAS_RESULT Parse_lins(SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size);
426static EAS_RESULT Parse_ins (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size);
427static EAS_RESULT Parse_insh (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_U32 *pRgnCount, EAS_U32 *pLocale);
428static EAS_RESULT Parse_lrgn (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, EAS_U16 artIndex, EAS_U32 numRegions);
429static EAS_RESULT Parse_rgn (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, EAS_U16 artIndex);
430static EAS_RESULT Parse_rgnh (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_DLS_REGION *pRgn);
431static EAS_RESULT Parse_lart (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, S_DLS_ART_VALUES *pArt);
432static EAS_RESULT Parse_art (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_DLS_ART_VALUES *pArt);
433static EAS_RESULT Parse_wlnk (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_U32 *pWaveIndex);
434static EAS_RESULT Parse_cdl (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 size, EAS_U32 *pValue);
435static void Convert_rgn (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_U16 regionIndex, EAS_U16 artIndex, EAS_U16 waveIndex, S_WSMP_DATA *pWsmp);
436static void Convert_art (SDLS_SYNTHESIZER_DATA *pDLSData, const S_DLS_ART_VALUES *pDLSArt, EAS_U16 artIndex);
437static EAS_I16 ConvertSampleRate (EAS_U32 sampleRate);
438static EAS_I16 ConvertSustain (EAS_I32 sustain);
439static EAS_I16 ConvertLFOPhaseIncrement (EAS_I32 pitchCents);
440static EAS_I8 ConvertPan (EAS_I32 pan);
441static EAS_U8 ConvertQ (EAS_I32 q);
442
443#ifdef _DEBUG_DLS
444static void DumpDLS (S_EAS *pEAS);
445#endif
446
447
448/*----------------------------------------------------------------------------
449 * DLSParser ()
450 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -0700451 * Purpose:
452 *
453 * Inputs:
The Android Open Source Project7df30102009-03-03 19:30:38 -0800454 * pEASData - pointer to over EAS data instance
455 * fileHandle - file handle for input file
456 * offset - offset into file where DLS data starts
Dave Sparks56c99cd2009-08-24 17:35:45 -0700457 *
The Android Open Source Project7df30102009-03-03 19:30:38 -0800458 * Outputs:
459 * EAS_RESULT
460 * ppEAS - address of pointer to alternate EAS wavetable
461 *
462 *----------------------------------------------------------------------------
463*/
464EAS_RESULT DLSParser (EAS_HW_DATA_HANDLE hwInstData, EAS_FILE_HANDLE fileHandle, EAS_I32 offset, EAS_DLSLIB_HANDLE *ppDLS)
465{
Dave Sparks56c99cd2009-08-24 17:35:45 -0700466 EAS_RESULT result;
467 SDLS_SYNTHESIZER_DATA dls;
468 EAS_U32 temp;
Marco Nelissen5eb6a7e2020-03-26 17:17:06 -0700469 uint32_t chunk_type;
Dave Sparks56c99cd2009-08-24 17:35:45 -0700470 EAS_I32 pos;
471 EAS_I32 chunkPos;
472 EAS_I32 size;
473 EAS_I32 instSize;
474 EAS_I32 rgnPoolSize;
475 EAS_I32 artPoolSize;
476 EAS_I32 waveLenSize;
477 EAS_I32 endDLS;
478 EAS_I32 wvplPos;
479 EAS_I32 wvplSize;
480 EAS_I32 linsPos;
481 EAS_I32 linsSize;
482 EAS_I32 ptblPos;
483 EAS_I32 ptblSize;
484 void *p;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800485
Dave Sparks56c99cd2009-08-24 17:35:45 -0700486 /* zero counts and pointers */
487 EAS_HWMemSet(&dls, 0, sizeof(dls));
The Android Open Source Project7df30102009-03-03 19:30:38 -0800488
Dave Sparks56c99cd2009-08-24 17:35:45 -0700489 /* save file handle and hwInstData to save copying pointers around */
490 dls.hwInstData = hwInstData;
491 dls.fileHandle = fileHandle;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800492
Dave Sparks56c99cd2009-08-24 17:35:45 -0700493 /* NULL return value in case of error */
494 *ppDLS = NULL;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800495
Dave Sparks56c99cd2009-08-24 17:35:45 -0700496 /* seek to start of DLS and read in RIFF tag and set processor endian flag */
497 if ((result = EAS_HWFileSeek(dls.hwInstData, dls.fileHandle, offset)) != EAS_SUCCESS)
498 return result;
Marco Nelissen5eb6a7e2020-03-26 17:17:06 -0700499 if ((result = EAS_HWReadFile(dls.hwInstData, dls.fileHandle, &chunk_type, sizeof(chunk_type), &size)) != EAS_SUCCESS)
Dave Sparks56c99cd2009-08-24 17:35:45 -0700500 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800501
Dave Sparks56c99cd2009-08-24 17:35:45 -0700502 /* check for processor endian-ness */
Marco Nelissen5eb6a7e2020-03-26 17:17:06 -0700503 dls.bigEndian = (chunk_type == CHUNK_RIFF);
The Android Open Source Project7df30102009-03-03 19:30:38 -0800504
Dave Sparks56c99cd2009-08-24 17:35:45 -0700505 /* first chunk should be DLS */
506 pos = offset;
507 if ((result = NextChunk(&dls, &pos, &temp, &size)) != EAS_SUCCESS)
508 return result;
509 if (temp != CHUNK_DLS)
510 {
511 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Expected DLS chunk, got %08lx\n", temp); */ }
512 return EAS_ERROR_FILE_FORMAT;
513 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800514
Dave Sparks56c99cd2009-08-24 17:35:45 -0700515 /* no instrument or wavepool chunks */
516 linsSize = wvplSize = ptblSize = linsPos = wvplPos = ptblPos = 0;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800517
Dave Sparks56c99cd2009-08-24 17:35:45 -0700518 /* scan the chunks in the DLS list */
519 endDLS = offset + size;
520 pos = offset + 12;
521 while (pos < endDLS)
522 {
523 chunkPos = pos;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800524
Dave Sparks56c99cd2009-08-24 17:35:45 -0700525 /* get the next chunk type */
526 if ((result = NextChunk(&dls, &pos, &temp, &size)) != EAS_SUCCESS)
527 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800528
Dave Sparks56c99cd2009-08-24 17:35:45 -0700529 /* parse useful chunks */
530 switch (temp)
531 {
532 case CHUNK_CDL:
533 if ((result = Parse_cdl(&dls, size, &temp)) != EAS_SUCCESS)
534 return result;
535 if (!temp)
536 return EAS_ERROR_UNRECOGNIZED_FORMAT;
537 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800538
Dave Sparks56c99cd2009-08-24 17:35:45 -0700539 case CHUNK_LINS:
540 linsPos = chunkPos + 12;
541 linsSize = size - 4;
542 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800543
Dave Sparks56c99cd2009-08-24 17:35:45 -0700544 case CHUNK_WVPL:
545 wvplPos = chunkPos + 12;
546 wvplSize = size - 4;
547 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800548
Dave Sparks56c99cd2009-08-24 17:35:45 -0700549 case CHUNK_PTBL:
550 ptblPos = chunkPos + 8;
551 ptblSize = size - 4;
552 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800553
Dave Sparks56c99cd2009-08-24 17:35:45 -0700554 default:
555 break;
556 }
557 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800558
Dave Sparks56c99cd2009-08-24 17:35:45 -0700559 /* must have a lins chunk */
560 if (linsSize == 0)
561 {
562 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "No lins chunk found"); */ }
563 return EAS_ERROR_UNRECOGNIZED_FORMAT;
564 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800565
Dave Sparks56c99cd2009-08-24 17:35:45 -0700566 /* must have a wvpl chunk */
567 if (wvplSize == 0)
568 {
569 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "No wvpl chunk found"); */ }
570 return EAS_ERROR_UNRECOGNIZED_FORMAT;
571 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800572
Dave Sparks56c99cd2009-08-24 17:35:45 -0700573 /* must have a ptbl chunk */
Aurimas Liutikas957372b2016-04-19 13:17:30 -0700574 if ((ptblSize == 0) || (ptblSize > (EAS_I32) (DLS_MAX_WAVE_COUNT * sizeof(POOLCUE) + sizeof(POOLTABLE))))
Dave Sparks56c99cd2009-08-24 17:35:45 -0700575 {
576 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "No ptbl chunk found"); */ }
577 return EAS_ERROR_UNRECOGNIZED_FORMAT;
578 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800579
Dave Sparks56c99cd2009-08-24 17:35:45 -0700580 /* pre-parse the wave pool chunk */
581 if ((result = Parse_ptbl(&dls, ptblPos, wvplPos, wvplSize)) != EAS_SUCCESS)
582 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800583
Dave Sparks56c99cd2009-08-24 17:35:45 -0700584 /* limit check */
585 if ((dls.waveCount == 0) || (dls.waveCount > DLS_MAX_WAVE_COUNT))
586 {
587 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "DLS file contains invalid #waves [%u]\n", dls.waveCount); */ }
588 return EAS_ERROR_FILE_FORMAT;
589 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800590
Dave Sparks56c99cd2009-08-24 17:35:45 -0700591 /* allocate memory for wsmp data */
592 dls.wsmpData = EAS_HWMalloc(dls.hwInstData, (EAS_I32) (sizeof(S_WSMP_DATA) * dls.waveCount));
593 if (dls.wsmpData == NULL)
594 {
595 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "EAS_HWMalloc for wsmp data failed\n"); */ }
596 return EAS_ERROR_MALLOC_FAILED;
597 }
598 EAS_HWMemSet(dls.wsmpData, 0, (EAS_I32) (sizeof(S_WSMP_DATA) * dls.waveCount));
The Android Open Source Project7df30102009-03-03 19:30:38 -0800599
Dave Sparks56c99cd2009-08-24 17:35:45 -0700600 /* pre-parse the lins chunk */
601 result = Parse_lins(&dls, linsPos, linsSize);
602 if (result == EAS_SUCCESS)
603 {
The Android Open Source Project7df30102009-03-03 19:30:38 -0800604
Dave Sparks56c99cd2009-08-24 17:35:45 -0700605 /* limit check */
606 if ((dls.regionCount == 0) || (dls.regionCount > DLS_MAX_REGION_COUNT))
607 {
608 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "DLS file contains invalid #regions [%u]\n", dls.regionCount); */ }
Marco Nelissen2815be22017-11-06 12:18:41 -0800609 EAS_HWFree(dls.hwInstData, dls.wsmpData);
Dave Sparks56c99cd2009-08-24 17:35:45 -0700610 return EAS_ERROR_FILE_FORMAT;
611 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800612
Dave Sparks56c99cd2009-08-24 17:35:45 -0700613 /* limit check */
614 if ((dls.artCount == 0) || (dls.artCount > DLS_MAX_ART_COUNT))
615 {
616 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "DLS file contains invalid #articulations [%u]\n", dls.regionCount); */ }
Marco Nelissen2815be22017-11-06 12:18:41 -0800617 EAS_HWFree(dls.hwInstData, dls.wsmpData);
Dave Sparks56c99cd2009-08-24 17:35:45 -0700618 return EAS_ERROR_FILE_FORMAT;
619 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800620
Dave Sparks56c99cd2009-08-24 17:35:45 -0700621 /* limit check */
622 if ((dls.instCount == 0) || (dls.instCount > DLS_MAX_INST_COUNT))
623 {
624 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "DLS file contains invalid #instruments [%u]\n", dls.instCount); */ }
Marco Nelissen2815be22017-11-06 12:18:41 -0800625 EAS_HWFree(dls.hwInstData, dls.wsmpData);
Dave Sparks56c99cd2009-08-24 17:35:45 -0700626 return EAS_ERROR_FILE_FORMAT;
627 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800628
Dave Sparks56c99cd2009-08-24 17:35:45 -0700629 /* Allocate memory for the converted DLS data */
630 /* calculate size of instrument data */
631 instSize = (EAS_I32) (sizeof(S_PROGRAM) * dls.instCount);
The Android Open Source Project7df30102009-03-03 19:30:38 -0800632
Dave Sparks56c99cd2009-08-24 17:35:45 -0700633 /* calculate size of region pool */
634 rgnPoolSize = (EAS_I32) (sizeof(S_DLS_REGION) * dls.regionCount);
The Android Open Source Project7df30102009-03-03 19:30:38 -0800635
Dave Sparks56c99cd2009-08-24 17:35:45 -0700636 /* calculate size of articulation pool, add one for default articulation */
637 dls.artCount++;
638 artPoolSize = (EAS_I32) (sizeof(S_DLS_ARTICULATION) * dls.artCount);
The Android Open Source Project7df30102009-03-03 19:30:38 -0800639
Dave Sparks56c99cd2009-08-24 17:35:45 -0700640 /* calculate size of wave length and offset arrays */
641 waveLenSize = (EAS_I32) (dls.waveCount * sizeof(EAS_U32));
The Android Open Source Project7df30102009-03-03 19:30:38 -0800642
Dave Sparks56c99cd2009-08-24 17:35:45 -0700643 /* calculate final memory size */
644 size = (EAS_I32) sizeof(S_EAS) + instSize + rgnPoolSize + artPoolSize + (2 * waveLenSize) + (EAS_I32) dls.wavePoolSize;
645 if (size <= 0) {
Marco Nelissen2815be22017-11-06 12:18:41 -0800646 EAS_HWFree(dls.hwInstData, dls.wsmpData);
Dave Sparks56c99cd2009-08-24 17:35:45 -0700647 return EAS_ERROR_FILE_FORMAT;
648 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800649
Dave Sparks56c99cd2009-08-24 17:35:45 -0700650 /* allocate the main EAS chunk */
651 dls.pDLS = EAS_HWMalloc(dls.hwInstData, size);
652 if (dls.pDLS == NULL)
653 {
654 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "EAS_HWMalloc failed for DLS memory allocation size %ld\n", size); */ }
Marco Nelissen2815be22017-11-06 12:18:41 -0800655 EAS_HWFree(dls.hwInstData, dls.wsmpData);
Dave Sparks56c99cd2009-08-24 17:35:45 -0700656 return EAS_ERROR_MALLOC_FAILED;
657 }
658 EAS_HWMemSet(dls.pDLS, 0, size);
659 dls.pDLS->refCount = 1;
660 p = PtrOfs(dls.pDLS, sizeof(S_EAS));
The Android Open Source Project7df30102009-03-03 19:30:38 -0800661
Dave Sparks56c99cd2009-08-24 17:35:45 -0700662 /* setup pointer to programs */
663 dls.pDLS->numDLSPrograms = (EAS_U16) dls.instCount;
664 dls.pDLS->pDLSPrograms = p;
665 p = PtrOfs(p, instSize);
The Android Open Source Project7df30102009-03-03 19:30:38 -0800666
Dave Sparks56c99cd2009-08-24 17:35:45 -0700667 /* setup pointer to regions */
668 dls.pDLS->pDLSRegions = p;
669 dls.pDLS->numDLSRegions = (EAS_U16) dls.regionCount;
670 p = PtrOfs(p, rgnPoolSize);
The Android Open Source Project7df30102009-03-03 19:30:38 -0800671
Dave Sparks56c99cd2009-08-24 17:35:45 -0700672 /* setup pointer to articulations */
673 dls.pDLS->numDLSArticulations = (EAS_U16) dls.artCount;
674 dls.pDLS->pDLSArticulations = p;
675 p = PtrOfs(p, artPoolSize);
The Android Open Source Project7df30102009-03-03 19:30:38 -0800676
Dave Sparks56c99cd2009-08-24 17:35:45 -0700677 /* setup pointer to wave length table */
678 dls.pDLS->numDLSSamples = (EAS_U16) dls.waveCount;
679 dls.pDLS->pDLSSampleLen = p;
680 p = PtrOfs(p, waveLenSize);
The Android Open Source Project7df30102009-03-03 19:30:38 -0800681
Dave Sparks56c99cd2009-08-24 17:35:45 -0700682 /* setup pointer to wave offsets table */
683 dls.pDLS->pDLSSampleOffsets = p;
684 p = PtrOfs(p, waveLenSize);
685
686 /* setup pointer to wave pool */
687 dls.pDLS->pDLSSamples = p;
688
689 /* clear filter flag */
690 dls.filterUsed = EAS_FALSE;
691
692 /* parse the wave pool and load samples */
693 result = Parse_ptbl(&dls, ptblPos, wvplPos, wvplSize);
694 }
695
696 /* create the default articulation */
Marco Nelissen3d9a1f52015-08-21 08:54:54 -0700697 if (dls.pDLS) {
698 Convert_art(&dls, &defaultArt, 0);
699 dls.artCount = 1;
700 }
Dave Sparks56c99cd2009-08-24 17:35:45 -0700701
702 /* parse the lins chunk and load instruments */
703 dls.regionCount = dls.instCount = 0;
704 if (result == EAS_SUCCESS)
705 result = Parse_lins(&dls, linsPos, linsSize);
706
707 /* clean up any temporary objects that were allocated */
708 if (dls.wsmpData)
709 EAS_HWFree(dls.hwInstData, dls.wsmpData);
710
711 /* if successful, return a pointer to the EAS collection */
712 if (result == EAS_SUCCESS)
713 {
714 *ppDLS = dls.pDLS;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800715#ifdef _DEBUG_DLS
Dave Sparks56c99cd2009-08-24 17:35:45 -0700716 DumpDLS(dls.pDLS);
The Android Open Source Project7df30102009-03-03 19:30:38 -0800717#endif
Dave Sparks56c99cd2009-08-24 17:35:45 -0700718 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800719
Dave Sparks56c99cd2009-08-24 17:35:45 -0700720 /* something went wrong, deallocate the EAS collection */
721 else
722 DLSCleanup(dls.hwInstData, dls.pDLS);
The Android Open Source Project7df30102009-03-03 19:30:38 -0800723
Dave Sparks56c99cd2009-08-24 17:35:45 -0700724 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800725}
726
727/*----------------------------------------------------------------------------
728 * DLSCleanup ()
729 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -0700730 * Purpose:
731 *
732 * Inputs:
The Android Open Source Project7df30102009-03-03 19:30:38 -0800733 * pEASData - pointer to over EAS data instance
734 * pEAS - pointer to alternate EAS wavetable
Dave Sparks56c99cd2009-08-24 17:35:45 -0700735 *
The Android Open Source Project7df30102009-03-03 19:30:38 -0800736 * Outputs:
737 * EAS_RESULT
738 *
739 *----------------------------------------------------------------------------
740*/
741EAS_RESULT DLSCleanup (EAS_HW_DATA_HANDLE hwInstData, S_DLS *pDLS)
742{
743
Dave Sparks56c99cd2009-08-24 17:35:45 -0700744 /* free the allocated memory */
745 if (pDLS)
746 {
747 if (pDLS->refCount)
748 {
749 if (--pDLS->refCount == 0)
750 EAS_HWFree(hwInstData, pDLS);
751 }
752 }
753 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800754}
755
756/*----------------------------------------------------------------------------
757 * DLSAddRef ()
758 *----------------------------------------------------------------------------
759 * Increment reference count
760 *----------------------------------------------------------------------------
761*/
762void DLSAddRef (S_DLS *pDLS)
763{
Dave Sparks56c99cd2009-08-24 17:35:45 -0700764 if (pDLS)
765 pDLS->refCount++;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800766}
767
768/*----------------------------------------------------------------------------
769 * NextChunk ()
770 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -0700771 * Purpose:
The Android Open Source Project7df30102009-03-03 19:30:38 -0800772 * Returns the type and size of the next chunk in the file
773 *
Dave Sparks56c99cd2009-08-24 17:35:45 -0700774 * Inputs:
775 *
The Android Open Source Project7df30102009-03-03 19:30:38 -0800776 * Outputs:
777 *
778 * Side Effects:
779 *----------------------------------------------------------------------------
780*/
781static EAS_RESULT NextChunk (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 *pPos, EAS_U32 *pChunkType, EAS_I32 *pSize)
782{
Dave Sparks56c99cd2009-08-24 17:35:45 -0700783 EAS_RESULT result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800784
Dave Sparks56c99cd2009-08-24 17:35:45 -0700785 /* seek to start of chunk */
786 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, *pPos)) != EAS_SUCCESS)
787 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800788
Dave Sparks56c99cd2009-08-24 17:35:45 -0700789 /* read the chunk type */
790 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, pChunkType, EAS_TRUE)) != EAS_SUCCESS)
791 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800792
Dave Sparks56c99cd2009-08-24 17:35:45 -0700793 /* read the chunk size */
794 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, pSize, EAS_FALSE)) != EAS_SUCCESS)
795 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800796
Marco Nelissenf01750a2017-05-11 14:43:54 -0700797 if (*pSize < 0) {
798 ALOGE("b/37093318");
799 return EAS_ERROR_FILE_FORMAT;
800 }
801
Dave Sparks56c99cd2009-08-24 17:35:45 -0700802 /* get form type for RIFF and LIST types */
803 if ((*pChunkType == CHUNK_RIFF) || (*pChunkType == CHUNK_LIST))
804 {
The Android Open Source Project7df30102009-03-03 19:30:38 -0800805
Dave Sparks56c99cd2009-08-24 17:35:45 -0700806 /* read the form type */
807 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, pChunkType, EAS_TRUE)) != EAS_SUCCESS)
808 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800809
Dave Sparks56c99cd2009-08-24 17:35:45 -0700810 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800811
Dave Sparks56c99cd2009-08-24 17:35:45 -0700812 /* calculate start of next chunk */
813 *pPos += *pSize + 8;
814
815 /* adjust to word boundary */
816 if (*pPos & 1)
817 (*pPos)++;
818
819 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800820}
821
822/*----------------------------------------------------------------------------
823 * Parse_ptbl ()
824 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -0700825 * Purpose:
826 *
The Android Open Source Project7df30102009-03-03 19:30:38 -0800827 *
828 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -0700829 *
830 *
The Android Open Source Project7df30102009-03-03 19:30:38 -0800831 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -0700832 *
The Android Open Source Project7df30102009-03-03 19:30:38 -0800833 *
834 *----------------------------------------------------------------------------
835*/
836static EAS_RESULT Parse_ptbl (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 wtblPos, EAS_I32 wtblSize)
837{
Dave Sparks56c99cd2009-08-24 17:35:45 -0700838 EAS_RESULT result;
839 EAS_U32 temp;
840 EAS_FILE_HANDLE tempFile;
841 EAS_U16 waveIndex;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800842
Dave Sparks56c99cd2009-08-24 17:35:45 -0700843 /* seek to start of chunk */
844 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS)
845 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800846
Dave Sparks56c99cd2009-08-24 17:35:45 -0700847 /* get the structure size */
848 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &temp, EAS_FALSE)) != EAS_SUCCESS)
849 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800850
Dave Sparks56c99cd2009-08-24 17:35:45 -0700851 /* get the number of waves */
852 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &pDLSData->waveCount, EAS_FALSE)) != EAS_SUCCESS)
853 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800854
Harish Mahendrakarc049c142020-04-30 04:24:53 +0530855 /* if second pass, ensure waveCount matches with the value parsed in first pass */
856 if (pDLSData->pDLS)
857 {
858 if (pDLSData->waveCount != pDLSData->pDLS->numDLSSamples)
859 {
860 return EAS_ERROR_DATA_INCONSISTENCY;
861 }
862 }
863
The Android Open Source Project7df30102009-03-03 19:30:38 -0800864#if 0
Dave Sparks56c99cd2009-08-24 17:35:45 -0700865 /* just need the wave count on the first pass */
866 if (!pDLSData->pDLS)
867 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800868#endif
869
Dave Sparks56c99cd2009-08-24 17:35:45 -0700870 /* open duplicate file handle */
871 if ((result = EAS_HWDupHandle(pDLSData->hwInstData, pDLSData->fileHandle, &tempFile)) != EAS_SUCCESS)
872 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800873
Dave Sparks56c99cd2009-08-24 17:35:45 -0700874 /* read to end of chunk */
875 for (waveIndex = 0; waveIndex < pDLSData->waveCount; waveIndex++)
876 {
The Android Open Source Project7df30102009-03-03 19:30:38 -0800877
Dave Sparks56c99cd2009-08-24 17:35:45 -0700878 /* get the offset to the wave and make sure it is within the wtbl chunk */
879 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, tempFile, &temp, EAS_FALSE)) != EAS_SUCCESS)
880 return result;
881 if (temp > (EAS_U32) wtblSize)
882 {
883 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Ptbl offset exceeds size of wtbl\n"); */ }
884 EAS_HWCloseFile(pDLSData->hwInstData, tempFile);
885 return EAS_ERROR_FILE_FORMAT;
886 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800887
Dave Sparks56c99cd2009-08-24 17:35:45 -0700888 /* parse the wave */
889 if ((result = Parse_wave(pDLSData, wtblPos +(EAS_I32) temp, waveIndex)) != EAS_SUCCESS)
890 return result;
891 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800892
Dave Sparks56c99cd2009-08-24 17:35:45 -0700893 /* close the temporary handle and return */
894 EAS_HWCloseFile(pDLSData->hwInstData, tempFile);
895 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800896}
897
898/*----------------------------------------------------------------------------
899 * Parse_wave ()
900 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -0700901 * Purpose:
902 *
The Android Open Source Project7df30102009-03-03 19:30:38 -0800903 *
904 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -0700905 *
906 *
The Android Open Source Project7df30102009-03-03 19:30:38 -0800907 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -0700908 *
The Android Open Source Project7df30102009-03-03 19:30:38 -0800909 *
910 *----------------------------------------------------------------------------
911*/
912static EAS_RESULT Parse_wave (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_U16 waveIndex)
913{
Dave Sparks56c99cd2009-08-24 17:35:45 -0700914 EAS_RESULT result;
915 EAS_U32 temp;
916 EAS_I32 size;
917 EAS_I32 endChunk;
918 EAS_I32 chunkPos;
919 EAS_I32 wsmpPos = 0;
920 EAS_I32 fmtPos = 0;
921 EAS_I32 dataPos = 0;
922 EAS_I32 dataSize = 0;
923 S_WSMP_DATA *p;
924 void *pSample;
925 S_WSMP_DATA wsmp;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800926
Dave Sparks56c99cd2009-08-24 17:35:45 -0700927 /* seek to start of chunk */
928 chunkPos = pos + 12;
929 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS)
930 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800931
Dave Sparks56c99cd2009-08-24 17:35:45 -0700932 /* get the chunk type */
933 if ((result = NextChunk(pDLSData, &pos, &temp, &size)) != EAS_SUCCESS)
934 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800935
Dave Sparks56c99cd2009-08-24 17:35:45 -0700936 /* make sure it is a wave chunk */
937 if (temp != CHUNK_WAVE)
938 {
939 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Offset in ptbl does not point to wave chunk\n"); */ }
940 return EAS_ERROR_FILE_FORMAT;
941 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800942
Dave Sparks56c99cd2009-08-24 17:35:45 -0700943 /* read to end of chunk */
944 pos = chunkPos;
945 endChunk = pos + size;
946 while (pos < endChunk)
947 {
948 chunkPos = pos;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800949
Dave Sparks56c99cd2009-08-24 17:35:45 -0700950 /* get the chunk type */
951 if ((result = NextChunk(pDLSData, &pos, &temp, &size)) != EAS_SUCCESS)
952 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800953
Dave Sparks56c99cd2009-08-24 17:35:45 -0700954 /* parse useful chunks */
955 switch (temp)
956 {
957 case CHUNK_WSMP:
958 wsmpPos = chunkPos + 8;
959 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800960
Dave Sparks56c99cd2009-08-24 17:35:45 -0700961 case CHUNK_FMT:
962 fmtPos = chunkPos + 8;
963 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800964
Dave Sparks56c99cd2009-08-24 17:35:45 -0700965 case CHUNK_DATA:
966 dataPos = chunkPos + 8;
967 dataSize = size;
968 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800969
Dave Sparks56c99cd2009-08-24 17:35:45 -0700970 default:
971 break;
972 }
973 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800974
Dave Sparks56c99cd2009-08-24 17:35:45 -0700975 // limit to reasonable size
Eric Laurent2d7f8e12015-05-14 09:10:40 -0700976 if (dataSize < 0 || dataSize > MAX_DLS_WAVE_SIZE)
Dave Sparks56c99cd2009-08-24 17:35:45 -0700977 {
978 return EAS_ERROR_SOUND_LIBRARY;
979 }
The Android Open Source Project7df30102009-03-03 19:30:38 -0800980
Dave Sparks56c99cd2009-08-24 17:35:45 -0700981 /* for first pass, use temporary variable */
982 if (pDLSData->pDLS == NULL)
983 p = &wsmp;
984 else
985 p = &pDLSData->wsmpData[waveIndex];
The Android Open Source Project7df30102009-03-03 19:30:38 -0800986
Dave Sparks56c99cd2009-08-24 17:35:45 -0700987 /* set the defaults */
988 p->fineTune = 0;
989 p->unityNote = 60;
990 p->gain = 0;
991 p->loopStart = 0;
992 p->loopLength = 0;
The Android Open Source Project7df30102009-03-03 19:30:38 -0800993
Dave Sparks56c99cd2009-08-24 17:35:45 -0700994 /* must have a fmt chunk */
995 if (!fmtPos)
996 {
997 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "DLS wave chunk has no fmt chunk\n"); */ }
998 return EAS_ERROR_UNRECOGNIZED_FORMAT;
999 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001000
Dave Sparks56c99cd2009-08-24 17:35:45 -07001001 /* must have a data chunk */
1002 if (!dataPos)
1003 {
1004 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "DLS wave chunk has no data chunk\n"); */ }
1005 return EAS_ERROR_UNRECOGNIZED_FORMAT;
1006 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001007
Dave Sparks56c99cd2009-08-24 17:35:45 -07001008 /* parse the wsmp chunk */
1009 if (wsmpPos)
1010 {
1011 if ((result = Parse_wsmp(pDLSData, wsmpPos, p)) != EAS_SUCCESS)
1012 return result;
1013 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001014
Dave Sparks56c99cd2009-08-24 17:35:45 -07001015 /* parse the fmt chunk */
1016 if ((result = Parse_fmt(pDLSData, fmtPos, p)) != EAS_SUCCESS)
1017 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001018
Dave Sparks56c99cd2009-08-24 17:35:45 -07001019 /* calculate the size of the wavetable needed. We need only half
1020 * the memory for 16-bit samples when in 8-bit mode, and we need
1021 * double the memory for 8-bit samples in 16-bit mode. For
1022 * unlooped samples, we may use ADPCM. If so, we need only 1/4
1023 * the memory.
1024 *
1025 * We also need to add one for looped samples to allow for
1026 * the first sample to be copied to the end of the loop.
1027 */
The Android Open Source Project7df30102009-03-03 19:30:38 -08001028
Dave Sparks56c99cd2009-08-24 17:35:45 -07001029 /* use ADPCM encode for unlooped 16-bit samples if ADPCM is enabled */
1030 /*lint -e{506} -e{774} groundwork for future version to support 8 & 16 bit */
1031 if (bitDepth == 8)
1032 {
1033 if (p->bitsPerSample == 8)
1034 size = dataSize;
1035 else
1036 /*lint -e{704} use shift for performance */
1037 size = dataSize >> 1;
1038 if (p->loopLength)
1039 size++;
1040 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001041
Dave Sparks56c99cd2009-08-24 17:35:45 -07001042 else
1043 {
1044 if (p->bitsPerSample == 16)
1045 size = dataSize;
1046 else
1047 /*lint -e{703} use shift for performance */
1048 size = dataSize << 1;
1049 if (p->loopLength)
1050 size += 2;
1051 }
1052
1053 /* for first pass, add size to wave pool size and return */
1054 if (pDLSData->pDLS == NULL)
1055 {
1056 pDLSData->wavePoolSize += (EAS_U32) size;
1057 return EAS_SUCCESS;
1058 }
1059
1060 /* allocate memory and read in the sample data */
Wei Jia9cf7e872015-08-21 13:41:42 -07001061 pSample = (EAS_U8*)pDLSData->pDLS->pDLSSamples + pDLSData->wavePoolOffset;
Dave Sparks56c99cd2009-08-24 17:35:45 -07001062 pDLSData->pDLS->pDLSSampleOffsets[waveIndex] = pDLSData->wavePoolOffset;
1063 pDLSData->pDLS->pDLSSampleLen[waveIndex] = (EAS_U32) size;
1064 pDLSData->wavePoolOffset += (EAS_U32) size;
1065 if (pDLSData->wavePoolOffset > pDLSData->wavePoolSize)
1066 {
1067 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Wave pool exceeded allocation\n"); */ }
1068 return EAS_ERROR_SOUND_LIBRARY;
1069 }
1070
Wei Jia9cf7e872015-08-21 13:41:42 -07001071 if ((result = Parse_data(pDLSData, dataPos, dataSize, p, pSample, (EAS_U32)size)) != EAS_SUCCESS)
Dave Sparks56c99cd2009-08-24 17:35:45 -07001072 return result;
1073
1074 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001075}
1076
1077/*----------------------------------------------------------------------------
1078 * Parse_wsmp ()
1079 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07001080 * Purpose:
1081 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001082 *
1083 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001084 *
1085 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001086 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001087 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001088 *
1089 *----------------------------------------------------------------------------
1090*/
1091static EAS_RESULT Parse_wsmp (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_WSMP_DATA *p)
1092{
Dave Sparks56c99cd2009-08-24 17:35:45 -07001093 EAS_RESULT result;
1094 EAS_U16 wtemp;
1095 EAS_U32 ltemp;
1096 EAS_U32 cbSize;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001097
Dave Sparks56c99cd2009-08-24 17:35:45 -07001098 /* seek to start of chunk */
1099 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS)
1100 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001101
Dave Sparks56c99cd2009-08-24 17:35:45 -07001102 /* get structure size */
1103 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &cbSize, EAS_FALSE)) != EAS_SUCCESS)
1104 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001105
Dave Sparks56c99cd2009-08-24 17:35:45 -07001106 /* get unity note */
1107 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &wtemp, EAS_FALSE)) != EAS_SUCCESS)
1108 return result;
1109 if (wtemp <= 127)
1110 p->unityNote = (EAS_U8) wtemp;
1111 else
1112 {
1113 p->unityNote = 60;
1114 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "Invalid unity note [%u] in DLS wsmp ignored, set to 60\n", wtemp); */ }
1115 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001116
Dave Sparks56c99cd2009-08-24 17:35:45 -07001117 /* get fine tune */
1118 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &p->fineTune, EAS_FALSE)) != EAS_SUCCESS)
1119 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001120
Dave Sparks56c99cd2009-08-24 17:35:45 -07001121 /* get gain */
1122 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &p->gain, EAS_FALSE)) != EAS_SUCCESS)
1123 return result;
1124 if (p->gain > 0)
1125 {
1126 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "Positive gain [%ld] in DLS wsmp ignored, set to 0dB\n", p->gain); */ }
1127 p->gain = 0;
1128 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001129
Dave Sparks56c99cd2009-08-24 17:35:45 -07001130 /* option flags */
1131 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &ltemp, EAS_FALSE)) != EAS_SUCCESS)
1132 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001133
Dave Sparks56c99cd2009-08-24 17:35:45 -07001134 /* sample loops */
1135 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &ltemp, EAS_FALSE)) != EAS_SUCCESS)
1136 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001137
Dave Sparks56c99cd2009-08-24 17:35:45 -07001138 /* if looped sample, get loop data */
1139 if (ltemp)
1140 {
The Android Open Source Project7df30102009-03-03 19:30:38 -08001141
Dave Sparks56c99cd2009-08-24 17:35:45 -07001142 if (ltemp > 1)
1143 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "DLS sample with %lu loops, ignoring extra loops\n", ltemp); */ }
1144
1145 /* skip ahead to loop data */
1146 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos + (EAS_I32) cbSize)) != EAS_SUCCESS)
1147 return result;
1148
1149 /* get structure size */
1150 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &ltemp, EAS_FALSE)) != EAS_SUCCESS)
1151 return result;
1152
1153 /* get loop type */
1154 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &ltemp, EAS_FALSE)) != EAS_SUCCESS)
1155 return result;
1156
1157 /* get loop start */
1158 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &p->loopStart, EAS_FALSE)) != EAS_SUCCESS)
1159 return result;
1160
1161 /* get loop length */
1162 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &p->loopLength, EAS_FALSE)) != EAS_SUCCESS)
1163 return result;
Wei Jia163e00f2015-08-20 16:03:14 -07001164
1165 /* ensure no overflow */
1166 if (p->loopLength
1167 && ((p->loopStart > EAS_U32_MAX - p->loopLength)
1168 || (p->loopStart + p->loopLength > EAS_U32_MAX / sizeof(EAS_SAMPLE))))
1169 {
1170 return EAS_FAILURE;
1171 }
Dave Sparks56c99cd2009-08-24 17:35:45 -07001172 }
1173
1174 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001175}
1176
1177/*----------------------------------------------------------------------------
1178 * Parse_fmt ()
1179 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07001180 * Purpose:
1181 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001182 *
1183 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001184 *
1185 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001186 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001187 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001188 *
1189 *----------------------------------------------------------------------------
1190*/
1191static EAS_RESULT Parse_fmt (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_WSMP_DATA *p)
1192{
Dave Sparks56c99cd2009-08-24 17:35:45 -07001193 EAS_RESULT result;
1194 EAS_U16 wtemp;
1195 EAS_U32 ltemp;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001196
Dave Sparks56c99cd2009-08-24 17:35:45 -07001197 /* seek to start of chunk */
1198 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS)
1199 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001200
Dave Sparks56c99cd2009-08-24 17:35:45 -07001201 /* get format tag */
1202 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &wtemp, EAS_FALSE)) != EAS_SUCCESS)
1203 return result;
1204 if (wtemp != WAVE_FORMAT_PCM)
1205 {
1206 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Unsupported DLS sample format %04x\n", wtemp); */ }
1207 return EAS_ERROR_UNRECOGNIZED_FORMAT;
1208 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001209
Dave Sparks56c99cd2009-08-24 17:35:45 -07001210 /* get number of channels */
1211 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &wtemp, EAS_FALSE)) != EAS_SUCCESS)
1212 return result;
1213 if (wtemp != 1)
1214 {
1215 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "No support for DLS multi-channel samples\n"); */ }
1216 return EAS_ERROR_UNRECOGNIZED_FORMAT;
1217 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001218
Dave Sparks56c99cd2009-08-24 17:35:45 -07001219 /* get sample rate */
1220 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &p->sampleRate, EAS_FALSE)) != EAS_SUCCESS)
1221 return result;
1222
1223 /* bytes/sec */
1224 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &ltemp, EAS_FALSE)) != EAS_SUCCESS)
1225 return result;
1226
1227 /* block align */
1228 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &wtemp, EAS_FALSE)) != EAS_SUCCESS)
1229 return result;
1230
1231 /* bits/sample */
1232 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &p->bitsPerSample, EAS_FALSE)) != EAS_SUCCESS)
1233 return result;
1234
1235 if ((p->bitsPerSample != 8) && (p->bitsPerSample != 16))
1236 {
1237 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Unsupported DLS bits-per-sample %d\n", p->bitsPerSample); */ }
1238 return EAS_ERROR_UNRECOGNIZED_FORMAT;
1239 }
1240
1241 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001242}
1243
1244#if defined( _8_BIT_SAMPLES)
1245/*----------------------------------------------------------------------------
1246 * Parse_data ()
1247 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07001248 * Purpose:
1249 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001250 * NOTE: The optimized assembly versions of the interpolator require
1251 * an extra sample at the end of the loop - a copy of the first
1252 * sample. This routine must allocate an extra sample of data and
1253 * copy the first sample of the loop to the end.
1254 *
1255 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001256 *
1257 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001258 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001259 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001260 *
1261 *----------------------------------------------------------------------------
1262*/
Wei Jia9cf7e872015-08-21 13:41:42 -07001263static EAS_RESULT Parse_data (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, S_WSMP_DATA *pWsmp, EAS_SAMPLE *pSample, EAS_U32 sampleLen)
The Android Open Source Project7df30102009-03-03 19:30:38 -08001264{
Dave Sparks56c99cd2009-08-24 17:35:45 -07001265 EAS_RESULT result;
1266 EAS_U8 convBuf[SAMPLE_CONVERT_CHUNK_SIZE];
1267 EAS_I32 count;
1268 EAS_I32 i;
1269 EAS_I8 *p;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001270
Dave Sparks56c99cd2009-08-24 17:35:45 -07001271 /* seek to start of chunk */
1272 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS)
1273 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001274
Dave Sparks56c99cd2009-08-24 17:35:45 -07001275 /* 8-bit samples in an 8-bit synth, just copy the data, and flip bit 7 */
1276 p = pSample;
1277 if (pWsmp->bitsPerSample == 8)
1278 {
1279 if ((result = EAS_HWReadFile(pDLSData->hwInstData, pDLSData->fileHandle, pSample, size, &count)) != EAS_SUCCESS)
1280 return result;
1281 for (i = 0; i < size; i++)
1282 /*lint -e{734} convert from unsigned to signed audio */
1283 *p++ ^= 0x80;
1284 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001285
Dave Sparks56c99cd2009-08-24 17:35:45 -07001286 /* 16-bit samples, need to convert to 8-bit or ADPCM */
1287 else
1288 {
The Android Open Source Project7df30102009-03-03 19:30:38 -08001289
Dave Sparks56c99cd2009-08-24 17:35:45 -07001290 while (size)
1291 {
1292 EAS_I8 *pInput;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001293
Dave Sparks56c99cd2009-08-24 17:35:45 -07001294 /* for undithered conversion, we're just copying the 8-bit data */
1295 if (pDLSData->bigEndian)
1296 pInput = (EAS_I8*) convBuf;
1297 else
1298 pInput = (EAS_I8*) convBuf + 1;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001299
Dave Sparks56c99cd2009-08-24 17:35:45 -07001300 /* read a small chunk of data and convert it */
1301 count = (size < SAMPLE_CONVERT_CHUNK_SIZE ? size : SAMPLE_CONVERT_CHUNK_SIZE);
1302 if ((result = EAS_HWReadFile(pDLSData->hwInstData, pDLSData->fileHandle, convBuf, count, &count)) != EAS_SUCCESS)
1303 return result;
1304 size -= count;
1305 /*lint -e{704} use shift for performance */
1306 count = count >> 1;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001307
Dave Sparks56c99cd2009-08-24 17:35:45 -07001308 while (count--)
1309 {
1310 *p++ = *pInput;
1311 pInput += 2;
1312 }
1313 }
1314 }
1315
1316 /* for looped samples, copy the last sample to the end */
1317 if (pWsmp->loopLength)
Wei Jia163e00f2015-08-20 16:03:14 -07001318 {
Wei Jia9cf7e872015-08-21 13:41:42 -07001319 if (sampleLen < sizeof(EAS_SAMPLE)
1320 || (pWsmp->loopStart + pWsmp->loopLength) * sizeof(EAS_SAMPLE) > sampleLen - sizeof(EAS_SAMPLE))
Wei Jia163e00f2015-08-20 16:03:14 -07001321 {
1322 return EAS_FAILURE;
1323 }
1324
Dave Sparks56c99cd2009-08-24 17:35:45 -07001325 pSample[pWsmp->loopStart + pWsmp->loopLength] = pSample[pWsmp->loopStart];
Wei Jia163e00f2015-08-20 16:03:14 -07001326 }
Dave Sparks56c99cd2009-08-24 17:35:45 -07001327
1328 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001329}
1330#elif defined(_16_BIT_SAMPLES)
taeseok715.kim92585972019-02-12 19:13:29 +09001331static EAS_RESULT Parse_data (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, S_WSMP_DATA *pWsmp, EAS_SAMPLE *pSample, EAS_U32 sampleLen)
1332{
1333 EAS_RESULT result;
1334 EAS_U8 convBuf[SAMPLE_CONVERT_CHUNK_SIZE];
1335 EAS_I32 count = 0;
1336 EAS_I32 i;
1337 EAS_I16 *p;
1338
1339 /* seek to start of chunk */
1340 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS)
1341 return result;
1342
1343 p = pSample;
1344
1345 while (size)
1346 {
1347 /* read a small chunk of data and convert it */
1348 count = (size < SAMPLE_CONVERT_CHUNK_SIZE ? size : SAMPLE_CONVERT_CHUNK_SIZE);
1349 if ((result = EAS_HWReadFile(pDLSData->hwInstData, pDLSData->fileHandle, convBuf, count, &count)) != EAS_SUCCESS)
1350 {
1351 return result;
1352 }
1353 size -= count;
1354 if (pWsmp->bitsPerSample == 16)
1355 {
1356 memcpy(p, convBuf, count);
1357 p += count >> 1;
1358 }
1359 else
1360 {
1361 for(i=0; i<count; i++)
1362 {
1363 *p++ = (short)((convBuf[i] ^ 0x80) << 8);
1364 }
1365 }
1366
1367 }
1368 /* for looped samples, copy the last sample to the end */
1369 if (pWsmp->loopLength)
1370 {
1371 if( (pDLSData->wavePoolOffset + pWsmp->loopLength) >= pDLSData->wavePoolSize )
1372 {
1373 return EAS_SUCCESS;
1374 }
Marco Nelissen3ff1a662020-09-30 16:28:55 -07001375 if (sampleLen < sizeof(EAS_SAMPLE)
1376 || (pWsmp->loopStart + pWsmp->loopLength) * sizeof(EAS_SAMPLE) > sampleLen - sizeof(EAS_SAMPLE)) {
1377 return EAS_FAILURE;
1378 }
taeseok715.kim92585972019-02-12 19:13:29 +09001379
1380 pSample[(pWsmp->loopStart + pWsmp->loopLength)>>1] = pSample[(pWsmp->loopStart)>>1];
1381 }
1382
1383 return EAS_SUCCESS;
1384}
The Android Open Source Project7df30102009-03-03 19:30:38 -08001385#else
1386#error "Must specifiy _8_BIT_SAMPLES or _16_BIT_SAMPLES"
1387#endif
1388
1389/*----------------------------------------------------------------------------
1390 * Parse_lins ()
1391 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07001392 * Purpose:
1393 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001394 *
1395 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001396 *
1397 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001398 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001399 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001400 *
1401 *----------------------------------------------------------------------------
1402*/
1403static EAS_RESULT Parse_lins (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size)
1404{
Dave Sparks56c99cd2009-08-24 17:35:45 -07001405 EAS_RESULT result;
1406 EAS_U32 temp;
1407 EAS_I32 endChunk;
1408 EAS_I32 chunkPos;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001409
Dave Sparks56c99cd2009-08-24 17:35:45 -07001410 /* seek to start of chunk */
1411 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS)
1412 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001413
Dave Sparks56c99cd2009-08-24 17:35:45 -07001414 /* read to end of chunk */
1415 endChunk = pos + size;
1416 while (pos < endChunk)
1417 {
1418 chunkPos = pos;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001419
Dave Sparks56c99cd2009-08-24 17:35:45 -07001420 /* get the next chunk type */
1421 if ((result = NextChunk(pDLSData, &pos, &temp, &size)) != EAS_SUCCESS)
1422 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001423
Dave Sparks56c99cd2009-08-24 17:35:45 -07001424 /* only instrument chunks are useful */
1425 if (temp != CHUNK_INS)
1426 continue;
1427
Harish Mahendrakarc049c142020-04-30 04:24:53 +05301428 /* if second pass, ensure instCount is less than numDLSPrograms */
1429 if (pDLSData->pDLS)
1430 {
1431 if (pDLSData->instCount >= pDLSData->pDLS->numDLSPrograms)
1432 {
1433 return EAS_ERROR_DATA_INCONSISTENCY;
1434 }
1435 }
1436
Dave Sparks56c99cd2009-08-24 17:35:45 -07001437 if ((result = Parse_ins(pDLSData, chunkPos + 12, size)) != EAS_SUCCESS)
1438 return result;
1439 }
1440
1441 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001442}
1443
1444/*----------------------------------------------------------------------------
1445 * Parse_ins ()
1446 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07001447 * Purpose:
1448 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001449 *
1450 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001451 *
1452 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001453 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001454 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001455 *
1456 *----------------------------------------------------------------------------
1457*/
1458static EAS_RESULT Parse_ins (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size)
1459{
Dave Sparks56c99cd2009-08-24 17:35:45 -07001460 EAS_RESULT result;
1461 EAS_U32 temp;
1462 EAS_I32 chunkPos;
1463 EAS_I32 endChunk;
1464 EAS_I32 lrgnPos;
1465 EAS_I32 lrgnSize;
1466 EAS_I32 lartPos;
1467 EAS_I32 lartSize;
1468 EAS_I32 lar2Pos;
1469 EAS_I32 lar2Size;
1470 EAS_I32 inshPos;
1471 EAS_U32 regionCount;
1472 EAS_U32 locale;
1473 S_DLS_ART_VALUES art;
1474 S_PROGRAM *pProgram;
1475 EAS_U16 artIndex;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001476
Dave Sparks56c99cd2009-08-24 17:35:45 -07001477 /* seek to start of chunk */
1478 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS)
1479 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001480
Dave Sparks56c99cd2009-08-24 17:35:45 -07001481 /* no chunks yet */
1482 lrgnPos = lrgnSize = lartPos = lartSize = lar2Pos = lar2Size = inshPos = artIndex = 0;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001483
Dave Sparks56c99cd2009-08-24 17:35:45 -07001484 /* read to end of chunk */
1485 endChunk = pos + size;
1486 while (pos < endChunk)
1487 {
1488 chunkPos = pos;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001489
Dave Sparks56c99cd2009-08-24 17:35:45 -07001490 /* get the next chunk type */
1491 if ((result = NextChunk(pDLSData, &pos, &temp, &size)) != EAS_SUCCESS)
1492 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001493
Dave Sparks56c99cd2009-08-24 17:35:45 -07001494 /* parse useful chunks */
1495 switch (temp)
1496 {
1497 case CHUNK_INSH:
1498 inshPos = chunkPos + 8;
1499 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001500
Dave Sparks56c99cd2009-08-24 17:35:45 -07001501 case CHUNK_LART:
1502 lartPos = chunkPos + 12;
1503 lartSize = size;
1504 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001505
Dave Sparks56c99cd2009-08-24 17:35:45 -07001506 case CHUNK_LAR2:
1507 lar2Pos = chunkPos + 12;
1508 lar2Size = size;
1509 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001510
Dave Sparks56c99cd2009-08-24 17:35:45 -07001511 case CHUNK_LRGN:
1512 lrgnPos = chunkPos + 12;
1513 lrgnSize = size;
1514 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001515
Dave Sparks56c99cd2009-08-24 17:35:45 -07001516 default:
1517 break;
1518 }
1519 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001520
Dave Sparks56c99cd2009-08-24 17:35:45 -07001521 /* must have an lrgn to be useful */
1522 if (!lrgnPos)
1523 {
1524 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "DLS ins chunk has no lrgn chunk\n"); */ }
1525 return EAS_ERROR_UNRECOGNIZED_FORMAT;
1526 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001527
Dave Sparks56c99cd2009-08-24 17:35:45 -07001528 /* must have an insh to be useful */
1529 if (!inshPos)
1530 {
1531 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "DLS ins chunk has no insh chunk\n"); */ }
1532 return EAS_ERROR_UNRECOGNIZED_FORMAT;
1533 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001534
Dave Sparks56c99cd2009-08-24 17:35:45 -07001535 /* parse the instrument header */
1536 if ((result = Parse_insh(pDLSData, inshPos, &regionCount, &locale)) != EAS_SUCCESS)
1537 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001538
Dave Sparks56c99cd2009-08-24 17:35:45 -07001539 /* initialize and parse the global data first */
1540 EAS_HWMemCpy(&art, &defaultArt, sizeof(S_DLS_ART_VALUES));
1541 if (lartPos)
1542 if ((result = Parse_lart(pDLSData, lartPos, lartSize, &art)) != EAS_SUCCESS)
1543 return result;
1544 if (lar2Pos)
1545 if ((result = Parse_lart(pDLSData, lar2Pos, lar2Size, &art)) != EAS_SUCCESS)
1546 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001547
Dave Sparks56c99cd2009-08-24 17:35:45 -07001548 if (art.values[PARAM_MODIFIED])
1549 {
1550 artIndex = (EAS_U16) pDLSData->artCount;
1551 pDLSData->artCount++;
1552 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001553
Dave Sparks56c99cd2009-08-24 17:35:45 -07001554 /* convert data on second pass */
1555 if (pDLSData->pDLS)
1556 {
1557
1558 if (art.values[PARAM_MODIFIED])
1559 Convert_art(pDLSData, &art, artIndex);
1560
1561 /* setup pointers */
1562 pProgram = &pDLSData->pDLS->pDLSPrograms[pDLSData->instCount];
1563
1564 /* initialize instrument */
1565 pProgram->locale = locale;
1566 pProgram->regionIndex = (EAS_U16) pDLSData->regionCount | FLAG_RGN_IDX_DLS_SYNTH;
1567
1568 }
1569
1570 /* parse the region data */
1571 if ((result = Parse_lrgn(pDLSData, lrgnPos, lrgnSize, artIndex, regionCount)) != EAS_SUCCESS)
1572 return result;
1573
1574 /* bump instrument count */
1575 pDLSData->instCount++;
1576 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001577}
1578
1579/*----------------------------------------------------------------------------
1580 * Parse_insh ()
1581 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07001582 * Purpose:
1583 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001584 *
1585 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001586 *
1587 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001588 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001589 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001590 *
1591 *----------------------------------------------------------------------------
1592*/
1593static EAS_RESULT Parse_insh (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_U32 *pRgnCount, EAS_U32 *pLocale)
1594{
Dave Sparks56c99cd2009-08-24 17:35:45 -07001595 EAS_RESULT result;
1596 EAS_U32 bank;
1597 EAS_U32 program;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001598
Dave Sparks56c99cd2009-08-24 17:35:45 -07001599 /* seek to start of chunk */
1600 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS)
1601 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001602
Dave Sparks56c99cd2009-08-24 17:35:45 -07001603 /* get the region count and locale */
1604 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, pRgnCount, EAS_FALSE)) != EAS_SUCCESS)
1605 return result;
1606 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &bank, EAS_FALSE)) != EAS_SUCCESS)
1607 return result;
1608 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &program, EAS_FALSE)) != EAS_SUCCESS)
1609 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001610
Dave Sparks56c99cd2009-08-24 17:35:45 -07001611 /* verify the parameters are valid */
1612 if (bank & 0x7fff8080)
1613 {
1614 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "DLS bank number is out of range: %08lx\n", bank); */ }
1615 bank &= 0xff7f;
1616 }
1617 if (program > 127)
1618 {
1619 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "DLS program number is out of range: %08lx\n", program); */ }
1620 program &= 0x7f;
1621 }
1622
1623 /* save the program number */
1624 *pLocale = (bank << 8) | program;
1625 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001626}
1627
1628/*----------------------------------------------------------------------------
1629 * Parse_lrgn ()
1630 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07001631 * Purpose:
1632 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001633 *
1634 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001635 *
1636 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001637 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001638 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001639 *
1640 *----------------------------------------------------------------------------
1641*/
1642static EAS_RESULT Parse_lrgn (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, EAS_U16 artIndex, EAS_U32 numRegions)
1643{
Dave Sparks56c99cd2009-08-24 17:35:45 -07001644 EAS_RESULT result;
1645 EAS_U32 temp;
1646 EAS_I32 chunkPos;
1647 EAS_I32 endChunk;
1648 EAS_U16 regionCount;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001649
Dave Sparks56c99cd2009-08-24 17:35:45 -07001650 /* seek to start of chunk */
1651 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS)
1652 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001653
Dave Sparks56c99cd2009-08-24 17:35:45 -07001654 /* read to end of chunk */
1655 regionCount = 0;
1656 endChunk = pos + size;
1657 while (pos < endChunk)
1658 {
1659 chunkPos = pos;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001660
Dave Sparks56c99cd2009-08-24 17:35:45 -07001661 /* get the next chunk type */
1662 if ((result = NextChunk(pDLSData, &pos, &temp, &size)) != EAS_SUCCESS)
1663 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001664
Dave Sparks56c99cd2009-08-24 17:35:45 -07001665 if ((temp == CHUNK_RGN) || (temp == CHUNK_RGN2))
1666 {
1667 if (regionCount == numRegions)
1668 {
1669 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "DLS region count exceeded cRegions value in insh, extra region ignored\n"); */ }
1670 return EAS_SUCCESS;
1671 }
Harish Mahendrakarc049c142020-04-30 04:24:53 +05301672 /* if second pass, ensure regionCount is less than numDLSRegions */
1673 if (pDLSData->pDLS)
1674 {
1675 if (pDLSData->regionCount >= pDLSData->pDLS->numDLSRegions)
1676 {
1677 return EAS_ERROR_DATA_INCONSISTENCY;
1678 }
1679 }
Dave Sparks56c99cd2009-08-24 17:35:45 -07001680 if ((result = Parse_rgn(pDLSData, chunkPos + 12, size, artIndex)) != EAS_SUCCESS)
1681 return result;
1682 regionCount++;
1683 }
1684 }
1685
1686 /* set a flag in the last region */
1687 if ((pDLSData->pDLS != NULL) && (regionCount > 0))
1688 pDLSData->pDLS->pDLSRegions[pDLSData->regionCount - 1].wtRegion.region.keyGroupAndFlags |= REGION_FLAG_LAST_REGION;
1689
1690 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001691}
1692
1693/*----------------------------------------------------------------------------
1694 * Parse_rgn ()
1695 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07001696 * Purpose:
1697 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001698 *
1699 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001700 *
1701 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001702 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001703 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001704 *
1705 *----------------------------------------------------------------------------
1706*/
1707static EAS_RESULT Parse_rgn (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, EAS_U16 artIndex)
1708{
Dave Sparks56c99cd2009-08-24 17:35:45 -07001709 EAS_RESULT result;
1710 EAS_U32 temp;
1711 EAS_I32 chunkPos;
1712 EAS_I32 endChunk;
1713 EAS_I32 rgnhPos;
1714 EAS_I32 lartPos;
1715 EAS_I32 lartSize;
1716 EAS_I32 lar2Pos;
1717 EAS_I32 lar2Size;
1718 EAS_I32 wlnkPos;
1719 EAS_I32 wsmpPos;
1720 EAS_U32 waveIndex;
1721 S_DLS_ART_VALUES art;
1722 S_WSMP_DATA wsmp;
1723 S_WSMP_DATA *pWsmp;
1724 EAS_U16 regionIndex;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001725
Dave Sparks56c99cd2009-08-24 17:35:45 -07001726 /* seek to start of chunk */
1727 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS)
1728 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001729
Dave Sparks56c99cd2009-08-24 17:35:45 -07001730 /* no chunks found yet */
1731 rgnhPos = lartPos = lartSize = lar2Pos = lar2Size = wsmpPos = wlnkPos = 0;
1732 regionIndex = (EAS_U16) pDLSData->regionCount;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001733
Dave Sparks56c99cd2009-08-24 17:35:45 -07001734 /* read to end of chunk */
1735 endChunk = pos + size;
1736 while (pos < endChunk)
1737 {
1738 chunkPos = pos;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001739
Dave Sparks56c99cd2009-08-24 17:35:45 -07001740 /* get the next chunk type */
1741 if ((result = NextChunk(pDLSData, &pos, &temp, &size)) != EAS_SUCCESS)
1742 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001743
Dave Sparks56c99cd2009-08-24 17:35:45 -07001744 /* parse useful chunks */
1745 switch (temp)
1746 {
1747 case CHUNK_CDL:
1748 if ((result = Parse_cdl(pDLSData, size, &temp)) != EAS_SUCCESS)
1749 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001750
Dave Sparks56c99cd2009-08-24 17:35:45 -07001751 /* if conditional chunk evaluates false, skip this list */
1752 if (!temp)
1753 return EAS_SUCCESS;
1754 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001755
Dave Sparks56c99cd2009-08-24 17:35:45 -07001756 case CHUNK_RGNH:
1757 rgnhPos = chunkPos + 8;
1758 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001759
Dave Sparks56c99cd2009-08-24 17:35:45 -07001760 case CHUNK_WLNK:
1761 wlnkPos = chunkPos + 8;
1762 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001763
Dave Sparks56c99cd2009-08-24 17:35:45 -07001764 case CHUNK_WSMP:
1765 wsmpPos = chunkPos + 8;
1766 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001767
Dave Sparks56c99cd2009-08-24 17:35:45 -07001768 case CHUNK_LART:
1769 lartPos = chunkPos + 12;
1770 lartSize = size;
1771 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001772
Dave Sparks56c99cd2009-08-24 17:35:45 -07001773 case CHUNK_LAR2:
1774 lar2Pos = chunkPos + 12;
1775 lar2Size = size;
1776 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001777
Dave Sparks56c99cd2009-08-24 17:35:45 -07001778 default:
1779 break;
1780 }
1781 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001782
Dave Sparks56c99cd2009-08-24 17:35:45 -07001783 /* must have a rgnh chunk to be useful */
1784 if (!rgnhPos)
1785 {
1786 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "DLS rgn chunk has no rgnh chunk\n"); */ }
1787 return EAS_ERROR_UNRECOGNIZED_FORMAT;
1788 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001789
Dave Sparks56c99cd2009-08-24 17:35:45 -07001790 /* must have a wlnk chunk to be useful */
1791 if (!wlnkPos)
1792 {
1793 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "DLS rgn chunk has no wlnk chunk\n"); */ }
1794 return EAS_ERROR_UNRECOGNIZED_FORMAT;
1795 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001796
Dave Sparks56c99cd2009-08-24 17:35:45 -07001797 /* parse wlnk chunk */
1798 if ((result = Parse_wlnk(pDLSData, wlnkPos, &waveIndex)) != EAS_SUCCESS)
1799 return result;
Wei Jia99e0e2e2015-08-20 16:25:04 -07001800 if (waveIndex >= pDLSData->waveCount)
1801 {
1802 return EAS_FAILURE;
1803 }
Dave Sparks56c99cd2009-08-24 17:35:45 -07001804 pWsmp = &pDLSData->wsmpData[waveIndex];
The Android Open Source Project7df30102009-03-03 19:30:38 -08001805
Dave Sparks56c99cd2009-08-24 17:35:45 -07001806 /* if there is any articulation data, parse it */
1807 EAS_HWMemCpy(&art, &defaultArt, sizeof(S_DLS_ART_VALUES));
1808 if (lartPos)
1809 {
1810 if ((result = Parse_lart(pDLSData, lartPos, lartSize, &art)) != EAS_SUCCESS)
1811 return result;
1812 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001813
Dave Sparks56c99cd2009-08-24 17:35:45 -07001814 if (lar2Pos)
1815 {
1816 if ((result = Parse_lart(pDLSData, lar2Pos, lar2Size, &art)) != EAS_SUCCESS)
1817 return result;
1818 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08001819
Dave Sparks56c99cd2009-08-24 17:35:45 -07001820 /* if second pass, process region header */
1821 if (pDLSData->pDLS)
1822 {
1823
1824 /* if local data was found convert it */
1825 if (art.values[PARAM_MODIFIED] == EAS_TRUE)
1826 {
Harish Mahendrakarc049c142020-04-30 04:24:53 +05301827 /* ensure artCount is less than numDLSArticulations */
1828 if (pDLSData->artCount >= pDLSData->pDLS->numDLSArticulations)
1829 {
1830 return EAS_ERROR_DATA_INCONSISTENCY;
1831 }
1832
Dave Sparks56c99cd2009-08-24 17:35:45 -07001833 Convert_art(pDLSData, &art, (EAS_U16) pDLSData->artCount);
1834 artIndex = (EAS_U16) pDLSData->artCount;
1835 }
1836
1837 /* parse region header */
1838 if ((result = Parse_rgnh(pDLSData, rgnhPos, &pDLSData->pDLS->pDLSRegions[regionIndex & REGION_INDEX_MASK])) != EAS_SUCCESS)
1839 return result;
1840
1841 /* parse wsmp chunk, copying parameters from original first */
1842 if (wsmpPos)
1843 {
1844 EAS_HWMemCpy(&wsmp, pWsmp, sizeof(wsmp));
1845 if ((result = Parse_wsmp(pDLSData, wsmpPos, &wsmp)) != EAS_SUCCESS)
1846 return result;
1847
1848 pWsmp = &wsmp;
1849 }
1850
1851 Convert_rgn(pDLSData, regionIndex, artIndex, (EAS_U16) waveIndex, pWsmp);
Wei Jia9cf7e872015-08-21 13:41:42 -07001852
1853 /* ensure loopStart and loopEnd fall in the range */
1854 if (pWsmp->loopLength != 0)
1855 {
1856 EAS_U32 sampleLen = pDLSData->pDLS->pDLSSampleLen[waveIndex];
1857 if (sampleLen < sizeof(EAS_SAMPLE)
1858 || (pWsmp->loopStart + pWsmp->loopLength) * sizeof(EAS_SAMPLE) > sampleLen - sizeof(EAS_SAMPLE))
1859 {
1860 return EAS_FAILURE;
1861 }
1862 }
Dave Sparks56c99cd2009-08-24 17:35:45 -07001863 }
1864
1865 /* if local articulation, bump count */
1866 if (art.values[PARAM_MODIFIED])
1867 pDLSData->artCount++;
1868
1869 /* increment region count */
1870 pDLSData->regionCount++;
1871 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001872}
1873
1874/*----------------------------------------------------------------------------
1875 * Parse_rgnh ()
1876 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07001877 * Purpose:
1878 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001879 *
1880 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001881 *
1882 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001883 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001884 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001885 *
1886 *----------------------------------------------------------------------------
1887*/
1888static EAS_RESULT Parse_rgnh (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_DLS_REGION *pRgn)
1889{
Dave Sparks56c99cd2009-08-24 17:35:45 -07001890 EAS_RESULT result;
1891 EAS_U16 lowKey;
1892 EAS_U16 highKey;
1893 EAS_U16 lowVel;
1894 EAS_U16 highVel;
1895 EAS_U16 optionFlags;
1896 EAS_U16 keyGroup;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001897
Dave Sparks56c99cd2009-08-24 17:35:45 -07001898 /* seek to start of chunk */
1899 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS)
1900 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001901
Dave Sparks56c99cd2009-08-24 17:35:45 -07001902 /* get the key range */
1903 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &lowKey, EAS_FALSE)) != EAS_SUCCESS)
1904 return result;
1905 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &highKey, EAS_FALSE)) != EAS_SUCCESS)
1906 return result;
1907
1908 /* check the range */
1909 if (lowKey > 127)
1910 {
1911 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "DLS rgnh: Low key out of range [%u]\n", lowKey); */ }
1912 lowKey = 127;
1913 }
1914 if (highKey > 127)
1915 {
1916 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "DLS rgnh: High key out of range [%u]\n", lowKey); */ }
1917 highKey = 127;
1918 }
1919
1920 /* get the velocity range */
1921 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &lowVel, EAS_FALSE)) != EAS_SUCCESS)
1922 return result;
1923 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &highVel, EAS_FALSE)) != EAS_SUCCESS)
1924 return result;
1925
1926 /* check the range */
1927 if (lowVel > 127)
1928 {
1929 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "DLS rgnh: Low velocity out of range [%u]\n", lowVel); */ }
1930 lowVel = 127;
1931 }
1932 if (highVel > 127)
1933 {
1934 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "DLS rgnh: High velocity out of range [%u]\n", highVel); */ }
1935 highVel = 127;
1936 }
1937
1938 /* get the option flags */
1939 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &optionFlags, EAS_FALSE)) != EAS_SUCCESS)
1940 return result;
1941
1942 /* get the key group */
1943 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &keyGroup, EAS_FALSE)) != EAS_SUCCESS)
1944 return result;
1945
1946 /* save the key range and key group */
1947 pRgn->wtRegion.region.rangeLow = (EAS_U8) lowKey;
1948 pRgn->wtRegion.region.rangeHigh = (EAS_U8) highKey;
1949
1950 /*lint -e{734} keyGroup will always be from 0-15 */
1951 pRgn->wtRegion.region.keyGroupAndFlags = keyGroup << 8;
1952 pRgn->velLow = (EAS_U8) lowVel;
1953 pRgn->velHigh = (EAS_U8) highVel;
1954 if (optionFlags & F_RGN_OPTION_SELFNONEXCLUSIVE)
1955 pRgn->wtRegion.region.keyGroupAndFlags |= REGION_FLAG_NON_SELF_EXCLUSIVE;
1956
1957 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001958}
1959
1960/*----------------------------------------------------------------------------
1961 * Parse_lart ()
1962 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07001963 * Purpose:
1964 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001965 *
1966 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001967 *
1968 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001969 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07001970 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08001971 *
1972 *----------------------------------------------------------------------------
1973*/
1974static EAS_RESULT Parse_lart (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, S_DLS_ART_VALUES *pArt)
1975{
Dave Sparks56c99cd2009-08-24 17:35:45 -07001976 EAS_RESULT result;
1977 EAS_U32 temp;
1978 EAS_I32 endChunk;
1979 EAS_I32 chunkPos;
1980 EAS_I32 art1Pos;
1981 EAS_I32 art2Pos;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001982
Dave Sparks56c99cd2009-08-24 17:35:45 -07001983 /* seek to start of chunk */
1984 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS)
1985 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001986
Dave Sparks56c99cd2009-08-24 17:35:45 -07001987 /* no articulation chunks yet */
1988 art1Pos = art2Pos = 0;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001989
Dave Sparks56c99cd2009-08-24 17:35:45 -07001990 /* read to end of chunk */
1991 endChunk = pos + size;
1992 while (pos < endChunk)
1993 {
1994 chunkPos = pos;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001995
Dave Sparks56c99cd2009-08-24 17:35:45 -07001996 /* get the next chunk type */
1997 if ((result = NextChunk(pDLSData, &pos, &temp, &size)) != EAS_SUCCESS)
1998 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08001999
Dave Sparks56c99cd2009-08-24 17:35:45 -07002000 /* parse useful chunks */
2001 switch (temp)
2002 {
2003 case CHUNK_CDL:
2004 if ((result = Parse_cdl(pDLSData, size, &temp)) != EAS_SUCCESS)
2005 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002006
Dave Sparks56c99cd2009-08-24 17:35:45 -07002007 /* if conditional chunk evaluates false, skip this list */
2008 if (!temp)
2009 return EAS_SUCCESS;
2010 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002011
Dave Sparks56c99cd2009-08-24 17:35:45 -07002012 case CHUNK_ART1:
2013 art1Pos = chunkPos + 8;
2014 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002015
Dave Sparks56c99cd2009-08-24 17:35:45 -07002016 case CHUNK_ART2:
2017 art2Pos = chunkPos + 8;
2018 break;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002019
Dave Sparks56c99cd2009-08-24 17:35:45 -07002020 default:
2021 break;
2022
2023 }
2024 }
2025
2026 if (art1Pos)
2027 {
2028 if ((result = Parse_art(pDLSData, art1Pos, pArt)) != EAS_SUCCESS)
2029 return result;
2030 }
2031
2032 if (art2Pos)
2033 {
2034 if ((result = Parse_art(pDLSData, art2Pos, pArt)) != EAS_SUCCESS)
2035 return result;
2036 }
2037
2038 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002039}
2040
2041/*----------------------------------------------------------------------------
2042 * Parse_art()
2043 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07002044 * Purpose:
2045 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002046 *
2047 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002048 *
2049 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002050 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002051 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002052 *
2053 *----------------------------------------------------------------------------
2054*/
2055static EAS_RESULT Parse_art (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_DLS_ART_VALUES *pArt)
2056{
Dave Sparks56c99cd2009-08-24 17:35:45 -07002057 EAS_RESULT result;
2058 EAS_U32 structSize;
2059 EAS_U32 numConnections;
2060 EAS_U16 source;
2061 EAS_U16 control;
2062 EAS_U16 destination;
2063 EAS_U16 transform;
2064 EAS_I32 scale;
2065 EAS_INT i;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002066
Dave Sparks56c99cd2009-08-24 17:35:45 -07002067 /* seek to start of data */
2068 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS)
2069 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002070
Dave Sparks56c99cd2009-08-24 17:35:45 -07002071 /* get the structure size */
2072 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &structSize, EAS_FALSE)) != EAS_SUCCESS)
2073 return result;
2074 pos += (EAS_I32) structSize;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002075
Dave Sparks56c99cd2009-08-24 17:35:45 -07002076 /* get the number of connections */
2077 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &numConnections, EAS_FALSE)) != EAS_SUCCESS)
2078 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002079
Dave Sparks56c99cd2009-08-24 17:35:45 -07002080 /* skip to start of connections */
2081 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS)
2082 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002083
Marco Nelissen71919432019-06-19 10:52:12 -07002084 while (numConnections)
Dave Sparks56c99cd2009-08-24 17:35:45 -07002085 {
Marco Nelissen71919432019-06-19 10:52:12 -07002086 numConnections--;
Dave Sparks56c99cd2009-08-24 17:35:45 -07002087 /* read the connection data */
2088 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &source, EAS_FALSE)) != EAS_SUCCESS)
2089 return result;
2090 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &control, EAS_FALSE)) != EAS_SUCCESS)
2091 return result;
2092 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &destination, EAS_FALSE)) != EAS_SUCCESS)
2093 return result;
2094 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &transform, EAS_FALSE)) != EAS_SUCCESS)
2095 return result;
2096 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &scale, EAS_FALSE)) != EAS_SUCCESS)
2097 return result;
2098
2099 /* look up the connection */
2100 for (i = 0; i < (EAS_INT) ENTRIES_IN_CONN_TABLE; i++)
2101 {
2102 if ((connTable[i].source == source) &&
2103 (connTable[i].destination == destination) &&
2104 (connTable[i].control == control))
2105 {
2106 /*lint -e{704} use shift for performance */
2107 pArt->values[connTable[i].connection] = (EAS_I16) (scale >> 16);
2108 pArt->values[PARAM_MODIFIED] = EAS_TRUE;
2109 break;
2110 }
2111 }
2112 if (i == PARAM_TABLE_SIZE)
2113 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "WARN: Unsupported parameter in DLS file\n"); */ }
2114 }
2115
2116 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002117}
2118
2119/*----------------------------------------------------------------------------
2120 * Parse_wlnk ()
2121 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07002122 * Purpose:
2123 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002124 *
2125 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002126 *
2127 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002128 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002129 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002130 *
2131 *----------------------------------------------------------------------------
2132*/
2133static EAS_RESULT Parse_wlnk (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_U32 *pWaveIndex)
2134{
Dave Sparks56c99cd2009-08-24 17:35:45 -07002135 EAS_RESULT result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002136
Dave Sparks56c99cd2009-08-24 17:35:45 -07002137 /* we only care about the the index */
2138 if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos + 8)) != EAS_SUCCESS)
2139 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002140
Dave Sparks56c99cd2009-08-24 17:35:45 -07002141 /* read the index */
2142 return EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle,pWaveIndex, EAS_FALSE);
The Android Open Source Project7df30102009-03-03 19:30:38 -08002143}
2144
2145/*----------------------------------------------------------------------------
2146 * PopcdlStack ()
2147 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07002148 * Purpose:
2149 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002150 *
2151 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002152 *
2153 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002154 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002155 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002156 *
2157 *----------------------------------------------------------------------------
2158*/
2159static EAS_RESULT PopcdlStack (EAS_U32 *pStack, EAS_INT *pStackPtr, EAS_U32 *pValue)
2160{
2161
Dave Sparks56c99cd2009-08-24 17:35:45 -07002162 /* stack underflow, cdl block has an errorr */
2163 if (*pStackPtr < 0)
2164 return EAS_ERROR_FILE_FORMAT;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002165
Dave Sparks56c99cd2009-08-24 17:35:45 -07002166 /* pop the value off the stack */
2167 *pValue = pStack[*pStackPtr];
2168 *pStackPtr = *pStackPtr - 1;
2169 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002170}
2171
2172/*----------------------------------------------------------------------------
2173 * PushcdlStack ()
2174 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07002175 * Purpose:
2176 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002177 *
2178 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002179 *
2180 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002181 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002182 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002183 *
2184 *----------------------------------------------------------------------------
2185*/
2186static EAS_RESULT PushcdlStack (EAS_U32 *pStack, EAS_INT *pStackPtr, EAS_U32 value)
2187{
2188
Dave Sparks56c99cd2009-08-24 17:35:45 -07002189 /* stack overflow, return an error */
Wei Jia56d15322017-02-07 10:35:31 -08002190 if (*pStackPtr >= (CDL_STACK_SIZE - 1)) {
2191 ALOGE("b/34031018, stackPtr(%d)", *pStackPtr);
2192 android_errorWriteLog(0x534e4554, "34031018");
Dave Sparks56c99cd2009-08-24 17:35:45 -07002193 return EAS_ERROR_FILE_FORMAT;
Wei Jia56d15322017-02-07 10:35:31 -08002194 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08002195
Dave Sparks56c99cd2009-08-24 17:35:45 -07002196 /* push the value onto the stack */
2197 *pStackPtr = *pStackPtr + 1;
2198 pStack[*pStackPtr] = value;
2199 return EAS_SUCCESS;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002200}
2201
2202/*----------------------------------------------------------------------------
2203 * QueryGUID ()
2204 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07002205 * Purpose:
2206 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002207 *
2208 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002209 *
2210 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002211 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002212 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002213 *
2214 *----------------------------------------------------------------------------
2215*/
2216static EAS_BOOL QueryGUID (const DLSID *pGUID, EAS_U32 *pValue)
2217{
2218
Dave Sparks56c99cd2009-08-24 17:35:45 -07002219 /* assume false */
2220 *pValue = 0;
2221 if (EAS_HWMemCmp(&DLSID_GMInHardware, pGUID, sizeof(DLSID)) == 0)
2222 {
2223 *pValue = 0xffffffff;
2224 return EAS_TRUE;
2225 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08002226
Dave Sparks56c99cd2009-08-24 17:35:45 -07002227 if (EAS_HWMemCmp(&DLSID_GSInHardware, pGUID, sizeof(DLSID)) == 0)
2228 return EAS_TRUE;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002229
Dave Sparks56c99cd2009-08-24 17:35:45 -07002230 if (EAS_HWMemCmp(&DLSID_XGInHardware, pGUID, sizeof(DLSID)) == 0)
2231 return EAS_TRUE;
2232
2233 if (EAS_HWMemCmp(&DLSID_SupportsDLS1, pGUID, sizeof(DLSID)) == 0)
2234 {
2235 *pValue = 0xffffffff;
2236 return EAS_TRUE;
2237 }
2238
2239 if (EAS_HWMemCmp(&DLSID_SupportsDLS2, pGUID, sizeof(DLSID)) == 0)
2240 return EAS_TRUE;
2241
2242 if (EAS_HWMemCmp(&DLSID_SampleMemorySize, pGUID, sizeof(DLSID)) == 0)
2243 {
2244 *pValue = MAX_DLS_MEMORY;
2245 return EAS_TRUE;
2246 }
2247
2248 if (EAS_HWMemCmp(&DLSID_ManufacturersID, pGUID, sizeof(DLSID)) == 0)
2249 {
2250 *pValue = 0x0000013A;
2251 return EAS_TRUE;
2252 }
2253
2254 if (EAS_HWMemCmp(&DLSID_ProductID, pGUID, sizeof(DLSID)) == 0)
2255 {
2256 *pValue = LIB_VERSION;
2257 return EAS_TRUE;
2258 }
2259
2260 if (EAS_HWMemCmp(&DLSID_SamplePlaybackRate, pGUID, sizeof(DLSID)) == 0)
2261 {
2262 *pValue = (EAS_U32) outputSampleRate;
2263 return EAS_TRUE;
2264 }
2265
2266 /* unrecognized DLSID */
2267 return EAS_FALSE;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002268}
2269
2270/*----------------------------------------------------------------------------
2271 * ReadDLSID ()
2272 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07002273 * Purpose:
The Android Open Source Project7df30102009-03-03 19:30:38 -08002274 * Reads a DLSID in a manner that is not sensitive to processor endian-ness
2275 *
2276 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002277 *
2278 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002279 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002280 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002281 *
2282 *----------------------------------------------------------------------------
2283*/
2284static EAS_RESULT ReadDLSID (SDLS_SYNTHESIZER_DATA *pDLSData, DLSID *pDLSID)
2285{
Dave Sparks56c99cd2009-08-24 17:35:45 -07002286 EAS_RESULT result;
2287 EAS_I32 n;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002288
Dave Sparks56c99cd2009-08-24 17:35:45 -07002289 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &pDLSID->Data1, EAS_FALSE)) != EAS_SUCCESS)
2290 return result;
2291 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &pDLSID->Data2, EAS_FALSE)) != EAS_SUCCESS)
2292 return result;
2293 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &pDLSID->Data3, EAS_FALSE)) != EAS_SUCCESS)
2294 return result;
2295 return EAS_HWReadFile(pDLSData->hwInstData, pDLSData->fileHandle, pDLSID->Data4, sizeof(pDLSID->Data4), &n);
The Android Open Source Project7df30102009-03-03 19:30:38 -08002296}
2297
2298/*----------------------------------------------------------------------------
2299 * Parse_cdl ()
2300 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07002301 * Purpose:
2302 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002303 *
2304 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002305 *
2306 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002307 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002308 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002309 *
2310 *----------------------------------------------------------------------------
2311*/
2312static EAS_RESULT Parse_cdl (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 size, EAS_U32 *pValue)
2313{
Dave Sparks56c99cd2009-08-24 17:35:45 -07002314 EAS_RESULT result;
2315 EAS_U32 stack[CDL_STACK_SIZE];
2316 EAS_U16 opcode;
2317 EAS_INT stackPtr;
2318 EAS_U32 x, y;
2319 DLSID dlsid;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002320
Dave Sparks56c99cd2009-08-24 17:35:45 -07002321 stackPtr = -1;
2322 *pValue = 0;
2323 x = 0;
2324 while (size)
2325 {
2326 /* read the opcode */
2327 if ((result = EAS_HWGetWord(pDLSData->hwInstData, pDLSData->fileHandle, &opcode, EAS_FALSE)) != EAS_SUCCESS)
2328 return result;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002329
Dave Sparks56c99cd2009-08-24 17:35:45 -07002330 /* handle binary opcodes */
2331 if (opcode <= DLS_CDL_EQ)
2332 {
2333 /* pop X and Y */
2334 if ((result = PopcdlStack(stack, &stackPtr, &x)) != EAS_SUCCESS)
2335 return result;
2336 if ((result = PopcdlStack(stack, &stackPtr, &y)) != EAS_SUCCESS)
2337 return result;
2338 switch (opcode)
2339 {
2340 case DLS_CDL_AND:
2341 x = x & y;
2342 break;
2343 case DLS_CDL_OR:
2344 x = x | y;
2345 break;
2346 case DLS_CDL_XOR:
2347 x = x ^ y;
2348 break;
2349 case DLS_CDL_ADD:
2350 x = x + y;
2351 break;
2352 case DLS_CDL_SUBTRACT:
2353 x = x - y;
2354 break;
2355 case DLS_CDL_MULTIPLY:
2356 x = x * y;
2357 break;
2358 case DLS_CDL_DIVIDE:
2359 if (!y)
2360 return EAS_ERROR_FILE_FORMAT;
2361 x = x / y;
2362 break;
2363 case DLS_CDL_LOGICAL_AND:
2364 x = (x && y);
2365 break;
2366 case DLS_CDL_LOGICAL_OR:
2367 x = (x || y);
2368 break;
2369 case DLS_CDL_LT:
2370 x = (x < y);
2371 break;
2372 case DLS_CDL_LE:
2373 x = (x <= y);
2374 break;
2375 case DLS_CDL_GT:
2376 x = (x > y);
2377 break;
2378 case DLS_CDL_GE:
2379 x = (x >= y);
2380 break;
2381 case DLS_CDL_EQ:
2382 x = (x == y);
2383 break;
2384 default:
2385 break;
2386 }
2387 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08002388
Dave Sparks56c99cd2009-08-24 17:35:45 -07002389 else if (opcode == DLS_CDL_NOT)
2390 {
2391 if ((result = PopcdlStack(stack, &stackPtr, &x)) != EAS_SUCCESS)
2392 return result;
2393 x = !x;
2394 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08002395
Dave Sparks56c99cd2009-08-24 17:35:45 -07002396 else if (opcode == DLS_CDL_CONST)
2397 {
2398 if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &x, EAS_FALSE)) != EAS_SUCCESS)
2399 return result;
2400 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08002401
Dave Sparks56c99cd2009-08-24 17:35:45 -07002402 else if (opcode == DLS_CDL_QUERY)
2403 {
2404 if ((result = ReadDLSID(pDLSData, &dlsid)) != EAS_SUCCESS)
2405 return result;
2406 QueryGUID(&dlsid, &x);
2407 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08002408
Dave Sparks56c99cd2009-08-24 17:35:45 -07002409 else if (opcode == DLS_CDL_QUERYSUPPORTED)
2410 {
2411 if ((result = ReadDLSID(pDLSData, &dlsid)) != EAS_SUCCESS)
2412 return result;
2413 x = QueryGUID(&dlsid, &y);
2414 }
2415 else
2416 { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "Unsupported opcode %d in DLS file\n", opcode); */ }
2417
2418 /* push the result on the stack */
2419 if ((result = PushcdlStack(stack, &stackPtr, x)) != EAS_SUCCESS)
2420 return result;
2421 }
2422
2423 /* pop the last result off the stack */
2424 return PopcdlStack(stack, &stackPtr, pValue);
The Android Open Source Project7df30102009-03-03 19:30:38 -08002425}
2426
2427/*----------------------------------------------------------------------------
2428 * Convert_rgn()
2429 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07002430 * Purpose:
The Android Open Source Project7df30102009-03-03 19:30:38 -08002431 * Convert region data from DLS to EAS
2432 *
2433 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002434 *
2435 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002436 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002437 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002438 *
2439 *----------------------------------------------------------------------------
2440*/
2441static void Convert_rgn (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_U16 regionIndex, EAS_U16 artIndex, EAS_U16 waveIndex, S_WSMP_DATA *pWsmp)
2442{
Dave Sparks56c99cd2009-08-24 17:35:45 -07002443 S_DLS_REGION *pRgn;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002444
Dave Sparks56c99cd2009-08-24 17:35:45 -07002445 /* setup pointers to data structures */
2446 pRgn = &pDLSData->pDLS->pDLSRegions[regionIndex];
The Android Open Source Project7df30102009-03-03 19:30:38 -08002447
Dave Sparks56c99cd2009-08-24 17:35:45 -07002448 /* intiailize indices */
2449 pRgn->wtRegion.artIndex = artIndex;
2450 pRgn->wtRegion.waveIndex = waveIndex;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002451
Dave Sparks56c99cd2009-08-24 17:35:45 -07002452 /* convert region data */
2453 /*lint -e{704} use shift for performance */
2454 pRgn->wtRegion.gain = (EAS_I16) (pWsmp->gain >> 16);
2455 pRgn->wtRegion.loopStart = pWsmp->loopStart;
2456 pRgn->wtRegion.loopEnd = (pWsmp->loopStart + pWsmp->loopLength);
2457 pRgn->wtRegion.tuning = pWsmp->fineTune -(pWsmp->unityNote * 100) + ConvertSampleRate(pWsmp->sampleRate);
2458 if (pWsmp->loopLength != 0)
2459 pRgn->wtRegion.region.keyGroupAndFlags |= REGION_FLAG_IS_LOOPED;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002460}
2461
2462/*----------------------------------------------------------------------------
2463 * Convert_art()
2464 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07002465 * Purpose:
The Android Open Source Project7df30102009-03-03 19:30:38 -08002466 * Convert articulation data from DLS to EAS
2467 *
2468 * Inputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002469 *
2470 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002471 * Outputs:
Dave Sparks56c99cd2009-08-24 17:35:45 -07002472 *
The Android Open Source Project7df30102009-03-03 19:30:38 -08002473 *
2474 *----------------------------------------------------------------------------
2475*/
2476static void Convert_art (SDLS_SYNTHESIZER_DATA *pDLSData, const S_DLS_ART_VALUES *pDLSArt, EAS_U16 artIndex)
2477{
Dave Sparks56c99cd2009-08-24 17:35:45 -07002478 S_DLS_ARTICULATION *pArt;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002479
Dave Sparks56c99cd2009-08-24 17:35:45 -07002480 /* setup pointers to data structures */
2481 pArt = &pDLSData->pDLS->pDLSArticulations[artIndex];
The Android Open Source Project7df30102009-03-03 19:30:38 -08002482
Dave Sparks56c99cd2009-08-24 17:35:45 -07002483 /* LFO parameters */
2484 pArt->modLFO.lfoFreq = ConvertLFOPhaseIncrement(pDLSArt->values[PARAM_MOD_LFO_FREQ]);
2485 pArt->modLFO.lfoDelay = -ConvertDelay(pDLSArt->values[PARAM_MOD_LFO_DELAY]);
2486 pArt->vibLFO.lfoFreq = ConvertLFOPhaseIncrement(pDLSArt->values[PARAM_VIB_LFO_FREQ]);
2487 pArt->vibLFO.lfoDelay = -ConvertDelay(pDLSArt->values[PARAM_VIB_LFO_DELAY]);
The Android Open Source Project7df30102009-03-03 19:30:38 -08002488
Dave Sparks56c99cd2009-08-24 17:35:45 -07002489 /* EG1 parameters */
2490 pArt->eg1.delayTime = ConvertDelay(pDLSArt->values[PARAM_VOL_EG_DELAY]);
2491 pArt->eg1.attackTime = pDLSArt->values[PARAM_VOL_EG_ATTACK];
2492 pArt->eg1.holdTime = pDLSArt->values[PARAM_VOL_EG_HOLD];
2493 pArt->eg1.decayTime = pDLSArt->values[PARAM_VOL_EG_DECAY];
2494 pArt->eg1.sustainLevel = ConvertSustain(pDLSArt->values[PARAM_VOL_EG_SUSTAIN]);
2495 pArt->eg1.releaseTime = ConvertRate(pDLSArt->values[PARAM_VOL_EG_RELEASE]);
2496 pArt->eg1.velToAttack = pDLSArt->values[PARAM_VOL_EG_VEL_TO_ATTACK];
2497 pArt->eg1.keyNumToDecay = pDLSArt->values[PARAM_VOL_EG_KEY_TO_DECAY];
2498 pArt->eg1.keyNumToHold = pDLSArt->values[PARAM_VOL_EG_KEY_TO_HOLD];
2499 pArt->eg1ShutdownTime = ConvertRate(pDLSArt->values[PARAM_VOL_EG_SHUTDOWN]);
The Android Open Source Project7df30102009-03-03 19:30:38 -08002500
Dave Sparks56c99cd2009-08-24 17:35:45 -07002501 /* EG2 parameters */
2502 pArt->eg2.delayTime = ConvertDelay(pDLSArt->values[PARAM_MOD_EG_DELAY]);
2503 pArt->eg2.attackTime = pDLSArt->values[PARAM_MOD_EG_ATTACK];
2504 pArt->eg2.holdTime = pDLSArt->values[PARAM_MOD_EG_HOLD];
2505 pArt->eg2.decayTime = pDLSArt->values[PARAM_MOD_EG_DECAY];
2506 pArt->eg2.sustainLevel = ConvertSustain(pDLSArt->values[PARAM_MOD_EG_SUSTAIN]);
2507 pArt->eg2.releaseTime = ConvertRate(pDLSArt->values[PARAM_MOD_EG_RELEASE]);
2508 pArt->eg2.velToAttack = pDLSArt->values[PARAM_MOD_EG_VEL_TO_ATTACK];
2509 pArt->eg2.keyNumToDecay = pDLSArt->values[PARAM_MOD_EG_KEY_TO_DECAY];
2510 pArt->eg2.keyNumToHold = pDLSArt->values[PARAM_MOD_EG_KEY_TO_HOLD];
The Android Open Source Project7df30102009-03-03 19:30:38 -08002511
Dave Sparks56c99cd2009-08-24 17:35:45 -07002512 /* filter parameters */
2513 pArt->filterCutoff = pDLSArt->values[PARAM_INITIAL_FC];
2514 pArt->filterQandFlags = ConvertQ(pDLSArt->values[PARAM_INITIAL_Q]);
2515 pArt->modLFOToFc = pDLSArt->values[PARAM_MOD_LFO_TO_FC];
2516 pArt->modLFOCC1ToFc = pDLSArt->values[PARAM_MOD_LFO_CC1_TO_FC];
2517 pArt->modLFOChanPressToFc = pDLSArt->values[PARAM_MOD_LFO_CHAN_PRESS_TO_FC];
2518 pArt->eg2ToFc = pDLSArt->values[PARAM_MOD_EG_TO_FC];
2519 pArt->velToFc = pDLSArt->values[PARAM_VEL_TO_FC];
2520 pArt->keyNumToFc = pDLSArt->values[PARAM_KEYNUM_TO_FC];
The Android Open Source Project7df30102009-03-03 19:30:38 -08002521
Dave Sparks56c99cd2009-08-24 17:35:45 -07002522 /* gain parameters */
2523 pArt->modLFOToGain = pDLSArt->values[PARAM_MOD_LFO_TO_GAIN];
2524 pArt->modLFOCC1ToGain = pDLSArt->values[PARAM_MOD_LFO_CC1_TO_GAIN];
2525 pArt->modLFOChanPressToGain = pDLSArt->values[PARAM_MOD_LFO_CHAN_PRESS_TO_GAIN];
The Android Open Source Project7df30102009-03-03 19:30:38 -08002526
Dave Sparks56c99cd2009-08-24 17:35:45 -07002527 /* pitch parameters */
2528 pArt->tuning = pDLSArt->values[PARAM_TUNING];
2529 pArt->keyNumToPitch = pDLSArt->values[PARAM_KEYNUM_TO_PITCH];
2530 pArt->vibLFOToPitch = pDLSArt->values[PARAM_VIB_LFO_TO_PITCH];
2531 pArt->vibLFOCC1ToPitch = pDLSArt->values[PARAM_VIB_LFO_CC1_TO_PITCH];
2532 pArt->vibLFOChanPressToPitch = pDLSArt->values[PARAM_VIB_LFO_CHAN_PRESS_TO_PITCH];
2533 pArt->modLFOToPitch = pDLSArt->values[PARAM_MOD_LFO_TO_PITCH];
2534 pArt->modLFOCC1ToPitch = pDLSArt->values[PARAM_MOD_LFO_CC1_TO_PITCH];
2535 pArt->modLFOChanPressToPitch = pDLSArt->values[PARAM_MOD_LFO_CHAN_PRESS_TO_PITCH];
2536 pArt->eg2ToPitch = pDLSArt->values[PARAM_MOD_EG_TO_PITCH];
The Android Open Source Project7df30102009-03-03 19:30:38 -08002537
Dave Sparks56c99cd2009-08-24 17:35:45 -07002538 /* output parameters */
2539 pArt->pan = ConvertPan(pDLSArt->values[PARAM_DEFAULT_PAN]);
The Android Open Source Project7df30102009-03-03 19:30:38 -08002540
Dave Sparks56c99cd2009-08-24 17:35:45 -07002541 if (pDLSArt->values[PARAM_VEL_TO_GAIN] != 0)
2542 pArt->filterQandFlags |= FLAG_DLS_VELOCITY_SENSITIVE;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002543
Dave Sparks56c99cd2009-08-24 17:35:45 -07002544#ifdef _REVERB
2545 pArt->reverbSend = pDLSArt->values[PARAM_DEFAULT_REVERB_SEND];
2546 pArt->cc91ToReverbSend = pDLSArt->values[PARAM_MIDI_CC91_TO_REVERB_SEND];
The Android Open Source Project7df30102009-03-03 19:30:38 -08002547#endif
2548
2549#ifdef _CHORUS
Dave Sparks56c99cd2009-08-24 17:35:45 -07002550 pArt->chorusSend = pDLSArt->values[PARAM_DEFAULT_CHORUS_SEND];
2551 pArt->cc93ToChorusSend = pDLSArt->values[PARAM_MIDI_CC93_TO_CHORUS_SEND];
2552#endif
The Android Open Source Project7df30102009-03-03 19:30:38 -08002553}
2554
2555/*----------------------------------------------------------------------------
2556 * ConvertSampleRate()
2557 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07002558 * Purpose:
The Android Open Source Project7df30102009-03-03 19:30:38 -08002559 *
Dave Sparks56c99cd2009-08-24 17:35:45 -07002560 * Inputs:
The Android Open Source Project7df30102009-03-03 19:30:38 -08002561 *
2562 * Outputs:
2563 *
2564 * Side Effects:
2565 *----------------------------------------------------------------------------
2566*/
2567static EAS_I16 ConvertSampleRate (EAS_U32 sampleRate)
2568{
Dave Sparks56c99cd2009-08-24 17:35:45 -07002569 return (EAS_I16) (1200.0 * log10((double) sampleRate / (double) outputSampleRate) / log10(2.0));
The Android Open Source Project7df30102009-03-03 19:30:38 -08002570}
2571
2572/*----------------------------------------------------------------------------
2573 * ConvertSustainEG2()
2574 *----------------------------------------------------------------------------
2575 * Convert sustain level to pitch/Fc multipler for EG2
2576 *----------------------------------------------------------------------------
2577*/
2578static EAS_I16 ConvertSustain (EAS_I32 sustain)
2579{
Dave Sparks56c99cd2009-08-24 17:35:45 -07002580 /* check for sustain level of zero */
2581 if (sustain == 0)
2582 return 0;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002583
Dave Sparks56c99cd2009-08-24 17:35:45 -07002584 /* convert to log2 factor */
2585 /*lint -e{704} use shift for performance */
2586 sustain = (sustain * SUSTAIN_LINEAR_CONVERSION_FACTOR) >> 15;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002587
Dave Sparks56c99cd2009-08-24 17:35:45 -07002588 if (sustain > SYNTH_FULL_SCALE_EG1_GAIN)
2589 return SYNTH_FULL_SCALE_EG1_GAIN;
2590 return (EAS_I16) sustain;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002591}
2592
2593/*----------------------------------------------------------------------------
2594 * ConvertDelay ()
2595 *----------------------------------------------------------------------------
2596 * Converts timecents to frame count. Used for LFO and envelope
2597 * delay times.
2598 *----------------------------------------------------------------------------
2599*/
2600EAS_I16 ConvertDelay (EAS_I32 timeCents)
2601{
Dave Sparks56c99cd2009-08-24 17:35:45 -07002602 EAS_I32 temp;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002603
Dave Sparks56c99cd2009-08-24 17:35:45 -07002604 if (timeCents == ZERO_TIME_IN_CENTS)
2605 return 0;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002606
Dave Sparks56c99cd2009-08-24 17:35:45 -07002607 /* divide time by secs per frame to get number of frames */
2608 temp = timeCents - dlsRateConvert;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002609
Dave Sparks56c99cd2009-08-24 17:35:45 -07002610 /* convert from time cents to 10-bit fraction */
2611 temp = FMUL_15x15(temp, TIME_CENTS_TO_LOG2);
The Android Open Source Project7df30102009-03-03 19:30:38 -08002612
Dave Sparks56c99cd2009-08-24 17:35:45 -07002613 /* convert to frame count */
2614 temp = EAS_LogToLinear16(temp - (15 << 10));
2615
2616 if (temp < SYNTH_FULL_SCALE_EG1_GAIN)
2617 return (EAS_I16) temp;
2618 return SYNTH_FULL_SCALE_EG1_GAIN;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002619}
2620
2621/*----------------------------------------------------------------------------
2622 * ConvertRate ()
2623 *----------------------------------------------------------------------------
2624 * Convert timecents to rate
2625 *----------------------------------------------------------------------------
2626*/
2627EAS_I16 ConvertRate (EAS_I32 timeCents)
2628{
Dave Sparks56c99cd2009-08-24 17:35:45 -07002629 EAS_I32 temp;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002630
Dave Sparks56c99cd2009-08-24 17:35:45 -07002631 if (timeCents == ZERO_TIME_IN_CENTS)
2632 return SYNTH_FULL_SCALE_EG1_GAIN;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002633
Dave Sparks56c99cd2009-08-24 17:35:45 -07002634 /* divide frame rate by time in log domain to get rate */
2635 temp = dlsRateConvert - timeCents;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002636
2637#if 1
Dave Sparks56c99cd2009-08-24 17:35:45 -07002638 temp = EAS_Calculate2toX(temp);
The Android Open Source Project7df30102009-03-03 19:30:38 -08002639#else
Dave Sparks56c99cd2009-08-24 17:35:45 -07002640 /* convert from time cents to 10-bit fraction */
2641 temp = FMUL_15x15(temp, TIME_CENTS_TO_LOG2);
2642
2643 /* convert to rate */
2644 temp = EAS_LogToLinear16(temp);
The Android Open Source Project7df30102009-03-03 19:30:38 -08002645#endif
2646
Dave Sparks56c99cd2009-08-24 17:35:45 -07002647 if (temp < SYNTH_FULL_SCALE_EG1_GAIN)
2648 return (EAS_I16) temp;
2649 return SYNTH_FULL_SCALE_EG1_GAIN;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002650}
2651
2652
2653/*----------------------------------------------------------------------------
2654 * ConvertLFOPhaseIncrement()
2655 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07002656 * Purpose:
The Android Open Source Project7df30102009-03-03 19:30:38 -08002657 *
Dave Sparks56c99cd2009-08-24 17:35:45 -07002658 * Inputs:
The Android Open Source Project7df30102009-03-03 19:30:38 -08002659 *
2660 * Outputs:
2661 *
2662 * Side Effects:
2663 *----------------------------------------------------------------------------
2664*/
2665static EAS_I16 ConvertLFOPhaseIncrement (EAS_I32 pitchCents)
2666{
The Android Open Source Project7df30102009-03-03 19:30:38 -08002667
Dave Sparks56c99cd2009-08-24 17:35:45 -07002668 /* check range */
2669 if (pitchCents > MAX_LFO_FREQUENCY_IN_PITCHCENTS)
2670 pitchCents = MAX_LFO_FREQUENCY_IN_PITCHCENTS;
2671 if (pitchCents < MIN_LFO_FREQUENCY_IN_PITCHCENTS)
2672 pitchCents = MIN_LFO_FREQUENCY_IN_PITCHCENTS;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002673
Dave Sparks56c99cd2009-08-24 17:35:45 -07002674 /* double the rate and divide by frame rate by subtracting in log domain */
2675 pitchCents = pitchCents - dlsLFOFrequencyConvert;
2676
2677 /* convert to phase increment */
2678 return (EAS_I16) EAS_Calculate2toX(pitchCents);
The Android Open Source Project7df30102009-03-03 19:30:38 -08002679}
2680
2681/*----------------------------------------------------------------------------
2682 * ConvertPan()
2683 *----------------------------------------------------------------------------
Dave Sparks56c99cd2009-08-24 17:35:45 -07002684 * Purpose:
The Android Open Source Project7df30102009-03-03 19:30:38 -08002685 *
Dave Sparks56c99cd2009-08-24 17:35:45 -07002686 * Inputs:
The Android Open Source Project7df30102009-03-03 19:30:38 -08002687 *
2688 * Outputs:
2689 *
2690 * Side Effects:
2691 *----------------------------------------------------------------------------
2692*/
2693static EAS_I8 ConvertPan (EAS_I32 pan)
2694{
Dave Sparks56c99cd2009-08-24 17:35:45 -07002695
2696 /* multiply by conversion factor */
2697 pan = FMUL_15x15 (PAN_CONVERSION_FACTOR, pan);
2698 if (pan < MIN_PAN_VALUE)
2699 return MIN_PAN_VALUE;
2700 if (pan > MAX_PAN_VALUE)
2701 return MAX_PAN_VALUE;
2702 return (EAS_I8) pan;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002703}
2704
2705/*----------------------------------------------------------------------------
2706 * ConvertQ()
2707 *----------------------------------------------------------------------------
2708 * Convert the DLS filter resonance to an index value used by the synth
2709 * that accesses tables of coefficients based on the Q.
2710 *----------------------------------------------------------------------------
2711*/
2712static EAS_U8 ConvertQ (EAS_I32 q)
2713{
2714
Dave Sparks56c99cd2009-08-24 17:35:45 -07002715 /* apply limits */
2716 if (q <= 0)
2717 return 0;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002718
Dave Sparks56c99cd2009-08-24 17:35:45 -07002719 /* convert to table index */
2720 /*lint -e{704} use shift for performance */
2721 q = (FILTER_Q_CONVERSION_FACTOR * q + 0x4000) >> 15;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002722
Dave Sparks56c99cd2009-08-24 17:35:45 -07002723 /* apply upper limit */
2724 if (q >= FILTER_RESONANCE_NUM_ENTRIES)
2725 q = FILTER_RESONANCE_NUM_ENTRIES - 1;
2726 return (EAS_U8) q;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002727}
2728
2729#ifdef _DEBUG_DLS
2730/*----------------------------------------------------------------------------
2731 * DumpDLS()
2732 *----------------------------------------------------------------------------
2733*/
2734static void DumpDLS (S_EAS *pEAS)
2735{
Dave Sparks56c99cd2009-08-24 17:35:45 -07002736 S_DLS_ARTICULATION *pArt;
2737 S_DLS_REGION *pRegion;
2738 EAS_INT i;
2739 EAS_INT j;
The Android Open Source Project7df30102009-03-03 19:30:38 -08002740
Dave Sparks56c99cd2009-08-24 17:35:45 -07002741 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000022 , pEAS->numPrograms);
2742 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000023 , pEAS->numWTRegions);
2743 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000024 , pEAS->numDLSArticulations);
2744 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000025 , pEAS->numSamples);
The Android Open Source Project7df30102009-03-03 19:30:38 -08002745
Dave Sparks56c99cd2009-08-24 17:35:45 -07002746 /* dump the instruments */
2747 for (i = 0; i < pEAS->numPrograms; i++)
2748 {
2749 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000026 ,
2750 pEAS->pPrograms[i].locale >> 16,
2751 (pEAS->pPrograms[i].locale >> 8) & 0x7f,
2752 pEAS->pPrograms[i].locale & 0x7f);
The Android Open Source Project7df30102009-03-03 19:30:38 -08002753
Dave Sparks56c99cd2009-08-24 17:35:45 -07002754 for (j = pEAS->pPrograms[i].regionIndex; ; j++)
2755 {
2756 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000027 , j);
2757 pRegion = &pEAS->pWTRegions[j];
2758 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000028 , pRegion->gain);
2759 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000029 , pRegion->region.rangeLow, pRegion->region.rangeHigh);
2760 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x0000002a , pRegion->region.keyGroupAndFlags);
2761 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x0000002b , pRegion->loopStart);
2762 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x0000002c , pRegion->loopEnd);
2763 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x0000002d , pRegion->tuning);
2764 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x0000002e , pRegion->artIndex);
2765 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x0000002f , pRegion->waveIndex);
The Android Open Source Project7df30102009-03-03 19:30:38 -08002766
Dave Sparks56c99cd2009-08-24 17:35:45 -07002767 if (pRegion->region.keyGroupAndFlags & REGION_FLAG_LAST_REGION)
2768 break;
2769 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08002770
Dave Sparks56c99cd2009-08-24 17:35:45 -07002771 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08002772
Dave Sparks56c99cd2009-08-24 17:35:45 -07002773 /* dump the articulation data */
2774 for (i = 0; i < pEAS->numDLSArticulations; i++)
2775 {
2776 /* articulation data */
2777 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000030 , i);
2778 pArt = &pEAS->pDLSArticulations[i];
2779 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000031 , pArt->m_nEG2toFilterDepth);
2780 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000032 , pArt->m_nEG2toPitchDepth);
2781 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000033 , pArt->m_nFilterCutoffFrequency);
2782 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000034 , pArt->m_nFilterResonance);
2783 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000035 , pArt->m_nLFOAmplitudeDepth);
2784 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000036 , pArt->m_nLFODelayTime);
2785 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000037 , pArt->m_nLFOFrequency);
2786 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000038 , pArt->m_nLFOPitchDepth);
2787 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000039 , pArt->m_nPan);
The Android Open Source Project7df30102009-03-03 19:30:38 -08002788
Dave Sparks56c99cd2009-08-24 17:35:45 -07002789 /* EG1 data */
2790 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x0000003a , pArt->m_sEG1.m_nAttack);
2791 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x0000003b , pArt->m_sEG1.m_nDecay);
2792 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x0000003c , pArt->m_sEG1.m_nSustain);
2793 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x0000003d , pArt->m_sEG1.m_nRelease);
The Android Open Source Project7df30102009-03-03 19:30:38 -08002794
Dave Sparks56c99cd2009-08-24 17:35:45 -07002795 /* EG2 data */
2796 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x0000003e , pArt->m_sEG2.m_nAttack);
2797 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x0000003f , pArt->m_sEG2.m_nDecay);
2798 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000040 , pArt->m_sEG2.m_nSustain);
2799 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000041 , pArt->m_sEG2.m_nRelease);
2800
2801 }
2802
2803 /* dump the waves */
2804 for (i = 0; i < pEAS->numSamples; i++)
2805 {
2806 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000042 , i);
2807 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000043 , pEAS->pSampleLen[i]);
2808 EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0x19299ed4, 0x00000044 , pEAS->ppSamples[i]);
2809 }
The Android Open Source Project7df30102009-03-03 19:30:38 -08002810
2811}
2812#endif
2813