The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1 | /*---------------------------------------------------------------------------- |
| 2 | * |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 3 | * File: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 4 | * eas_mdls.c |
| 5 | * |
| 6 | * Contents and purpose: |
| 7 | * This file contains DLS to EAS converter. |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 8 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 9 | * 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 Jia | 56d1532 | 2017-02-07 10:35:31 -0800 | [diff] [blame] | 117 | #include "log/log.h" |
| 118 | |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 119 | #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.kim | 9258597 | 2019-02-12 19:13:29 +0900 | [diff] [blame] | 126 | #include <string.h> |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 127 | |
| 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 */ |
| 130 | extern double log10(double x); |
| 131 | |
| 132 | /*------------------------------------ |
| 133 | * defines |
| 134 | *------------------------------------ |
| 135 | */ |
| 136 | |
| 137 | // #define _DEBUG_DLS |
| 138 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 139 | #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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 144 | |
Wei Jia | 163e00f | 2015-08-20 16:03:14 -0700 | [diff] [blame] | 145 | #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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 153 | /*------------------------------------ |
| 154 | * typedefs |
| 155 | *------------------------------------ |
| 156 | */ |
| 157 | |
| 158 | /* offsets to articulation data */ |
| 159 | typedef enum |
| 160 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 161 | PARAM_MODIFIED = 0, |
| 162 | PARAM_MOD_LFO_FREQ, |
| 163 | PARAM_MOD_LFO_DELAY, |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 164 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 165 | PARAM_VIB_LFO_FREQ, |
| 166 | PARAM_VIB_LFO_DELAY, |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 167 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 168 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 178 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 179 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 188 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 189 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 197 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 198 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 219 | } E_ART_INDEX; |
| 220 | |
| 221 | /* temporary data structure combining region, articulation, and envelope data */ |
| 222 | typedef struct s_art_dls_tag |
| 223 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 224 | EAS_I16 values[PARAM_TABLE_SIZE]; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 225 | } S_DLS_ART_VALUES; |
| 226 | |
| 227 | /* temporary data structure for wlnk chunk data */ |
| 228 | typedef struct |
| 229 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 230 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 237 | } S_WSMP_DATA; |
| 238 | |
| 239 | /* temporary data structure used while parsing a DLS file */ |
| 240 | typedef struct |
| 241 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 242 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 254 | } SDLS_SYNTHESIZER_DATA; |
| 255 | |
| 256 | /* connection lookup table */ |
| 257 | typedef struct s_connection_tag |
| 258 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 259 | EAS_U16 source; |
| 260 | EAS_U16 control; |
| 261 | EAS_U16 destination; |
| 262 | EAS_U16 connection; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 263 | } S_CONNECTION; |
| 264 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 265 | static const S_CONNECTION connTable[] = |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 266 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 267 | { 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 269 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 270 | { 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 323 | }; |
| 324 | #define ENTRIES_IN_CONN_TABLE (sizeof(connTable)/sizeof(S_CONNECTION)) |
| 325 | |
| 326 | static const S_DLS_ART_VALUES defaultArt = |
| 327 | { |
Aurimas Liutikas | 957372b | 2016-04-19 13:17:30 -0700 | [diff] [blame] | 328 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 329 | 0, /* not modified */ |
| 330 | -851, /* Mod LFO frequency: 5 Hz */ |
| 331 | -7973, /* Mod LFO delay: 10 milliseconds */ |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 332 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 333 | -851, /* Vib LFO frequency: 5 Hz */ |
| 334 | -7973, /* Vib LFO delay: 10 milliseconds */ |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 335 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 336 | -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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 346 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 347 | -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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 356 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 357 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 365 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 366 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 370 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 371 | 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 Liutikas | 957372b | 2016-04-19 13:17:30 -0700 | [diff] [blame] | 386 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 387 | }; |
| 388 | |
| 389 | /*------------------------------------ |
| 390 | * local variables |
| 391 | *------------------------------------ |
| 392 | */ |
| 393 | |
| 394 | #if defined(_8_BIT_SAMPLES) |
| 395 | static const EAS_INT bitDepth = 8; |
| 396 | #elif defined(_16_BIT_SAMPLES) |
| 397 | static const EAS_INT bitDepth = 16; |
| 398 | #else |
| 399 | #error "Must define _8_BIT_SAMPLES or _16_BIT_SAMPLES" |
| 400 | #endif |
| 401 | |
| 402 | static const EAS_U32 outputSampleRate = _OUTPUT_SAMPLE_RATE; |
| 403 | static const EAS_I32 dlsRateConvert = DLS_RATE_CONVERT; |
| 404 | static const EAS_I32 dlsLFOFrequencyConvert = DLS_LFO_FREQUENCY_CONVERT; |
| 405 | |
| 406 | /*------------------------------------ |
| 407 | * inline functions |
| 408 | *------------------------------------ |
| 409 | */ |
| 410 | EAS_INLINE void *PtrOfs (void *p, EAS_I32 offset) |
| 411 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 412 | return (void*) (((EAS_U8*) p) + offset); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | /*------------------------------------ |
| 416 | * prototypes |
| 417 | *------------------------------------ |
| 418 | */ |
| 419 | static EAS_RESULT NextChunk (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 *pPos, EAS_U32 *pChunkType, EAS_I32 *pSize); |
| 420 | static EAS_RESULT Parse_ptbl (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 wsmpPos, EAS_I32 wsmpSize); |
| 421 | static EAS_RESULT Parse_wave (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_U16 waveIndex); |
| 422 | static EAS_RESULT Parse_wsmp (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_WSMP_DATA *p); |
| 423 | static EAS_RESULT Parse_fmt (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_WSMP_DATA *p); |
Wei Jia | 9cf7e87 | 2015-08-21 13:41:42 -0700 | [diff] [blame] | 424 | static 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 425 | static EAS_RESULT Parse_lins(SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size); |
| 426 | static EAS_RESULT Parse_ins (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size); |
| 427 | static EAS_RESULT Parse_insh (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_U32 *pRgnCount, EAS_U32 *pLocale); |
| 428 | static EAS_RESULT Parse_lrgn (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, EAS_U16 artIndex, EAS_U32 numRegions); |
| 429 | static EAS_RESULT Parse_rgn (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, EAS_U16 artIndex); |
| 430 | static EAS_RESULT Parse_rgnh (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_DLS_REGION *pRgn); |
| 431 | static EAS_RESULT Parse_lart (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, S_DLS_ART_VALUES *pArt); |
| 432 | static EAS_RESULT Parse_art (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_DLS_ART_VALUES *pArt); |
| 433 | static EAS_RESULT Parse_wlnk (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_U32 *pWaveIndex); |
| 434 | static EAS_RESULT Parse_cdl (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 size, EAS_U32 *pValue); |
| 435 | static void Convert_rgn (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_U16 regionIndex, EAS_U16 artIndex, EAS_U16 waveIndex, S_WSMP_DATA *pWsmp); |
| 436 | static void Convert_art (SDLS_SYNTHESIZER_DATA *pDLSData, const S_DLS_ART_VALUES *pDLSArt, EAS_U16 artIndex); |
| 437 | static EAS_I16 ConvertSampleRate (EAS_U32 sampleRate); |
| 438 | static EAS_I16 ConvertSustain (EAS_I32 sustain); |
| 439 | static EAS_I16 ConvertLFOPhaseIncrement (EAS_I32 pitchCents); |
| 440 | static EAS_I8 ConvertPan (EAS_I32 pan); |
| 441 | static EAS_U8 ConvertQ (EAS_I32 q); |
| 442 | |
| 443 | #ifdef _DEBUG_DLS |
| 444 | static void DumpDLS (S_EAS *pEAS); |
| 445 | #endif |
| 446 | |
| 447 | |
| 448 | /*---------------------------------------------------------------------------- |
| 449 | * DLSParser () |
| 450 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 451 | * Purpose: |
| 452 | * |
| 453 | * Inputs: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 454 | * pEASData - pointer to over EAS data instance |
| 455 | * fileHandle - file handle for input file |
| 456 | * offset - offset into file where DLS data starts |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 457 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 458 | * Outputs: |
| 459 | * EAS_RESULT |
| 460 | * ppEAS - address of pointer to alternate EAS wavetable |
| 461 | * |
| 462 | *---------------------------------------------------------------------------- |
| 463 | */ |
| 464 | EAS_RESULT DLSParser (EAS_HW_DATA_HANDLE hwInstData, EAS_FILE_HANDLE fileHandle, EAS_I32 offset, EAS_DLSLIB_HANDLE *ppDLS) |
| 465 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 466 | EAS_RESULT result; |
| 467 | SDLS_SYNTHESIZER_DATA dls; |
| 468 | EAS_U32 temp; |
Marco Nelissen | 5eb6a7e | 2020-03-26 17:17:06 -0700 | [diff] [blame] | 469 | uint32_t chunk_type; |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 470 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 485 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 486 | /* zero counts and pointers */ |
| 487 | EAS_HWMemSet(&dls, 0, sizeof(dls)); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 488 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 489 | /* save file handle and hwInstData to save copying pointers around */ |
| 490 | dls.hwInstData = hwInstData; |
| 491 | dls.fileHandle = fileHandle; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 492 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 493 | /* NULL return value in case of error */ |
| 494 | *ppDLS = NULL; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 495 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 496 | /* 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 Nelissen | 5eb6a7e | 2020-03-26 17:17:06 -0700 | [diff] [blame] | 499 | if ((result = EAS_HWReadFile(dls.hwInstData, dls.fileHandle, &chunk_type, sizeof(chunk_type), &size)) != EAS_SUCCESS) |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 500 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 501 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 502 | /* check for processor endian-ness */ |
Marco Nelissen | 5eb6a7e | 2020-03-26 17:17:06 -0700 | [diff] [blame] | 503 | dls.bigEndian = (chunk_type == CHUNK_RIFF); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 504 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 505 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 514 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 515 | /* no instrument or wavepool chunks */ |
| 516 | linsSize = wvplSize = ptblSize = linsPos = wvplPos = ptblPos = 0; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 517 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 518 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 524 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 525 | /* get the next chunk type */ |
| 526 | if ((result = NextChunk(&dls, &pos, &temp, &size)) != EAS_SUCCESS) |
| 527 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 528 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 529 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 538 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 539 | case CHUNK_LINS: |
| 540 | linsPos = chunkPos + 12; |
| 541 | linsSize = size - 4; |
| 542 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 543 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 544 | case CHUNK_WVPL: |
| 545 | wvplPos = chunkPos + 12; |
| 546 | wvplSize = size - 4; |
| 547 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 548 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 549 | case CHUNK_PTBL: |
| 550 | ptblPos = chunkPos + 8; |
| 551 | ptblSize = size - 4; |
| 552 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 553 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 554 | default: |
| 555 | break; |
| 556 | } |
| 557 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 558 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 559 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 565 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 566 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 572 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 573 | /* must have a ptbl chunk */ |
Aurimas Liutikas | 957372b | 2016-04-19 13:17:30 -0700 | [diff] [blame] | 574 | if ((ptblSize == 0) || (ptblSize > (EAS_I32) (DLS_MAX_WAVE_COUNT * sizeof(POOLCUE) + sizeof(POOLTABLE)))) |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 575 | { |
| 576 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "No ptbl chunk found"); */ } |
| 577 | return EAS_ERROR_UNRECOGNIZED_FORMAT; |
| 578 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 579 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 580 | /* pre-parse the wave pool chunk */ |
| 581 | if ((result = Parse_ptbl(&dls, ptblPos, wvplPos, wvplSize)) != EAS_SUCCESS) |
| 582 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 583 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 584 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 590 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 591 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 599 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 600 | /* pre-parse the lins chunk */ |
| 601 | result = Parse_lins(&dls, linsPos, linsSize); |
| 602 | if (result == EAS_SUCCESS) |
| 603 | { |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 604 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 605 | /* 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 Nelissen | 2815be2 | 2017-11-06 12:18:41 -0800 | [diff] [blame] | 609 | EAS_HWFree(dls.hwInstData, dls.wsmpData); |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 610 | return EAS_ERROR_FILE_FORMAT; |
| 611 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 612 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 613 | /* 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 Nelissen | 2815be2 | 2017-11-06 12:18:41 -0800 | [diff] [blame] | 617 | EAS_HWFree(dls.hwInstData, dls.wsmpData); |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 618 | return EAS_ERROR_FILE_FORMAT; |
| 619 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 620 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 621 | /* 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 Nelissen | 2815be2 | 2017-11-06 12:18:41 -0800 | [diff] [blame] | 625 | EAS_HWFree(dls.hwInstData, dls.wsmpData); |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 626 | return EAS_ERROR_FILE_FORMAT; |
| 627 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 628 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 629 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 632 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 633 | /* calculate size of region pool */ |
| 634 | rgnPoolSize = (EAS_I32) (sizeof(S_DLS_REGION) * dls.regionCount); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 635 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 636 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 639 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 640 | /* calculate size of wave length and offset arrays */ |
| 641 | waveLenSize = (EAS_I32) (dls.waveCount * sizeof(EAS_U32)); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 642 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 643 | /* 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 Nelissen | 2815be2 | 2017-11-06 12:18:41 -0800 | [diff] [blame] | 646 | EAS_HWFree(dls.hwInstData, dls.wsmpData); |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 647 | return EAS_ERROR_FILE_FORMAT; |
| 648 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 649 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 650 | /* 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 Nelissen | 2815be2 | 2017-11-06 12:18:41 -0800 | [diff] [blame] | 655 | EAS_HWFree(dls.hwInstData, dls.wsmpData); |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 656 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 661 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 662 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 666 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 667 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 671 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 672 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 676 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 677 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 681 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 682 | /* 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 Nelissen | 3d9a1f5 | 2015-08-21 08:54:54 -0700 | [diff] [blame] | 697 | if (dls.pDLS) { |
| 698 | Convert_art(&dls, &defaultArt, 0); |
| 699 | dls.artCount = 1; |
| 700 | } |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 701 | |
| 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 715 | #ifdef _DEBUG_DLS |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 716 | DumpDLS(dls.pDLS); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 717 | #endif |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 718 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 719 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 720 | /* something went wrong, deallocate the EAS collection */ |
| 721 | else |
| 722 | DLSCleanup(dls.hwInstData, dls.pDLS); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 723 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 724 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | /*---------------------------------------------------------------------------- |
| 728 | * DLSCleanup () |
| 729 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 730 | * Purpose: |
| 731 | * |
| 732 | * Inputs: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 733 | * pEASData - pointer to over EAS data instance |
| 734 | * pEAS - pointer to alternate EAS wavetable |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 735 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 736 | * Outputs: |
| 737 | * EAS_RESULT |
| 738 | * |
| 739 | *---------------------------------------------------------------------------- |
| 740 | */ |
| 741 | EAS_RESULT DLSCleanup (EAS_HW_DATA_HANDLE hwInstData, S_DLS *pDLS) |
| 742 | { |
| 743 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 744 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | /*---------------------------------------------------------------------------- |
| 757 | * DLSAddRef () |
| 758 | *---------------------------------------------------------------------------- |
| 759 | * Increment reference count |
| 760 | *---------------------------------------------------------------------------- |
| 761 | */ |
| 762 | void DLSAddRef (S_DLS *pDLS) |
| 763 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 764 | if (pDLS) |
| 765 | pDLS->refCount++; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | /*---------------------------------------------------------------------------- |
| 769 | * NextChunk () |
| 770 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 771 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 772 | * Returns the type and size of the next chunk in the file |
| 773 | * |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 774 | * Inputs: |
| 775 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 776 | * Outputs: |
| 777 | * |
| 778 | * Side Effects: |
| 779 | *---------------------------------------------------------------------------- |
| 780 | */ |
| 781 | static EAS_RESULT NextChunk (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 *pPos, EAS_U32 *pChunkType, EAS_I32 *pSize) |
| 782 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 783 | EAS_RESULT result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 784 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 785 | /* seek to start of chunk */ |
| 786 | if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, *pPos)) != EAS_SUCCESS) |
| 787 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 788 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 789 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 792 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 793 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 796 | |
Marco Nelissen | f01750a | 2017-05-11 14:43:54 -0700 | [diff] [blame] | 797 | if (*pSize < 0) { |
| 798 | ALOGE("b/37093318"); |
| 799 | return EAS_ERROR_FILE_FORMAT; |
| 800 | } |
| 801 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 802 | /* get form type for RIFF and LIST types */ |
| 803 | if ((*pChunkType == CHUNK_RIFF) || (*pChunkType == CHUNK_LIST)) |
| 804 | { |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 805 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 806 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 809 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 810 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 811 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 812 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | /*---------------------------------------------------------------------------- |
| 823 | * Parse_ptbl () |
| 824 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 825 | * Purpose: |
| 826 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 827 | * |
| 828 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 829 | * |
| 830 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 831 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 832 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 833 | * |
| 834 | *---------------------------------------------------------------------------- |
| 835 | */ |
| 836 | static EAS_RESULT Parse_ptbl (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 wtblPos, EAS_I32 wtblSize) |
| 837 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 838 | EAS_RESULT result; |
| 839 | EAS_U32 temp; |
| 840 | EAS_FILE_HANDLE tempFile; |
| 841 | EAS_U16 waveIndex; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 842 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 843 | /* seek to start of chunk */ |
| 844 | if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS) |
| 845 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 846 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 847 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 850 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 851 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 854 | |
Harish Mahendrakar | c049c14 | 2020-04-30 04:24:53 +0530 | [diff] [blame] | 855 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 864 | #if 0 |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 865 | /* just need the wave count on the first pass */ |
| 866 | if (!pDLSData->pDLS) |
| 867 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 868 | #endif |
| 869 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 870 | /* open duplicate file handle */ |
| 871 | if ((result = EAS_HWDupHandle(pDLSData->hwInstData, pDLSData->fileHandle, &tempFile)) != EAS_SUCCESS) |
| 872 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 873 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 874 | /* read to end of chunk */ |
| 875 | for (waveIndex = 0; waveIndex < pDLSData->waveCount; waveIndex++) |
| 876 | { |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 877 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 878 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 887 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 888 | /* parse the wave */ |
| 889 | if ((result = Parse_wave(pDLSData, wtblPos +(EAS_I32) temp, waveIndex)) != EAS_SUCCESS) |
| 890 | return result; |
| 891 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 892 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 893 | /* close the temporary handle and return */ |
| 894 | EAS_HWCloseFile(pDLSData->hwInstData, tempFile); |
| 895 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | /*---------------------------------------------------------------------------- |
| 899 | * Parse_wave () |
| 900 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 901 | * Purpose: |
| 902 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 903 | * |
| 904 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 905 | * |
| 906 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 907 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 908 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 909 | * |
| 910 | *---------------------------------------------------------------------------- |
| 911 | */ |
| 912 | static EAS_RESULT Parse_wave (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_U16 waveIndex) |
| 913 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 914 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 926 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 927 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 931 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 932 | /* get the chunk type */ |
| 933 | if ((result = NextChunk(pDLSData, &pos, &temp, &size)) != EAS_SUCCESS) |
| 934 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 935 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 936 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 942 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 943 | /* read to end of chunk */ |
| 944 | pos = chunkPos; |
| 945 | endChunk = pos + size; |
| 946 | while (pos < endChunk) |
| 947 | { |
| 948 | chunkPos = pos; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 949 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 950 | /* get the chunk type */ |
| 951 | if ((result = NextChunk(pDLSData, &pos, &temp, &size)) != EAS_SUCCESS) |
| 952 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 953 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 954 | /* parse useful chunks */ |
| 955 | switch (temp) |
| 956 | { |
| 957 | case CHUNK_WSMP: |
| 958 | wsmpPos = chunkPos + 8; |
| 959 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 960 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 961 | case CHUNK_FMT: |
| 962 | fmtPos = chunkPos + 8; |
| 963 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 964 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 965 | case CHUNK_DATA: |
| 966 | dataPos = chunkPos + 8; |
| 967 | dataSize = size; |
| 968 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 969 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 970 | default: |
| 971 | break; |
| 972 | } |
| 973 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 974 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 975 | // limit to reasonable size |
Eric Laurent | 2d7f8e1 | 2015-05-14 09:10:40 -0700 | [diff] [blame] | 976 | if (dataSize < 0 || dataSize > MAX_DLS_WAVE_SIZE) |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 977 | { |
| 978 | return EAS_ERROR_SOUND_LIBRARY; |
| 979 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 980 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 981 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 986 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 987 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 993 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 994 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1000 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1001 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1007 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1008 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1014 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1015 | /* parse the fmt chunk */ |
| 1016 | if ((result = Parse_fmt(pDLSData, fmtPos, p)) != EAS_SUCCESS) |
| 1017 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1018 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1019 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1028 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1029 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1041 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1042 | 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 Jia | 9cf7e87 | 2015-08-21 13:41:42 -0700 | [diff] [blame] | 1061 | pSample = (EAS_U8*)pDLSData->pDLS->pDLSSamples + pDLSData->wavePoolOffset; |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1062 | 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 Jia | 9cf7e87 | 2015-08-21 13:41:42 -0700 | [diff] [blame] | 1071 | if ((result = Parse_data(pDLSData, dataPos, dataSize, p, pSample, (EAS_U32)size)) != EAS_SUCCESS) |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1072 | return result; |
| 1073 | |
| 1074 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | /*---------------------------------------------------------------------------- |
| 1078 | * Parse_wsmp () |
| 1079 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1080 | * Purpose: |
| 1081 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1082 | * |
| 1083 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1084 | * |
| 1085 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1086 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1087 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1088 | * |
| 1089 | *---------------------------------------------------------------------------- |
| 1090 | */ |
| 1091 | static EAS_RESULT Parse_wsmp (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_WSMP_DATA *p) |
| 1092 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1093 | EAS_RESULT result; |
| 1094 | EAS_U16 wtemp; |
| 1095 | EAS_U32 ltemp; |
| 1096 | EAS_U32 cbSize; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1097 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1098 | /* seek to start of chunk */ |
| 1099 | if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS) |
| 1100 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1101 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1102 | /* get structure size */ |
| 1103 | if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, &cbSize, EAS_FALSE)) != EAS_SUCCESS) |
| 1104 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1105 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1106 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1116 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1117 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1120 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1121 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1129 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1130 | /* option flags */ |
| 1131 | if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, <emp, EAS_FALSE)) != EAS_SUCCESS) |
| 1132 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1133 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1134 | /* sample loops */ |
| 1135 | if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, <emp, EAS_FALSE)) != EAS_SUCCESS) |
| 1136 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1137 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1138 | /* if looped sample, get loop data */ |
| 1139 | if (ltemp) |
| 1140 | { |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1141 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1142 | 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, <emp, EAS_FALSE)) != EAS_SUCCESS) |
| 1151 | return result; |
| 1152 | |
| 1153 | /* get loop type */ |
| 1154 | if ((result = EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle, <emp, 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 Jia | 163e00f | 2015-08-20 16:03:14 -0700 | [diff] [blame] | 1164 | |
| 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 Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | /*---------------------------------------------------------------------------- |
| 1178 | * Parse_fmt () |
| 1179 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1180 | * Purpose: |
| 1181 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1182 | * |
| 1183 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1184 | * |
| 1185 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1186 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1187 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1188 | * |
| 1189 | *---------------------------------------------------------------------------- |
| 1190 | */ |
| 1191 | static EAS_RESULT Parse_fmt (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_WSMP_DATA *p) |
| 1192 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1193 | EAS_RESULT result; |
| 1194 | EAS_U16 wtemp; |
| 1195 | EAS_U32 ltemp; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1196 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1197 | /* seek to start of chunk */ |
| 1198 | if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS) |
| 1199 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1200 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1201 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1209 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1210 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1218 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1219 | /* 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, <emp, 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | #if defined( _8_BIT_SAMPLES) |
| 1245 | /*---------------------------------------------------------------------------- |
| 1246 | * Parse_data () |
| 1247 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1248 | * Purpose: |
| 1249 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1250 | * 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 Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1256 | * |
| 1257 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1258 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1259 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1260 | * |
| 1261 | *---------------------------------------------------------------------------- |
| 1262 | */ |
Wei Jia | 9cf7e87 | 2015-08-21 13:41:42 -0700 | [diff] [blame] | 1263 | static 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1264 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1265 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1270 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1271 | /* seek to start of chunk */ |
| 1272 | if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS) |
| 1273 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1274 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1275 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1285 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1286 | /* 16-bit samples, need to convert to 8-bit or ADPCM */ |
| 1287 | else |
| 1288 | { |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1289 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1290 | while (size) |
| 1291 | { |
| 1292 | EAS_I8 *pInput; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1293 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1294 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1299 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1300 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1307 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1308 | 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 Jia | 163e00f | 2015-08-20 16:03:14 -0700 | [diff] [blame] | 1318 | { |
Wei Jia | 9cf7e87 | 2015-08-21 13:41:42 -0700 | [diff] [blame] | 1319 | if (sampleLen < sizeof(EAS_SAMPLE) |
| 1320 | || (pWsmp->loopStart + pWsmp->loopLength) * sizeof(EAS_SAMPLE) > sampleLen - sizeof(EAS_SAMPLE)) |
Wei Jia | 163e00f | 2015-08-20 16:03:14 -0700 | [diff] [blame] | 1321 | { |
| 1322 | return EAS_FAILURE; |
| 1323 | } |
| 1324 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1325 | pSample[pWsmp->loopStart + pWsmp->loopLength] = pSample[pWsmp->loopStart]; |
Wei Jia | 163e00f | 2015-08-20 16:03:14 -0700 | [diff] [blame] | 1326 | } |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1327 | |
| 1328 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1329 | } |
| 1330 | #elif defined(_16_BIT_SAMPLES) |
taeseok715.kim | 9258597 | 2019-02-12 19:13:29 +0900 | [diff] [blame] | 1331 | static 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 Nelissen | 3ff1a66 | 2020-09-30 16:28:55 -0700 | [diff] [blame] | 1375 | if (sampleLen < sizeof(EAS_SAMPLE) |
| 1376 | || (pWsmp->loopStart + pWsmp->loopLength) * sizeof(EAS_SAMPLE) > sampleLen - sizeof(EAS_SAMPLE)) { |
| 1377 | return EAS_FAILURE; |
| 1378 | } |
taeseok715.kim | 9258597 | 2019-02-12 19:13:29 +0900 | [diff] [blame] | 1379 | |
| 1380 | pSample[(pWsmp->loopStart + pWsmp->loopLength)>>1] = pSample[(pWsmp->loopStart)>>1]; |
| 1381 | } |
| 1382 | |
| 1383 | return EAS_SUCCESS; |
| 1384 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1385 | #else |
| 1386 | #error "Must specifiy _8_BIT_SAMPLES or _16_BIT_SAMPLES" |
| 1387 | #endif |
| 1388 | |
| 1389 | /*---------------------------------------------------------------------------- |
| 1390 | * Parse_lins () |
| 1391 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1392 | * Purpose: |
| 1393 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1394 | * |
| 1395 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1396 | * |
| 1397 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1398 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1399 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1400 | * |
| 1401 | *---------------------------------------------------------------------------- |
| 1402 | */ |
| 1403 | static EAS_RESULT Parse_lins (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size) |
| 1404 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1405 | EAS_RESULT result; |
| 1406 | EAS_U32 temp; |
| 1407 | EAS_I32 endChunk; |
| 1408 | EAS_I32 chunkPos; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1409 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1410 | /* seek to start of chunk */ |
| 1411 | if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS) |
| 1412 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1413 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1414 | /* read to end of chunk */ |
| 1415 | endChunk = pos + size; |
| 1416 | while (pos < endChunk) |
| 1417 | { |
| 1418 | chunkPos = pos; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1419 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1420 | /* get the next chunk type */ |
| 1421 | if ((result = NextChunk(pDLSData, &pos, &temp, &size)) != EAS_SUCCESS) |
| 1422 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1423 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1424 | /* only instrument chunks are useful */ |
| 1425 | if (temp != CHUNK_INS) |
| 1426 | continue; |
| 1427 | |
Harish Mahendrakar | c049c14 | 2020-04-30 04:24:53 +0530 | [diff] [blame] | 1428 | /* 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 Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1437 | if ((result = Parse_ins(pDLSData, chunkPos + 12, size)) != EAS_SUCCESS) |
| 1438 | return result; |
| 1439 | } |
| 1440 | |
| 1441 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | /*---------------------------------------------------------------------------- |
| 1445 | * Parse_ins () |
| 1446 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1447 | * Purpose: |
| 1448 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1449 | * |
| 1450 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1451 | * |
| 1452 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1453 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1454 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1455 | * |
| 1456 | *---------------------------------------------------------------------------- |
| 1457 | */ |
| 1458 | static EAS_RESULT Parse_ins (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size) |
| 1459 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1460 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1476 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1477 | /* seek to start of chunk */ |
| 1478 | if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS) |
| 1479 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1480 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1481 | /* no chunks yet */ |
| 1482 | lrgnPos = lrgnSize = lartPos = lartSize = lar2Pos = lar2Size = inshPos = artIndex = 0; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1483 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1484 | /* read to end of chunk */ |
| 1485 | endChunk = pos + size; |
| 1486 | while (pos < endChunk) |
| 1487 | { |
| 1488 | chunkPos = pos; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1489 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1490 | /* get the next chunk type */ |
| 1491 | if ((result = NextChunk(pDLSData, &pos, &temp, &size)) != EAS_SUCCESS) |
| 1492 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1493 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1494 | /* parse useful chunks */ |
| 1495 | switch (temp) |
| 1496 | { |
| 1497 | case CHUNK_INSH: |
| 1498 | inshPos = chunkPos + 8; |
| 1499 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1500 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1501 | case CHUNK_LART: |
| 1502 | lartPos = chunkPos + 12; |
| 1503 | lartSize = size; |
| 1504 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1505 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1506 | case CHUNK_LAR2: |
| 1507 | lar2Pos = chunkPos + 12; |
| 1508 | lar2Size = size; |
| 1509 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1510 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1511 | case CHUNK_LRGN: |
| 1512 | lrgnPos = chunkPos + 12; |
| 1513 | lrgnSize = size; |
| 1514 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1515 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1516 | default: |
| 1517 | break; |
| 1518 | } |
| 1519 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1520 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1521 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1527 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1528 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1534 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1535 | /* parse the instrument header */ |
| 1536 | if ((result = Parse_insh(pDLSData, inshPos, ®ionCount, &locale)) != EAS_SUCCESS) |
| 1537 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1538 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1539 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1547 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1548 | if (art.values[PARAM_MODIFIED]) |
| 1549 | { |
| 1550 | artIndex = (EAS_U16) pDLSData->artCount; |
| 1551 | pDLSData->artCount++; |
| 1552 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1553 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1554 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | /*---------------------------------------------------------------------------- |
| 1580 | * Parse_insh () |
| 1581 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1582 | * Purpose: |
| 1583 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1584 | * |
| 1585 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1586 | * |
| 1587 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1588 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1589 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1590 | * |
| 1591 | *---------------------------------------------------------------------------- |
| 1592 | */ |
| 1593 | static EAS_RESULT Parse_insh (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_U32 *pRgnCount, EAS_U32 *pLocale) |
| 1594 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1595 | EAS_RESULT result; |
| 1596 | EAS_U32 bank; |
| 1597 | EAS_U32 program; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1598 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1599 | /* seek to start of chunk */ |
| 1600 | if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS) |
| 1601 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1602 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1603 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1610 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1611 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | /*---------------------------------------------------------------------------- |
| 1629 | * Parse_lrgn () |
| 1630 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1631 | * Purpose: |
| 1632 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1633 | * |
| 1634 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1635 | * |
| 1636 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1637 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1638 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1639 | * |
| 1640 | *---------------------------------------------------------------------------- |
| 1641 | */ |
| 1642 | static EAS_RESULT Parse_lrgn (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, EAS_U16 artIndex, EAS_U32 numRegions) |
| 1643 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1644 | EAS_RESULT result; |
| 1645 | EAS_U32 temp; |
| 1646 | EAS_I32 chunkPos; |
| 1647 | EAS_I32 endChunk; |
| 1648 | EAS_U16 regionCount; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1649 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1650 | /* seek to start of chunk */ |
| 1651 | if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS) |
| 1652 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1653 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1654 | /* read to end of chunk */ |
| 1655 | regionCount = 0; |
| 1656 | endChunk = pos + size; |
| 1657 | while (pos < endChunk) |
| 1658 | { |
| 1659 | chunkPos = pos; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1660 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1661 | /* get the next chunk type */ |
| 1662 | if ((result = NextChunk(pDLSData, &pos, &temp, &size)) != EAS_SUCCESS) |
| 1663 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1664 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1665 | 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 Mahendrakar | c049c14 | 2020-04-30 04:24:53 +0530 | [diff] [blame] | 1672 | /* 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 Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1680 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | /*---------------------------------------------------------------------------- |
| 1694 | * Parse_rgn () |
| 1695 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1696 | * Purpose: |
| 1697 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1698 | * |
| 1699 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1700 | * |
| 1701 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1702 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1703 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1704 | * |
| 1705 | *---------------------------------------------------------------------------- |
| 1706 | */ |
| 1707 | static EAS_RESULT Parse_rgn (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, EAS_U16 artIndex) |
| 1708 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1709 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1725 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1726 | /* seek to start of chunk */ |
| 1727 | if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS) |
| 1728 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1729 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1730 | /* no chunks found yet */ |
| 1731 | rgnhPos = lartPos = lartSize = lar2Pos = lar2Size = wsmpPos = wlnkPos = 0; |
| 1732 | regionIndex = (EAS_U16) pDLSData->regionCount; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1733 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1734 | /* read to end of chunk */ |
| 1735 | endChunk = pos + size; |
| 1736 | while (pos < endChunk) |
| 1737 | { |
| 1738 | chunkPos = pos; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1739 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1740 | /* get the next chunk type */ |
| 1741 | if ((result = NextChunk(pDLSData, &pos, &temp, &size)) != EAS_SUCCESS) |
| 1742 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1743 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1744 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1750 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1751 | /* if conditional chunk evaluates false, skip this list */ |
| 1752 | if (!temp) |
| 1753 | return EAS_SUCCESS; |
| 1754 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1755 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1756 | case CHUNK_RGNH: |
| 1757 | rgnhPos = chunkPos + 8; |
| 1758 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1759 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1760 | case CHUNK_WLNK: |
| 1761 | wlnkPos = chunkPos + 8; |
| 1762 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1763 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1764 | case CHUNK_WSMP: |
| 1765 | wsmpPos = chunkPos + 8; |
| 1766 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1767 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1768 | case CHUNK_LART: |
| 1769 | lartPos = chunkPos + 12; |
| 1770 | lartSize = size; |
| 1771 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1772 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1773 | case CHUNK_LAR2: |
| 1774 | lar2Pos = chunkPos + 12; |
| 1775 | lar2Size = size; |
| 1776 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1777 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1778 | default: |
| 1779 | break; |
| 1780 | } |
| 1781 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1782 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1783 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1789 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1790 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1796 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1797 | /* parse wlnk chunk */ |
| 1798 | if ((result = Parse_wlnk(pDLSData, wlnkPos, &waveIndex)) != EAS_SUCCESS) |
| 1799 | return result; |
Wei Jia | 99e0e2e | 2015-08-20 16:25:04 -0700 | [diff] [blame] | 1800 | if (waveIndex >= pDLSData->waveCount) |
| 1801 | { |
| 1802 | return EAS_FAILURE; |
| 1803 | } |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1804 | pWsmp = &pDLSData->wsmpData[waveIndex]; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1805 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1806 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1813 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1814 | if (lar2Pos) |
| 1815 | { |
| 1816 | if ((result = Parse_lart(pDLSData, lar2Pos, lar2Size, &art)) != EAS_SUCCESS) |
| 1817 | return result; |
| 1818 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1819 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1820 | /* 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 Mahendrakar | c049c14 | 2020-04-30 04:24:53 +0530 | [diff] [blame] | 1827 | /* ensure artCount is less than numDLSArticulations */ |
| 1828 | if (pDLSData->artCount >= pDLSData->pDLS->numDLSArticulations) |
| 1829 | { |
| 1830 | return EAS_ERROR_DATA_INCONSISTENCY; |
| 1831 | } |
| 1832 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1833 | 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 Jia | 9cf7e87 | 2015-08-21 13:41:42 -0700 | [diff] [blame] | 1852 | |
| 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 Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1863 | } |
| 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | /*---------------------------------------------------------------------------- |
| 1875 | * Parse_rgnh () |
| 1876 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1877 | * Purpose: |
| 1878 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1879 | * |
| 1880 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1881 | * |
| 1882 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1883 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1884 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1885 | * |
| 1886 | *---------------------------------------------------------------------------- |
| 1887 | */ |
| 1888 | static EAS_RESULT Parse_rgnh (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_DLS_REGION *pRgn) |
| 1889 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1890 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1897 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1898 | /* seek to start of chunk */ |
| 1899 | if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS) |
| 1900 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1901 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1902 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | /*---------------------------------------------------------------------------- |
| 1961 | * Parse_lart () |
| 1962 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1963 | * Purpose: |
| 1964 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1965 | * |
| 1966 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1967 | * |
| 1968 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1969 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1970 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1971 | * |
| 1972 | *---------------------------------------------------------------------------- |
| 1973 | */ |
| 1974 | static EAS_RESULT Parse_lart (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_I32 size, S_DLS_ART_VALUES *pArt) |
| 1975 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1976 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1982 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1983 | /* seek to start of chunk */ |
| 1984 | if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS) |
| 1985 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1986 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1987 | /* no articulation chunks yet */ |
| 1988 | art1Pos = art2Pos = 0; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1989 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1990 | /* read to end of chunk */ |
| 1991 | endChunk = pos + size; |
| 1992 | while (pos < endChunk) |
| 1993 | { |
| 1994 | chunkPos = pos; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1995 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1996 | /* get the next chunk type */ |
| 1997 | if ((result = NextChunk(pDLSData, &pos, &temp, &size)) != EAS_SUCCESS) |
| 1998 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1999 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2000 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2006 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2007 | /* if conditional chunk evaluates false, skip this list */ |
| 2008 | if (!temp) |
| 2009 | return EAS_SUCCESS; |
| 2010 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2011 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2012 | case CHUNK_ART1: |
| 2013 | art1Pos = chunkPos + 8; |
| 2014 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2015 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2016 | case CHUNK_ART2: |
| 2017 | art2Pos = chunkPos + 8; |
| 2018 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2019 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2020 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | /*---------------------------------------------------------------------------- |
| 2042 | * Parse_art() |
| 2043 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2044 | * Purpose: |
| 2045 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2046 | * |
| 2047 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2048 | * |
| 2049 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2050 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2051 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2052 | * |
| 2053 | *---------------------------------------------------------------------------- |
| 2054 | */ |
| 2055 | static EAS_RESULT Parse_art (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, S_DLS_ART_VALUES *pArt) |
| 2056 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2057 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2066 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2067 | /* seek to start of data */ |
| 2068 | if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS) |
| 2069 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2070 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2071 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2075 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2076 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2079 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2080 | /* skip to start of connections */ |
| 2081 | if ((result = EAS_HWFileSeek(pDLSData->hwInstData, pDLSData->fileHandle, pos)) != EAS_SUCCESS) |
| 2082 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2083 | |
Marco Nelissen | 7191943 | 2019-06-19 10:52:12 -0700 | [diff] [blame] | 2084 | while (numConnections) |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2085 | { |
Marco Nelissen | 7191943 | 2019-06-19 10:52:12 -0700 | [diff] [blame] | 2086 | numConnections--; |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2087 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | /*---------------------------------------------------------------------------- |
| 2120 | * Parse_wlnk () |
| 2121 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2122 | * Purpose: |
| 2123 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2124 | * |
| 2125 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2126 | * |
| 2127 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2128 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2129 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2130 | * |
| 2131 | *---------------------------------------------------------------------------- |
| 2132 | */ |
| 2133 | static EAS_RESULT Parse_wlnk (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 pos, EAS_U32 *pWaveIndex) |
| 2134 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2135 | EAS_RESULT result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2136 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2137 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2140 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2141 | /* read the index */ |
| 2142 | return EAS_HWGetDWord(pDLSData->hwInstData, pDLSData->fileHandle,pWaveIndex, EAS_FALSE); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | /*---------------------------------------------------------------------------- |
| 2146 | * PopcdlStack () |
| 2147 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2148 | * Purpose: |
| 2149 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2150 | * |
| 2151 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2152 | * |
| 2153 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2154 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2155 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2156 | * |
| 2157 | *---------------------------------------------------------------------------- |
| 2158 | */ |
| 2159 | static EAS_RESULT PopcdlStack (EAS_U32 *pStack, EAS_INT *pStackPtr, EAS_U32 *pValue) |
| 2160 | { |
| 2161 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2162 | /* stack underflow, cdl block has an errorr */ |
| 2163 | if (*pStackPtr < 0) |
| 2164 | return EAS_ERROR_FILE_FORMAT; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2165 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2166 | /* pop the value off the stack */ |
| 2167 | *pValue = pStack[*pStackPtr]; |
| 2168 | *pStackPtr = *pStackPtr - 1; |
| 2169 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | /*---------------------------------------------------------------------------- |
| 2173 | * PushcdlStack () |
| 2174 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2175 | * Purpose: |
| 2176 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2177 | * |
| 2178 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2179 | * |
| 2180 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2181 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2182 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2183 | * |
| 2184 | *---------------------------------------------------------------------------- |
| 2185 | */ |
| 2186 | static EAS_RESULT PushcdlStack (EAS_U32 *pStack, EAS_INT *pStackPtr, EAS_U32 value) |
| 2187 | { |
| 2188 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2189 | /* stack overflow, return an error */ |
Wei Jia | 56d1532 | 2017-02-07 10:35:31 -0800 | [diff] [blame] | 2190 | if (*pStackPtr >= (CDL_STACK_SIZE - 1)) { |
| 2191 | ALOGE("b/34031018, stackPtr(%d)", *pStackPtr); |
| 2192 | android_errorWriteLog(0x534e4554, "34031018"); |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2193 | return EAS_ERROR_FILE_FORMAT; |
Wei Jia | 56d1532 | 2017-02-07 10:35:31 -0800 | [diff] [blame] | 2194 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2195 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2196 | /* push the value onto the stack */ |
| 2197 | *pStackPtr = *pStackPtr + 1; |
| 2198 | pStack[*pStackPtr] = value; |
| 2199 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | /*---------------------------------------------------------------------------- |
| 2203 | * QueryGUID () |
| 2204 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2205 | * Purpose: |
| 2206 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2207 | * |
| 2208 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2209 | * |
| 2210 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2211 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2212 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2213 | * |
| 2214 | *---------------------------------------------------------------------------- |
| 2215 | */ |
| 2216 | static EAS_BOOL QueryGUID (const DLSID *pGUID, EAS_U32 *pValue) |
| 2217 | { |
| 2218 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2219 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2226 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2227 | if (EAS_HWMemCmp(&DLSID_GSInHardware, pGUID, sizeof(DLSID)) == 0) |
| 2228 | return EAS_TRUE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2229 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2230 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | /*---------------------------------------------------------------------------- |
| 2271 | * ReadDLSID () |
| 2272 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2273 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2274 | * Reads a DLSID in a manner that is not sensitive to processor endian-ness |
| 2275 | * |
| 2276 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2277 | * |
| 2278 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2279 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2280 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2281 | * |
| 2282 | *---------------------------------------------------------------------------- |
| 2283 | */ |
| 2284 | static EAS_RESULT ReadDLSID (SDLS_SYNTHESIZER_DATA *pDLSData, DLSID *pDLSID) |
| 2285 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2286 | EAS_RESULT result; |
| 2287 | EAS_I32 n; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2288 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2289 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | /*---------------------------------------------------------------------------- |
| 2299 | * Parse_cdl () |
| 2300 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2301 | * Purpose: |
| 2302 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2303 | * |
| 2304 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2305 | * |
| 2306 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2307 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2308 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2309 | * |
| 2310 | *---------------------------------------------------------------------------- |
| 2311 | */ |
| 2312 | static EAS_RESULT Parse_cdl (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_I32 size, EAS_U32 *pValue) |
| 2313 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2314 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2320 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2321 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2329 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2330 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2388 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2389 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2395 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2396 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2401 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2402 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2408 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2409 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | /*---------------------------------------------------------------------------- |
| 2428 | * Convert_rgn() |
| 2429 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2430 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2431 | * Convert region data from DLS to EAS |
| 2432 | * |
| 2433 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2434 | * |
| 2435 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2436 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2437 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2438 | * |
| 2439 | *---------------------------------------------------------------------------- |
| 2440 | */ |
| 2441 | static void Convert_rgn (SDLS_SYNTHESIZER_DATA *pDLSData, EAS_U16 regionIndex, EAS_U16 artIndex, EAS_U16 waveIndex, S_WSMP_DATA *pWsmp) |
| 2442 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2443 | S_DLS_REGION *pRgn; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2444 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2445 | /* setup pointers to data structures */ |
| 2446 | pRgn = &pDLSData->pDLS->pDLSRegions[regionIndex]; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2447 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2448 | /* intiailize indices */ |
| 2449 | pRgn->wtRegion.artIndex = artIndex; |
| 2450 | pRgn->wtRegion.waveIndex = waveIndex; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2451 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2452 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | /*---------------------------------------------------------------------------- |
| 2463 | * Convert_art() |
| 2464 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2465 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2466 | * Convert articulation data from DLS to EAS |
| 2467 | * |
| 2468 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2469 | * |
| 2470 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2471 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2472 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2473 | * |
| 2474 | *---------------------------------------------------------------------------- |
| 2475 | */ |
| 2476 | static void Convert_art (SDLS_SYNTHESIZER_DATA *pDLSData, const S_DLS_ART_VALUES *pDLSArt, EAS_U16 artIndex) |
| 2477 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2478 | S_DLS_ARTICULATION *pArt; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2479 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2480 | /* setup pointers to data structures */ |
| 2481 | pArt = &pDLSData->pDLS->pDLSArticulations[artIndex]; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2482 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2483 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2488 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2489 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2500 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2501 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2511 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2512 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2521 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2522 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2526 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2527 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2537 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2538 | /* output parameters */ |
| 2539 | pArt->pan = ConvertPan(pDLSArt->values[PARAM_DEFAULT_PAN]); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2540 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2541 | if (pDLSArt->values[PARAM_VEL_TO_GAIN] != 0) |
| 2542 | pArt->filterQandFlags |= FLAG_DLS_VELOCITY_SENSITIVE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2543 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2544 | #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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2547 | #endif |
| 2548 | |
| 2549 | #ifdef _CHORUS |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2550 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | /*---------------------------------------------------------------------------- |
| 2556 | * ConvertSampleRate() |
| 2557 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2558 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2559 | * |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2560 | * Inputs: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2561 | * |
| 2562 | * Outputs: |
| 2563 | * |
| 2564 | * Side Effects: |
| 2565 | *---------------------------------------------------------------------------- |
| 2566 | */ |
| 2567 | static EAS_I16 ConvertSampleRate (EAS_U32 sampleRate) |
| 2568 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2569 | return (EAS_I16) (1200.0 * log10((double) sampleRate / (double) outputSampleRate) / log10(2.0)); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | /*---------------------------------------------------------------------------- |
| 2573 | * ConvertSustainEG2() |
| 2574 | *---------------------------------------------------------------------------- |
| 2575 | * Convert sustain level to pitch/Fc multipler for EG2 |
| 2576 | *---------------------------------------------------------------------------- |
| 2577 | */ |
| 2578 | static EAS_I16 ConvertSustain (EAS_I32 sustain) |
| 2579 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2580 | /* check for sustain level of zero */ |
| 2581 | if (sustain == 0) |
| 2582 | return 0; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2583 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2584 | /* convert to log2 factor */ |
| 2585 | /*lint -e{704} use shift for performance */ |
| 2586 | sustain = (sustain * SUSTAIN_LINEAR_CONVERSION_FACTOR) >> 15; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2587 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2588 | if (sustain > SYNTH_FULL_SCALE_EG1_GAIN) |
| 2589 | return SYNTH_FULL_SCALE_EG1_GAIN; |
| 2590 | return (EAS_I16) sustain; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2591 | } |
| 2592 | |
| 2593 | /*---------------------------------------------------------------------------- |
| 2594 | * ConvertDelay () |
| 2595 | *---------------------------------------------------------------------------- |
| 2596 | * Converts timecents to frame count. Used for LFO and envelope |
| 2597 | * delay times. |
| 2598 | *---------------------------------------------------------------------------- |
| 2599 | */ |
| 2600 | EAS_I16 ConvertDelay (EAS_I32 timeCents) |
| 2601 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2602 | EAS_I32 temp; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2603 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2604 | if (timeCents == ZERO_TIME_IN_CENTS) |
| 2605 | return 0; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2606 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2607 | /* divide time by secs per frame to get number of frames */ |
| 2608 | temp = timeCents - dlsRateConvert; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2609 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2610 | /* convert from time cents to 10-bit fraction */ |
| 2611 | temp = FMUL_15x15(temp, TIME_CENTS_TO_LOG2); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2612 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2613 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2619 | } |
| 2620 | |
| 2621 | /*---------------------------------------------------------------------------- |
| 2622 | * ConvertRate () |
| 2623 | *---------------------------------------------------------------------------- |
| 2624 | * Convert timecents to rate |
| 2625 | *---------------------------------------------------------------------------- |
| 2626 | */ |
| 2627 | EAS_I16 ConvertRate (EAS_I32 timeCents) |
| 2628 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2629 | EAS_I32 temp; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2630 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2631 | if (timeCents == ZERO_TIME_IN_CENTS) |
| 2632 | return SYNTH_FULL_SCALE_EG1_GAIN; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2633 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2634 | /* divide frame rate by time in log domain to get rate */ |
| 2635 | temp = dlsRateConvert - timeCents; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2636 | |
| 2637 | #if 1 |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2638 | temp = EAS_Calculate2toX(temp); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2639 | #else |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2640 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2645 | #endif |
| 2646 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2647 | if (temp < SYNTH_FULL_SCALE_EG1_GAIN) |
| 2648 | return (EAS_I16) temp; |
| 2649 | return SYNTH_FULL_SCALE_EG1_GAIN; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2650 | } |
| 2651 | |
| 2652 | |
| 2653 | /*---------------------------------------------------------------------------- |
| 2654 | * ConvertLFOPhaseIncrement() |
| 2655 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2656 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2657 | * |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2658 | * Inputs: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2659 | * |
| 2660 | * Outputs: |
| 2661 | * |
| 2662 | * Side Effects: |
| 2663 | *---------------------------------------------------------------------------- |
| 2664 | */ |
| 2665 | static EAS_I16 ConvertLFOPhaseIncrement (EAS_I32 pitchCents) |
| 2666 | { |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2667 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2668 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2673 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2674 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2679 | } |
| 2680 | |
| 2681 | /*---------------------------------------------------------------------------- |
| 2682 | * ConvertPan() |
| 2683 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2684 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2685 | * |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2686 | * Inputs: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2687 | * |
| 2688 | * Outputs: |
| 2689 | * |
| 2690 | * Side Effects: |
| 2691 | *---------------------------------------------------------------------------- |
| 2692 | */ |
| 2693 | static EAS_I8 ConvertPan (EAS_I32 pan) |
| 2694 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2695 | |
| 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2703 | } |
| 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 | */ |
| 2712 | static EAS_U8 ConvertQ (EAS_I32 q) |
| 2713 | { |
| 2714 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2715 | /* apply limits */ |
| 2716 | if (q <= 0) |
| 2717 | return 0; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2718 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2719 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2722 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2723 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | #ifdef _DEBUG_DLS |
| 2730 | /*---------------------------------------------------------------------------- |
| 2731 | * DumpDLS() |
| 2732 | *---------------------------------------------------------------------------- |
| 2733 | */ |
| 2734 | static void DumpDLS (S_EAS *pEAS) |
| 2735 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2736 | S_DLS_ARTICULATION *pArt; |
| 2737 | S_DLS_REGION *pRegion; |
| 2738 | EAS_INT i; |
| 2739 | EAS_INT j; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2740 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2741 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2745 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2746 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2753 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2754 | 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2766 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2767 | if (pRegion->region.keyGroupAndFlags & REGION_FLAG_LAST_REGION) |
| 2768 | break; |
| 2769 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2770 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2771 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2772 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2773 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2788 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2789 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2794 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 2795 | /* 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 Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 2810 | |
| 2811 | } |
| 2812 | #endif |
| 2813 | |