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_public.c |
| 5 | * |
| 6 | * Contents and purpose: |
| 7 | * Contains EAS library public interface |
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 Sonic Network Inc. 2004 |
| 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: 842 $ |
| 26 | * $Date: 2007-08-23 14:32:31 -0700 (Thu, 23 Aug 2007) $ |
| 27 | *---------------------------------------------------------------------------- |
| 28 | */ |
| 29 | |
Phil Burk | c71f73a | 2018-06-19 08:19:05 -0700 | [diff] [blame] | 30 | #define LOG_TAG "Sonivox" |
| 31 | #include "log/log.h" |
| 32 | |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 33 | #include "eas_synthcfg.h" |
| 34 | #include "eas.h" |
| 35 | #include "eas_config.h" |
| 36 | #include "eas_host.h" |
| 37 | #include "eas_report.h" |
| 38 | #include "eas_data.h" |
| 39 | #include "eas_parser.h" |
| 40 | #include "eas_pcm.h" |
| 41 | #include "eas_midi.h" |
| 42 | #include "eas_mixer.h" |
| 43 | #include "eas_build.h" |
| 44 | #include "eas_vm_protos.h" |
| 45 | #include "eas_math.h" |
| 46 | |
| 47 | #ifdef JET_INTERFACE |
| 48 | #include "jet_data.h" |
| 49 | #endif |
| 50 | |
| 51 | #ifdef DLS_SYNTHESIZER |
| 52 | #include "eas_mdls.h" |
| 53 | #endif |
| 54 | |
| 55 | /* number of events to parse before calling EAS_HWYield function */ |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 56 | #define YIELD_EVENT_COUNT 10 |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 57 | |
| 58 | /*---------------------------------------------------------------------------- |
| 59 | * easLibConfig |
| 60 | * |
| 61 | * This structure is available through the EAS public interface to allow |
| 62 | * the user to check the configuration of the library. |
| 63 | *---------------------------------------------------------------------------- |
| 64 | */ |
| 65 | static const S_EAS_LIB_CONFIG easLibConfig = |
| 66 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 67 | LIB_VERSION, |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 68 | #ifdef _CHECKED_BUILD |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 69 | EAS_TRUE, |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 70 | #else |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 71 | EAS_FALSE, |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 72 | #endif |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 73 | MAX_SYNTH_VOICES, |
| 74 | NUM_OUTPUT_CHANNELS, |
| 75 | _OUTPUT_SAMPLE_RATE, |
| 76 | BUFFER_SIZE_IN_MONO_SAMPLES, |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 77 | #ifdef _FILTER_ENABLED |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 78 | EAS_TRUE, |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 79 | #else |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 80 | EAS_FALSE, |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 81 | #endif |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 82 | _BUILD_TIME_, |
| 83 | _BUILD_VERSION_ |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | /* local prototypes */ |
| 87 | static EAS_RESULT EAS_ParseEvents (S_EAS_DATA *pEASData, S_EAS_STREAM *pStream, EAS_U32 endTime, EAS_INT parseMode); |
| 88 | |
| 89 | /*---------------------------------------------------------------------------- |
| 90 | * EAS_SetStreamParameter |
| 91 | *---------------------------------------------------------------------------- |
| 92 | * Sets the specified parameter in the stream. Allows access to |
| 93 | * customizable settings within the individual file parsers. |
| 94 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 95 | * pEASData - pointer to EAS persistent data object |
| 96 | * pStream - stream handle |
| 97 | * param - enumerated parameter (see eas_parser.h) |
| 98 | * value - new value |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 99 | *---------------------------------------------------------------------------- |
| 100 | */ |
| 101 | EAS_RESULT EAS_SetStreamParameter (S_EAS_DATA *pEASData, EAS_HANDLE pStream, EAS_I32 param, EAS_I32 value) |
| 102 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 103 | S_FILE_PARSER_INTERFACE *pParserModule; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 104 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 105 | pParserModule = (S_FILE_PARSER_INTERFACE*) pStream->pParserModule; |
| 106 | if (pParserModule->pfSetData) |
| 107 | return (*pParserModule->pfSetData)(pEASData, pStream->handle, param, value); |
| 108 | return EAS_ERROR_FEATURE_NOT_AVAILABLE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /*---------------------------------------------------------------------------- |
| 112 | * EAS_GetStreamParameter |
| 113 | *---------------------------------------------------------------------------- |
| 114 | * Sets the specified parameter in the stream. Allows access to |
| 115 | * customizable settings within the individual file parsers. |
| 116 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 117 | * pEASData - pointer to EAS persistent data object |
| 118 | * pStream - stream handle |
| 119 | * param - enumerated parameter (see eas_parser.h) |
| 120 | * pValue - pointer to variable to receive current setting |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 121 | *---------------------------------------------------------------------------- |
| 122 | */ |
| 123 | EAS_RESULT EAS_GetStreamParameter (S_EAS_DATA *pEASData, EAS_HANDLE pStream, EAS_I32 param, EAS_I32 *pValue) |
| 124 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 125 | S_FILE_PARSER_INTERFACE *pParserModule; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 126 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 127 | pParserModule = (S_FILE_PARSER_INTERFACE*) pStream->pParserModule; |
| 128 | if (pParserModule->pfGetData) |
| 129 | return (*pParserModule->pfGetData)(pEASData, pStream->handle, param, pValue); |
| 130 | return EAS_ERROR_FEATURE_NOT_AVAILABLE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /*---------------------------------------------------------------------------- |
| 134 | * EAS_StreamReady() |
| 135 | *---------------------------------------------------------------------------- |
| 136 | * This routine sets common parameters like transpose, volume, etc. |
| 137 | * First, it attempts to use the parser EAS_SetStreamParameter interface. If that |
| 138 | * fails, it attempts to get the synth handle from the parser and |
| 139 | * set the parameter directly on the synth. This eliminates duplicate |
| 140 | * code in the parser. |
| 141 | *---------------------------------------------------------------------------- |
| 142 | */ |
| 143 | EAS_BOOL EAS_StreamReady (S_EAS_DATA *pEASData, EAS_HANDLE pStream) |
| 144 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 145 | S_FILE_PARSER_INTERFACE *pParserModule; |
| 146 | EAS_STATE state; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 147 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 148 | pParserModule = (S_FILE_PARSER_INTERFACE*) pStream->pParserModule; |
| 149 | if (pParserModule->pfState(pEASData, pStream->handle, &state) != EAS_SUCCESS) |
| 150 | return EAS_FALSE; |
| 151 | return (state < EAS_STATE_OPEN); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /*---------------------------------------------------------------------------- |
| 155 | * EAS_IntSetStrmParam() |
| 156 | *---------------------------------------------------------------------------- |
| 157 | * This routine sets common parameters like transpose, volume, etc. |
| 158 | * First, it attempts to use the parser EAS_SetStreamParameter interface. If that |
| 159 | * fails, it attempts to get the synth handle from the parser and |
| 160 | * set the parameter directly on the synth. This eliminates duplicate |
| 161 | * code in the parser. |
| 162 | *---------------------------------------------------------------------------- |
| 163 | */ |
| 164 | EAS_RESULT EAS_IntSetStrmParam (S_EAS_DATA *pEASData, EAS_HANDLE pStream, EAS_INT param, EAS_I32 value) |
| 165 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 166 | S_SYNTH *pSynth; |
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 | /* try to set the parameter using stream interface */ |
| 169 | if (EAS_SetStreamParameter(pEASData, pStream, param, value) == EAS_SUCCESS) |
| 170 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 171 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 172 | /* get a pointer to the synth object and set it directly */ |
| 173 | /*lint -e{740} we are cheating by passing a pointer through this interface */ |
| 174 | if (EAS_GetStreamParameter(pEASData, pStream, PARSER_DATA_SYNTH_HANDLE, (EAS_I32*) &pSynth) != EAS_SUCCESS) |
| 175 | return EAS_ERROR_INVALID_PARAMETER; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 176 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 177 | if (pSynth == NULL) |
| 178 | return EAS_ERROR_INVALID_PARAMETER; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 179 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 180 | switch (param) |
| 181 | { |
| 182 | |
| 183 | #ifdef DLS_SYNTHESIZER |
| 184 | case PARSER_DATA_DLS_COLLECTION: |
| 185 | { |
| 186 | EAS_RESULT result = VMSetDLSLib(pSynth, (EAS_DLSLIB_HANDLE) value); |
| 187 | if (result == EAS_SUCCESS) |
| 188 | { |
| 189 | DLSAddRef((S_DLS*) value); |
| 190 | VMInitializeAllChannels(pEASData->pVoiceMgr, pSynth); |
| 191 | } |
| 192 | return result; |
| 193 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 194 | #endif |
| 195 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 196 | case PARSER_DATA_EAS_LIBRARY: |
| 197 | return VMSetEASLib(pSynth, (EAS_SNDLIB_HANDLE) value); |
| 198 | |
| 199 | case PARSER_DATA_POLYPHONY: |
| 200 | return VMSetPolyphony(pEASData->pVoiceMgr, pSynth, value); |
| 201 | |
| 202 | case PARSER_DATA_PRIORITY: |
| 203 | return VMSetPriority(pEASData->pVoiceMgr, pSynth, value); |
| 204 | |
| 205 | case PARSER_DATA_TRANSPOSITION: |
| 206 | VMSetTranposition(pSynth, value); |
| 207 | break; |
| 208 | |
| 209 | case PARSER_DATA_VOLUME: |
| 210 | VMSetVolume(pSynth, (EAS_U16) value); |
| 211 | break; |
| 212 | |
| 213 | default: |
| 214 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Invalid paramter %d in call to EAS_IntSetStrmParam", param); */ } |
| 215 | return EAS_ERROR_INVALID_PARAMETER; |
| 216 | } |
| 217 | |
| 218 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /*---------------------------------------------------------------------------- |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 222 | * EAS_AllocateStream() |
| 223 | *---------------------------------------------------------------------------- |
| 224 | * Purpose: |
| 225 | * Allocates a stream handle |
| 226 | * |
| 227 | * Inputs: |
| 228 | * |
| 229 | * Outputs: |
| 230 | * |
| 231 | *---------------------------------------------------------------------------- |
| 232 | */ |
| 233 | static EAS_INT EAS_AllocateStream (EAS_DATA_HANDLE pEASData) |
| 234 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 235 | EAS_INT streamNum; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 236 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 237 | /* check for static allocation, only one stream allowed */ |
| 238 | if (pEASData->staticMemoryModel) |
| 239 | { |
| 240 | if (pEASData->streams[0].handle != NULL) |
| 241 | { |
| 242 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Attempt to open multiple streams in static model\n"); */ } |
| 243 | return -1; |
| 244 | } |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | /* dynamic model */ |
| 249 | for (streamNum = 0; streamNum < MAX_NUMBER_STREAMS; streamNum++) |
| 250 | if (pEASData->streams[streamNum].handle == NULL) |
| 251 | break; |
| 252 | if (streamNum == MAX_NUMBER_STREAMS) |
| 253 | { |
| 254 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Exceeded maximum number of open streams\n"); */ } |
| 255 | return -1; |
| 256 | } |
| 257 | return streamNum; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /*---------------------------------------------------------------------------- |
| 261 | * EAS_InitStream() |
| 262 | *---------------------------------------------------------------------------- |
| 263 | * Purpose: |
| 264 | * Initialize a stream |
| 265 | * |
| 266 | * Inputs: |
| 267 | * |
| 268 | * Outputs: |
| 269 | * |
| 270 | *---------------------------------------------------------------------------- |
| 271 | */ |
| 272 | static void EAS_InitStream (S_EAS_STREAM *pStream, EAS_VOID_PTR pParserModule, EAS_VOID_PTR streamHandle) |
| 273 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 274 | pStream->pParserModule = pParserModule; |
| 275 | pStream->handle = streamHandle; |
| 276 | pStream->time = 0; |
| 277 | pStream->frameLength = AUDIO_FRAME_LENGTH; |
| 278 | pStream->repeatCount = 0; |
| 279 | pStream->volume = DEFAULT_STREAM_VOLUME; |
| 280 | pStream->streamFlags = 0; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /*---------------------------------------------------------------------------- |
| 284 | * EAS_Config() |
| 285 | *---------------------------------------------------------------------------- |
| 286 | * Purpose: |
| 287 | * Returns a pointer to a structure containing the configuration options |
| 288 | * in this library build. |
| 289 | * |
| 290 | * Inputs: |
| 291 | * |
| 292 | * Outputs: |
| 293 | * |
| 294 | *---------------------------------------------------------------------------- |
| 295 | */ |
| 296 | EAS_PUBLIC const S_EAS_LIB_CONFIG *EAS_Config (void) |
| 297 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 298 | return &easLibConfig; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | /*---------------------------------------------------------------------------- |
| 302 | * EAS_Init() |
| 303 | *---------------------------------------------------------------------------- |
| 304 | * Purpose: |
| 305 | * Initialize the synthesizer library |
| 306 | * |
| 307 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 308 | * ppEASData - pointer to data handle variable for this instance |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 309 | * |
| 310 | * Outputs: |
| 311 | * |
| 312 | *---------------------------------------------------------------------------- |
| 313 | */ |
| 314 | EAS_PUBLIC EAS_RESULT EAS_Init (EAS_DATA_HANDLE *ppEASData) |
| 315 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 316 | EAS_HW_DATA_HANDLE pHWInstData; |
| 317 | EAS_RESULT result; |
| 318 | S_EAS_DATA *pEASData; |
| 319 | EAS_INT module; |
| 320 | EAS_BOOL staticMemoryModel; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 321 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 322 | /* get the memory model */ |
| 323 | staticMemoryModel = EAS_CMStaticMemoryModel(); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 324 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 325 | /* initialize the host wrapper interface */ |
| 326 | *ppEASData = NULL; |
| 327 | if ((result = EAS_HWInit(&pHWInstData)) != EAS_SUCCESS) |
| 328 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 329 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 330 | /* check Configuration Module for S_EAS_DATA allocation */ |
| 331 | if (staticMemoryModel) |
| 332 | pEASData = EAS_CMEnumData(EAS_CM_EAS_DATA); |
| 333 | else |
| 334 | pEASData = EAS_HWMalloc(pHWInstData, sizeof(S_EAS_DATA)); |
| 335 | if (!pEASData) |
| 336 | { |
| 337 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_FATAL, "Failed to allocate EAS library memory\n"); */ } |
| 338 | return EAS_ERROR_MALLOC_FAILED; |
| 339 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 340 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 341 | /* initialize some data */ |
| 342 | EAS_HWMemSet(pEASData, 0, sizeof(S_EAS_DATA)); |
| 343 | pEASData->staticMemoryModel = (EAS_BOOL8) staticMemoryModel; |
| 344 | pEASData->hwInstData = pHWInstData; |
| 345 | pEASData->renderTime = 0; |
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 | /* set header search flag */ |
| 348 | #ifdef FILE_HEADER_SEARCH |
| 349 | pEASData->searchHeaderFlag = EAS_TRUE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 350 | #endif |
| 351 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 352 | /* initalize parameters */ |
| 353 | EAS_SetVolume(pEASData, NULL, DEFAULT_VOLUME); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 354 | |
| 355 | #ifdef _METRICS_ENABLED |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 356 | /* initalize the metrics module */ |
| 357 | pEASData->pMetricsModule = EAS_CMEnumOptModules(EAS_MODULE_METRICS); |
| 358 | if (pEASData->pMetricsModule != NULL) |
| 359 | { |
| 360 | if ((result = (*pEASData->pMetricsModule->pfInit)(pEASData, &pEASData->pMetricsData)) != EAS_SUCCESS) |
| 361 | { |
| 362 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Error %ld initializing metrics module\n", result); */ } |
| 363 | return result; |
| 364 | } |
| 365 | } |
| 366 | #endif |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 367 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 368 | /* initailize the voice manager & synthesizer */ |
| 369 | if ((result = VMInitialize(pEASData)) != EAS_SUCCESS) |
| 370 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 371 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 372 | /* initialize mix engine */ |
| 373 | if ((result = EAS_MixEngineInit(pEASData)) != EAS_SUCCESS) |
| 374 | { |
| 375 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Error %ld starting up mix engine\n", result); */ } |
| 376 | return result; |
| 377 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 378 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 379 | /* initialize effects modules */ |
| 380 | for (module = 0; module < NUM_EFFECTS_MODULES; module++) |
| 381 | { |
| 382 | pEASData->effectsModules[module].effect = EAS_CMEnumFXModules(module); |
| 383 | if (pEASData->effectsModules[module].effect != NULL) |
| 384 | { |
| 385 | if ((result = (*pEASData->effectsModules[module].effect->pfInit)(pEASData, &pEASData->effectsModules[module].effectData)) != EAS_SUCCESS) |
| 386 | { |
| 387 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_FATAL, "Initialization of effects module %d returned %d\n", module, result); */ } |
| 388 | return result; |
| 389 | } |
| 390 | } |
| 391 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 392 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 393 | /* initialize PCM engine */ |
| 394 | if ((result = EAS_PEInit(pEASData)) != EAS_SUCCESS) |
| 395 | { |
| 396 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_FATAL, "EAS_PEInit failed with error code %ld\n", result); */ } |
| 397 | return result; |
| 398 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 399 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 400 | /* return instance data pointer to host */ |
| 401 | *ppEASData = pEASData; |
| 402 | |
| 403 | return EAS_SUCCESS; |
| 404 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 405 | |
| 406 | /*---------------------------------------------------------------------------- |
| 407 | * EAS_Shutdown() |
| 408 | *---------------------------------------------------------------------------- |
| 409 | * Purpose: |
| 410 | * Shuts down the library. Deallocates any memory associated with the |
| 411 | * synthesizer (dynamic memory model only) |
| 412 | * |
| 413 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 414 | * pEASData - handle to data for this instance |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 415 | * |
| 416 | * Outputs: |
| 417 | * |
| 418 | *---------------------------------------------------------------------------- |
| 419 | */ |
| 420 | EAS_PUBLIC EAS_RESULT EAS_Shutdown (EAS_DATA_HANDLE pEASData) |
| 421 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 422 | /* check for NULL handle */ |
| 423 | if (!pEASData) |
| 424 | return EAS_ERROR_HANDLE_INTEGRITY; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 425 | |
liuchao | 6040cfa | 2017-04-13 10:48:51 +0800 | [diff] [blame] | 426 | /* establish pointers */ |
| 427 | EAS_HW_DATA_HANDLE hwInstData = pEASData->hwInstData; |
| 428 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 429 | /* if there are streams open, close them */ |
liuchao | 6040cfa | 2017-04-13 10:48:51 +0800 | [diff] [blame] | 430 | EAS_RESULT reportResult = EAS_SUCCESS; |
| 431 | |
| 432 | EAS_RESULT result; |
| 433 | EAS_INT i; |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 434 | for (i = 0; i < MAX_NUMBER_STREAMS; i++) |
| 435 | { |
| 436 | if (pEASData->streams[i].pParserModule && pEASData->streams[i].handle) |
| 437 | { |
| 438 | if ((result = (*((S_FILE_PARSER_INTERFACE*)(pEASData->streams[i].pParserModule))->pfClose)(pEASData, pEASData->streams[i].handle)) != EAS_SUCCESS) |
| 439 | { |
| 440 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Error %ld shutting down parser module\n", result); */ } |
| 441 | reportResult = result; |
| 442 | } |
| 443 | } |
| 444 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 445 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 446 | /* shutdown PCM engine */ |
| 447 | if ((result = EAS_PEShutdown(pEASData)) != EAS_SUCCESS) |
| 448 | { |
| 449 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Error %ld shutting down PCM engine\n", result); */ } |
| 450 | if (reportResult == EAS_SUCCESS) |
| 451 | reportResult = result; |
| 452 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 453 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 454 | /* shutdown mix engine */ |
| 455 | if ((result = EAS_MixEngineShutdown(pEASData)) != EAS_SUCCESS) |
| 456 | { |
| 457 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Error %ld shutting down mix engine\n", result); */ } |
| 458 | if (reportResult == EAS_SUCCESS) |
| 459 | reportResult = result; |
| 460 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 461 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 462 | /* shutdown effects modules */ |
| 463 | for (i = 0; i < NUM_EFFECTS_MODULES; i++) |
| 464 | { |
| 465 | if (pEASData->effectsModules[i].effect) |
| 466 | { |
| 467 | if ((result = (*pEASData->effectsModules[i].effect->pfShutdown)(pEASData, pEASData->effectsModules[i].effectData)) != EAS_SUCCESS) |
| 468 | { |
| 469 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_FATAL, "Shutdown of effects module %d returned %d\n", i, result); */ } |
| 470 | if (reportResult == EAS_SUCCESS) |
| 471 | reportResult = result; |
| 472 | } |
| 473 | } |
| 474 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 475 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 476 | /* shutdown the voice manager & synthesizer */ |
| 477 | VMShutdown(pEASData); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 478 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 479 | #ifdef _METRICS_ENABLED |
| 480 | /* shutdown the metrics module */ |
| 481 | if (pEASData->pMetricsModule != NULL) |
| 482 | { |
| 483 | if ((result = (*pEASData->pMetricsModule->pfShutdown)(pEASData, pEASData->pMetricsData)) != EAS_SUCCESS) |
| 484 | { |
| 485 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Error %ld shutting down metrics module\n", result); */ } |
| 486 | if (reportResult == EAS_SUCCESS) |
| 487 | reportResult = result; |
| 488 | } |
| 489 | } |
| 490 | #endif |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 491 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 492 | /* release allocated memory */ |
| 493 | if (!pEASData->staticMemoryModel) |
| 494 | EAS_HWFree(hwInstData, pEASData); |
| 495 | |
| 496 | /* shutdown host wrappers */ |
| 497 | if (hwInstData) |
| 498 | { |
| 499 | if ((result = EAS_HWShutdown(hwInstData)) != EAS_SUCCESS) |
| 500 | { |
| 501 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Error %ld shutting down host wrappers\n", result); */ } |
| 502 | if (reportResult == EAS_SUCCESS) |
| 503 | reportResult = result; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | return reportResult; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | #ifdef JET_INTERFACE |
| 511 | /*---------------------------------------------------------------------------- |
| 512 | * EAS_OpenJETStream() |
| 513 | *---------------------------------------------------------------------------- |
| 514 | * Private interface for JET to open an SMF stream with an offset |
| 515 | *---------------------------------------------------------------------------- |
| 516 | */ |
| 517 | EAS_RESULT EAS_OpenJETStream (EAS_DATA_HANDLE pEASData, EAS_FILE_HANDLE fileHandle, EAS_I32 offset, EAS_HANDLE *ppStream) |
| 518 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 519 | EAS_RESULT result; |
| 520 | EAS_VOID_PTR streamHandle; |
| 521 | S_FILE_PARSER_INTERFACE *pParserModule; |
| 522 | EAS_INT streamNum; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 523 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 524 | /* allocate a stream */ |
| 525 | if ((streamNum = EAS_AllocateStream(pEASData)) < 0) |
| 526 | return EAS_ERROR_MAX_STREAMS_OPEN; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 527 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 528 | /* check Configuration Module for SMF parser */ |
| 529 | *ppStream = NULL; |
| 530 | streamHandle = NULL; |
| 531 | pParserModule = (S_FILE_PARSER_INTERFACE *) EAS_CMEnumModules(0); |
| 532 | if (pParserModule == NULL) |
| 533 | return EAS_ERROR_UNRECOGNIZED_FORMAT; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 534 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 535 | /* see if SMF parser recognizes the file */ |
| 536 | if ((result = (*pParserModule->pfCheckFileType)(pEASData, fileHandle, &streamHandle, offset)) != EAS_SUCCESS) |
| 537 | { |
| 538 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "CheckFileType returned error %ld\n", result); */ } |
| 539 | return result; |
| 540 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 541 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 542 | /* parser recognized the file, return the handle */ |
| 543 | if (streamHandle) |
| 544 | { |
| 545 | EAS_InitStream(&pEASData->streams[streamNum], pParserModule, streamHandle); |
| 546 | *ppStream = &pEASData->streams[streamNum]; |
| 547 | return EAS_SUCCESS; |
| 548 | } |
| 549 | |
| 550 | return EAS_ERROR_UNRECOGNIZED_FORMAT; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 551 | } |
| 552 | #endif |
| 553 | |
| 554 | /*---------------------------------------------------------------------------- |
| 555 | * EAS_OpenFile() |
| 556 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 557 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 558 | * Opens a file for audio playback. |
| 559 | * |
| 560 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 561 | * pEASData - pointer to overall EAS data structure |
| 562 | * pHandle - pointer to file handle |
| 563 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 564 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 565 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 566 | * |
| 567 | * Side Effects: |
| 568 | * |
| 569 | *---------------------------------------------------------------------------- |
| 570 | */ |
| 571 | EAS_PUBLIC EAS_RESULT EAS_OpenFile (EAS_DATA_HANDLE pEASData, EAS_FILE_LOCATOR locator, EAS_HANDLE *ppStream) |
| 572 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 573 | EAS_RESULT result; |
| 574 | EAS_FILE_HANDLE fileHandle; |
| 575 | EAS_VOID_PTR streamHandle; |
| 576 | S_FILE_PARSER_INTERFACE *pParserModule; |
| 577 | EAS_INT streamNum; |
| 578 | EAS_INT moduleNum; |
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 | /* open the file */ |
| 581 | if ((result = EAS_HWOpenFile(pEASData->hwInstData, locator, &fileHandle, EAS_FILE_READ)) != 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 | /* allocate a stream */ |
| 585 | if ((streamNum = EAS_AllocateStream(pEASData)) < 0) |
gbhakteX | a965c0d | 2012-07-26 18:53:25 +0530 | [diff] [blame] | 586 | { |
| 587 | /* Closing the opened file as stream allocation failed */ |
| 588 | EAS_HWCloseFile(pEASData->hwInstData, fileHandle); |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 589 | return EAS_ERROR_MAX_STREAMS_OPEN; |
gbhakteX | a965c0d | 2012-07-26 18:53:25 +0530 | [diff] [blame] | 590 | } |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 591 | /* check Configuration Module for file parsers */ |
| 592 | pParserModule = NULL; |
| 593 | *ppStream = NULL; |
| 594 | streamHandle = NULL; |
| 595 | for (moduleNum = 0; ; moduleNum++) |
| 596 | { |
| 597 | pParserModule = (S_FILE_PARSER_INTERFACE *) EAS_CMEnumModules(moduleNum); |
| 598 | if (pParserModule == NULL) |
| 599 | break; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 600 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 601 | /* see if this parser recognizes it */ |
| 602 | if ((result = (*pParserModule->pfCheckFileType)(pEASData, fileHandle, &streamHandle, 0L)) != EAS_SUCCESS) |
| 603 | { |
gbhakteX | a965c0d | 2012-07-26 18:53:25 +0530 | [diff] [blame] | 604 | /* Closing the opened file as file type check failed */ |
| 605 | EAS_HWCloseFile(pEASData->hwInstData, fileHandle); |
| 606 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 607 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "CheckFileType returned error %ld\n", result); */ } |
| 608 | return result; |
| 609 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 610 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 611 | /* parser recognized the file, return the handle */ |
| 612 | if (streamHandle) |
| 613 | { |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 614 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 615 | /* save the parser pointer and file handle */ |
| 616 | EAS_InitStream(&pEASData->streams[streamNum], pParserModule, streamHandle); |
| 617 | *ppStream = &pEASData->streams[streamNum]; |
| 618 | return EAS_SUCCESS; |
| 619 | } |
| 620 | |
| 621 | /* rewind the file for the next parser */ |
| 622 | if ((result = EAS_HWFileSeek(pEASData->hwInstData, fileHandle, 0L)) != EAS_SUCCESS) |
gbhakteX | a965c0d | 2012-07-26 18:53:25 +0530 | [diff] [blame] | 623 | { |
| 624 | /* Closing the opened file as file seek failed */ |
| 625 | EAS_HWCloseFile(pEASData->hwInstData, fileHandle); |
| 626 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 627 | return result; |
gbhakteX | a965c0d | 2012-07-26 18:53:25 +0530 | [diff] [blame] | 628 | } |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | /* no parser was able to recognize the file, close it and return an error */ |
| 632 | EAS_HWCloseFile(pEASData->hwInstData, fileHandle); |
| 633 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "No parser recognized the requested file\n"); */ } |
| 634 | return EAS_ERROR_UNRECOGNIZED_FORMAT; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 635 | } |
| 636 | |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 637 | /*---------------------------------------------------------------------------- |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 638 | * EAS_Prepare() |
| 639 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 640 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 641 | * Prepares the synthesizer to play the file or stream. Parses the first |
| 642 | * frame of data from the file and arms the synthesizer. |
| 643 | * |
| 644 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 645 | * pEASData - pointer to overall EAS data structure |
| 646 | * handle - file or stream handle |
| 647 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 648 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 649 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 650 | * |
| 651 | * Side Effects: |
| 652 | * |
| 653 | *---------------------------------------------------------------------------- |
| 654 | */ |
| 655 | EAS_PUBLIC EAS_RESULT EAS_Prepare (EAS_DATA_HANDLE pEASData, EAS_HANDLE pStream) |
| 656 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 657 | S_FILE_PARSER_INTERFACE *pParserModule; |
| 658 | EAS_STATE state; |
| 659 | EAS_RESULT result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 660 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 661 | pParserModule = (S_FILE_PARSER_INTERFACE*) pStream->pParserModule; |
| 662 | if (pParserModule == NULL) |
| 663 | return EAS_ERROR_FEATURE_NOT_AVAILABLE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 664 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 665 | /* check for valid state */ |
| 666 | result = pParserModule->pfState(pEASData, pStream->handle, &state); |
| 667 | if (result == EAS_SUCCESS) |
| 668 | { |
| 669 | /* prepare the stream */ |
| 670 | if (state == EAS_STATE_OPEN) |
| 671 | { |
| 672 | pParserModule = (S_FILE_PARSER_INTERFACE*) pStream->pParserModule; |
| 673 | result = (*pParserModule->pfPrepare)(pEASData, pStream->handle); |
| 674 | |
| 675 | /* set volume */ |
| 676 | if (result == EAS_SUCCESS) |
| 677 | result = EAS_SetVolume(pEASData, pStream, pStream->volume); |
| 678 | } |
| 679 | else |
| 680 | result = EAS_ERROR_NOT_VALID_IN_THIS_STATE; |
| 681 | |
| 682 | } |
| 683 | |
| 684 | return result; |
| 685 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 686 | |
| 687 | /*---------------------------------------------------------------------------- |
| 688 | * EAS_Render() |
| 689 | *---------------------------------------------------------------------------- |
| 690 | * Purpose: |
| 691 | * Parse the Midi data and render PCM audio data. |
| 692 | * |
| 693 | * Inputs: |
| 694 | * pEASData - buffer for internal EAS data |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 695 | * pOut - output buffer pointer |
| 696 | * nNumRequested - requested num samples to generate |
| 697 | * pnNumGenerated - actual number of samples generated |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 698 | * |
| 699 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 700 | * EAS_SUCCESS if PCM data was successfully rendered |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 701 | * |
| 702 | *---------------------------------------------------------------------------- |
| 703 | */ |
| 704 | EAS_PUBLIC EAS_RESULT EAS_Render (EAS_DATA_HANDLE pEASData, EAS_PCM *pOut, EAS_I32 numRequested, EAS_I32 *pNumGenerated) |
| 705 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 706 | S_FILE_PARSER_INTERFACE *pParserModule; |
| 707 | EAS_RESULT result; |
| 708 | EAS_I32 voicesRendered; |
| 709 | EAS_STATE parserState; |
| 710 | EAS_INT streamNum; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 711 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 712 | /* assume no samples generated and reset workload */ |
| 713 | *pNumGenerated = 0; |
| 714 | VMInitWorkload(pEASData->pVoiceMgr); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 715 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 716 | /* no support for other buffer sizes yet */ |
| 717 | if (numRequested != BUFFER_SIZE_IN_MONO_SAMPLES) |
| 718 | { |
| 719 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "This library supports only %ld samples in buffer, host requested %ld samples\n", |
| 720 | (EAS_I32) BUFFER_SIZE_IN_MONO_SAMPLES, numRequested); */ } |
| 721 | return EAS_BUFFER_SIZE_MISMATCH; |
| 722 | } |
| 723 | |
| 724 | #ifdef _METRICS_ENABLED |
| 725 | /* start performance counter */ |
| 726 | if (pEASData->pMetricsData) |
| 727 | (*pEASData->pMetricsModule->pfStartTimer)(pEASData->pMetricsData, EAS_PM_TOTAL_TIME); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 728 | #endif |
| 729 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 730 | /* prep the frame buffer, do mix engine prep only if TRUE */ |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 731 | #ifdef _SPLIT_ARCHITECTURE |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 732 | if (VMStartFrame(pEASData)) |
| 733 | EAS_MixEnginePrep(pEASData, numRequested); |
| 734 | #else |
| 735 | /* prep the mix engine */ |
| 736 | EAS_MixEnginePrep(pEASData, numRequested); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 737 | #endif |
| 738 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 739 | /* save the output buffer pointer */ |
| 740 | pEASData->pOutputAudioBuffer = pOut; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 741 | |
| 742 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 743 | #ifdef _METRICS_ENABLED |
| 744 | /* start performance counter */ |
| 745 | if (pEASData->pMetricsData) |
| 746 | (*pEASData->pMetricsModule->pfStartTimer)(pEASData->pMetricsData, EAS_PM_PARSE_TIME); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 747 | #endif |
| 748 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 749 | /* if we haven't finished parsing from last time, do it now */ |
| 750 | /* need to parse another frame of events before we render again */ |
| 751 | for (streamNum = 0; streamNum < MAX_NUMBER_STREAMS; streamNum++) |
| 752 | { |
| 753 | /* clear the locate flag */ |
| 754 | pEASData->streams[streamNum].streamFlags &= ~STREAM_FLAGS_LOCATE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 755 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 756 | if (pEASData->streams[streamNum].pParserModule) |
| 757 | { |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 758 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 759 | /* establish pointer to parser module */ |
| 760 | pParserModule = pEASData->streams[streamNum].pParserModule; |
| 761 | |
Marco Nelissen | 2fa59c8 | 2020-04-22 09:33:28 -0700 | [diff] [blame] | 762 | #ifdef JET_INTERFACE |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 763 | /* handle pause */ |
| 764 | if (pEASData->streams[streamNum].streamFlags & STREAM_FLAGS_PAUSE) |
| 765 | { |
| 766 | if (pParserModule->pfPause) |
| 767 | result = pParserModule->pfPause(pEASData, pEASData->streams[streamNum].handle); |
| 768 | pEASData->streams[streamNum].streamFlags &= ~STREAM_FLAGS_PAUSE; |
| 769 | } |
Marco Nelissen | 2fa59c8 | 2020-04-22 09:33:28 -0700 | [diff] [blame] | 770 | #endif |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 771 | |
| 772 | /* get current state */ |
| 773 | if ((result = (*pParserModule->pfState)(pEASData, pEASData->streams[streamNum].handle, &parserState)) != EAS_SUCCESS) |
| 774 | return result; |
| 775 | |
Marco Nelissen | 2fa59c8 | 2020-04-22 09:33:28 -0700 | [diff] [blame] | 776 | #ifdef JET_INTERFACE |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 777 | /* handle resume */ |
| 778 | if (parserState == EAS_STATE_PAUSED) |
| 779 | { |
| 780 | if (pEASData->streams[streamNum].streamFlags & STREAM_FLAGS_RESUME) |
| 781 | { |
| 782 | if (pParserModule->pfResume) |
| 783 | result = pParserModule->pfResume(pEASData, pEASData->streams[streamNum].handle); |
| 784 | pEASData->streams[streamNum].streamFlags &= ~STREAM_FLAGS_RESUME; |
| 785 | } |
| 786 | } |
Marco Nelissen | 2fa59c8 | 2020-04-22 09:33:28 -0700 | [diff] [blame] | 787 | #endif |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 788 | |
| 789 | /* if necessary, parse stream */ |
| 790 | if ((pEASData->streams[streamNum].streamFlags & STREAM_FLAGS_PARSED) == 0) |
| 791 | if ((result = EAS_ParseEvents(pEASData, &pEASData->streams[streamNum], pEASData->streams[streamNum].time + pEASData->streams[streamNum].frameLength, eParserModePlay)) != EAS_SUCCESS) |
| 792 | return result; |
| 793 | |
| 794 | /* check for an early abort */ |
| 795 | if ((pEASData->streams[streamNum].streamFlags) == 0) |
| 796 | { |
| 797 | |
| 798 | #ifdef _METRICS_ENABLED |
| 799 | /* stop performance counter */ |
| 800 | if (pEASData->pMetricsData) |
| 801 | (*pEASData->pMetricsModule->pfStartTimer)(pEASData->pMetricsData, EAS_PM_TOTAL_TIME); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 802 | #endif |
| 803 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 804 | return EAS_SUCCESS; |
| 805 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 806 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 807 | /* check for repeat */ |
| 808 | if (pEASData->streams[streamNum].repeatCount) |
| 809 | { |
| 810 | |
| 811 | /* check for stopped state */ |
| 812 | if ((result = (*pParserModule->pfState)(pEASData, pEASData->streams[streamNum].handle, &parserState)) != EAS_SUCCESS) |
| 813 | return result; |
| 814 | if (parserState == EAS_STATE_STOPPED) |
| 815 | { |
| 816 | |
| 817 | /* decrement repeat count, unless it is negative */ |
| 818 | if (pEASData->streams[streamNum].repeatCount > 0) |
| 819 | pEASData->streams[streamNum].repeatCount--; |
| 820 | |
| 821 | /* reset the parser */ |
| 822 | if ((result = (*pParserModule->pfReset)(pEASData, pEASData->streams[streamNum].handle)) != EAS_SUCCESS) |
| 823 | return result; |
| 824 | pEASData->streams[streamNum].time = 0; |
| 825 | } |
| 826 | } |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | #ifdef _METRICS_ENABLED |
| 831 | /* stop performance counter */ |
| 832 | if (pEASData->pMetricsData) |
| 833 | (void)(*pEASData->pMetricsModule->pfStopTimer)(pEASData->pMetricsData, EAS_PM_PARSE_TIME); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 834 | #endif |
| 835 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 836 | #ifdef _METRICS_ENABLED |
| 837 | /* start the render timer */ |
| 838 | if (pEASData->pMetricsData) |
| 839 | (*pEASData->pMetricsModule->pfStartTimer)(pEASData->pMetricsData, EAS_PM_RENDER_TIME); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 840 | #endif |
| 841 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 842 | /* render audio */ |
| 843 | if ((result = VMRender(pEASData->pVoiceMgr, BUFFER_SIZE_IN_MONO_SAMPLES, pEASData->pMixBuffer, &voicesRendered)) != EAS_SUCCESS) |
| 844 | { |
| 845 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "pfRender function returned error %ld\n", result); */ } |
| 846 | return result; |
| 847 | } |
| 848 | |
| 849 | #ifdef _METRICS_ENABLED |
| 850 | /* stop the render timer */ |
| 851 | if (pEASData->pMetricsData) { |
| 852 | (*pEASData->pMetricsModule->pfIncrementCounter)(pEASData->pMetricsData, EAS_PM_FRAME_COUNT, 1); |
| 853 | (void)(*pEASData->pMetricsModule->pfStopTimer)(pEASData->pMetricsData, EAS_PM_RENDER_TIME); |
| 854 | (*pEASData->pMetricsModule->pfIncrementCounter)(pEASData->pMetricsData, EAS_PM_TOTAL_VOICE_COUNT, (EAS_U32) voicesRendered); |
| 855 | (void)(*pEASData->pMetricsModule->pfRecordMaxValue)(pEASData->pMetricsData, EAS_PM_MAX_VOICES, (EAS_U32) voicesRendered); |
| 856 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 857 | #endif |
| 858 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 859 | //2 Do we really need frameParsed? |
| 860 | /* need to parse another frame of events before we render again */ |
| 861 | for (streamNum = 0; streamNum < MAX_NUMBER_STREAMS; streamNum++) |
| 862 | if (pEASData->streams[streamNum].pParserModule != NULL) |
| 863 | pEASData->streams[streamNum].streamFlags &= ~STREAM_FLAGS_PARSED; |
| 864 | |
| 865 | #ifdef _METRICS_ENABLED |
| 866 | /* start performance counter */ |
| 867 | if (pEASData->pMetricsData) |
| 868 | (*pEASData->pMetricsModule->pfStartTimer)(pEASData->pMetricsData, EAS_PM_STREAM_TIME); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 869 | #endif |
| 870 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 871 | #ifdef _METRICS_ENABLED |
| 872 | /* stop the stream timer */ |
| 873 | if (pEASData->pMetricsData) |
| 874 | (void)(*pEASData->pMetricsModule->pfStopTimer)(pEASData->pMetricsData, EAS_PM_STREAM_TIME); |
| 875 | #endif |
| 876 | |
| 877 | #ifdef _METRICS_ENABLED |
| 878 | /* start the post timer */ |
| 879 | if (pEASData->pMetricsData) |
| 880 | (*pEASData->pMetricsModule->pfStartTimer)(pEASData->pMetricsData, EAS_PM_POST_TIME); |
| 881 | #endif |
| 882 | |
| 883 | /* for split architecture, send DSP vectors. Do post only if return is TRUE */ |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 884 | #ifdef _SPLIT_ARCHITECTURE |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 885 | if (VMEndFrame(pEASData)) |
| 886 | { |
| 887 | /* now do post-processing */ |
| 888 | EAS_MixEnginePost(pEASData, numRequested); |
| 889 | *pNumGenerated = numRequested; |
| 890 | } |
| 891 | #else |
| 892 | /* now do post-processing */ |
| 893 | EAS_MixEnginePost(pEASData, numRequested); |
| 894 | *pNumGenerated = numRequested; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 895 | #endif |
| 896 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 897 | #ifdef _METRICS_ENABLED |
| 898 | /* stop the post timer */ |
| 899 | if (pEASData->pMetricsData) |
| 900 | (void)(*pEASData->pMetricsModule->pfStopTimer)(pEASData->pMetricsData, EAS_PM_POST_TIME); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 901 | #endif |
| 902 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 903 | /* advance render time */ |
| 904 | pEASData->renderTime += AUDIO_FRAME_LENGTH; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 905 | |
| 906 | #if 0 |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 907 | /* dump workload for debug */ |
| 908 | if (pEASData->pVoiceMgr->workload) |
| 909 | { /* dpp: EAS_ReportEx(_EAS_SEVERITY_DETAIL, "Workload = %d\n", pEASData->pVoiceMgr->workload); */ } |
| 910 | #endif |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 911 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 912 | #ifdef _METRICS_ENABLED |
| 913 | /* stop performance counter */ |
| 914 | if (pEASData->pMetricsData) |
| 915 | { |
| 916 | PERF_TIMER temp; |
| 917 | temp = (*pEASData->pMetricsModule->pfStopTimer)(pEASData->pMetricsData, EAS_PM_TOTAL_TIME); |
| 918 | |
| 919 | /* if max render time, record the number of voices and time */ |
| 920 | if ((*pEASData->pMetricsModule->pfRecordMaxValue) |
| 921 | (pEASData->pMetricsData, EAS_PM_MAX_CYCLES, (EAS_U32) temp)) |
| 922 | { |
| 923 | (*pEASData->pMetricsModule->pfRecordValue)(pEASData->pMetricsData, EAS_PM_MAX_CYCLES_VOICES, (EAS_U32) voicesRendered); |
| 924 | (*pEASData->pMetricsModule->pfRecordValue)(pEASData->pMetricsData, EAS_PM_MAX_CYCLES_TIME, (EAS_I32) (pEASData->renderTime >> 8)); |
| 925 | } |
| 926 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 927 | #endif |
| 928 | |
| 929 | #ifdef JET_INTERFACE |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 930 | /* let JET to do its thing */ |
| 931 | if (pEASData->jetHandle != NULL) |
| 932 | { |
| 933 | result = JET_Process(pEASData); |
| 934 | if (result != EAS_SUCCESS) |
| 935 | return result; |
| 936 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 937 | #endif |
| 938 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 939 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 940 | } |
| 941 | |
Marco Nelissen | 2fa59c8 | 2020-04-22 09:33:28 -0700 | [diff] [blame] | 942 | #ifdef JET_INTERFACE |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 943 | /*---------------------------------------------------------------------------- |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 944 | * EAS_SetTransposition) |
| 945 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 946 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 947 | * Sets the key tranposition for the synthesizer. Transposes all |
| 948 | * melodic instruments by the specified amount. Range is limited |
| 949 | * to +/-12 semitones. |
| 950 | * |
| 951 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 952 | * pEASData - handle to data for this instance |
| 953 | * handle - handle to stream |
| 954 | * transposition - +/-12 semitones |
| 955 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 956 | * Outputs: |
| 957 | * |
| 958 | * Side Effects: |
| 959 | * |
| 960 | *---------------------------------------------------------------------------- |
| 961 | */ |
| 962 | EAS_PUBLIC EAS_RESULT EAS_SetTransposition (EAS_DATA_HANDLE pEASData, EAS_HANDLE pStream, EAS_I32 transposition) |
| 963 | { |
| 964 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 965 | /* check range */ |
| 966 | if ((transposition < -12) || (transposition > 12)) |
| 967 | return EAS_ERROR_INVALID_PARAMETER; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 968 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 969 | if (!EAS_StreamReady(pEASData, pStream)) |
| 970 | return EAS_ERROR_NOT_VALID_IN_THIS_STATE; |
| 971 | return EAS_IntSetStrmParam(pEASData, pStream, PARSER_DATA_TRANSPOSITION, transposition); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 972 | } |
Marco Nelissen | 2fa59c8 | 2020-04-22 09:33:28 -0700 | [diff] [blame] | 973 | #endif |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 974 | |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 975 | /*---------------------------------------------------------------------------- |
| 976 | * EAS_ParseEvents() |
| 977 | *---------------------------------------------------------------------------- |
| 978 | * Purpose: |
| 979 | * Parse events in the current streams until the desired time is reached. |
| 980 | * |
| 981 | * Inputs: |
| 982 | * pEASData - buffer for internal EAS data |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 983 | * endTime - stop parsing if this time is reached |
| 984 | * parseMode - play, locate, or metadata |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 985 | * |
| 986 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 987 | * EAS_SUCCESS if PCM data was successfully rendered |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 988 | * |
| 989 | *---------------------------------------------------------------------------- |
| 990 | */ |
| 991 | static EAS_RESULT EAS_ParseEvents (S_EAS_DATA *pEASData, EAS_HANDLE pStream, EAS_U32 endTime, EAS_INT parseMode) |
| 992 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 993 | S_FILE_PARSER_INTERFACE *pParserModule; |
| 994 | EAS_RESULT result; |
| 995 | EAS_I32 parserState; |
| 996 | EAS_BOOL done; |
| 997 | EAS_INT yieldCount = YIELD_EVENT_COUNT; |
| 998 | EAS_U32 time = 0; |
Phil Burk | 27151ca | 2018-08-18 11:52:03 -0700 | [diff] [blame] | 999 | |
Phil Burk | c71f73a | 2018-06-19 08:19:05 -0700 | [diff] [blame] | 1000 | // This constant is the maximum number of events that can be processed in a single time slice. |
| 1001 | // A typical ringtone will contain a few events per time slice. |
| 1002 | // Extremely dense ringtones might go up to 50 events. |
| 1003 | // If we see this many events then the file is probably stuck in an infinite loop |
Phil Burk | 27151ca | 2018-08-18 11:52:03 -0700 | [diff] [blame] | 1004 | // and should be aborted. |
| 1005 | static const EAS_INT MAX_EVENT_COUNT = 100000; |
Phil Burk | c71f73a | 2018-06-19 08:19:05 -0700 | [diff] [blame] | 1006 | EAS_INT eventCount = 0; |
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 | /* does this parser have a time function? */ |
| 1009 | pParserModule = pStream->pParserModule; |
| 1010 | if (pParserModule->pfTime == NULL) |
| 1011 | { |
| 1012 | /* check state */ |
| 1013 | if ((result = (*pParserModule->pfState)(pEASData, pStream->handle, &parserState)) != EAS_SUCCESS) |
| 1014 | return result; |
| 1015 | /* if play state, advance time */ |
| 1016 | if ((parserState >= EAS_STATE_READY) && (parserState <= EAS_STATE_PAUSING)) |
| 1017 | pStream->time += pStream->frameLength; |
| 1018 | done = EAS_TRUE; |
| 1019 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1020 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1021 | /* assume we're not done, in case we abort out */ |
| 1022 | else |
| 1023 | { |
| 1024 | pStream->streamFlags &= ~STREAM_FLAGS_PARSED; |
| 1025 | done = EAS_FALSE; |
| 1026 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1027 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1028 | while (!done) |
| 1029 | { |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1030 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1031 | /* check for stopped state */ |
| 1032 | if ((result = (*pParserModule->pfState)(pEASData, pStream->handle, &parserState)) != EAS_SUCCESS) |
| 1033 | return result; |
| 1034 | if (parserState > EAS_STATE_PLAY) |
| 1035 | { |
| 1036 | /* save current time if we're not in play mode */ |
| 1037 | if (parseMode != eParserModePlay) |
| 1038 | pStream->time = time << 8; |
| 1039 | done = EAS_TRUE; |
| 1040 | break; |
| 1041 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1042 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1043 | /* get the next event time */ |
| 1044 | if (pParserModule->pfTime) |
| 1045 | { |
| 1046 | if ((result = (*pParserModule->pfTime)(pEASData, pStream->handle, &time)) != EAS_SUCCESS) |
| 1047 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1048 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1049 | /* if next event is within this frame, parse it */ |
| 1050 | if (time < (endTime >> 8)) |
| 1051 | { |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1052 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1053 | /* parse the next event */ |
Phil Burk | c71f73a | 2018-06-19 08:19:05 -0700 | [diff] [blame] | 1054 | if (pParserModule->pfEvent) { |
| 1055 | if ((result = (*pParserModule->pfEvent)(pEASData, pStream->handle, parseMode)) |
| 1056 | != EAS_SUCCESS) { |
| 1057 | ALOGE("%s() pfEvent returned %ld", __func__, result); |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1058 | return result; |
Phil Burk | c71f73a | 2018-06-19 08:19:05 -0700 | [diff] [blame] | 1059 | } |
| 1060 | } |
Phil Burk | 27151ca | 2018-08-18 11:52:03 -0700 | [diff] [blame] | 1061 | |
| 1062 | // An infinite loop within a ringtone file can cause this function |
Phil Burk | c71f73a | 2018-06-19 08:19:05 -0700 | [diff] [blame] | 1063 | // to loop forever. Try to detect that and return an error. |
Phil Burk | 27151ca | 2018-08-18 11:52:03 -0700 | [diff] [blame] | 1064 | // Only check when playing. Otherwise a very large file could be rejected |
| 1065 | // when scanning the entire file in a single call to this function. |
| 1066 | // OTA files will only do infinite loops when in eParserModePlay. |
| 1067 | if (++eventCount >= MAX_EVENT_COUNT && parseMode == eParserModePlay) { |
| 1068 | ALOGE("%s() aborting, %d events. Infinite loop in song file?!", |
Phil Burk | c71f73a | 2018-06-19 08:19:05 -0700 | [diff] [blame] | 1069 | __func__, eventCount); |
| 1070 | android_errorWriteLog(0x534e4554, "68664359"); |
| 1071 | return EAS_ERROR_FILE_POS; |
| 1072 | } |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1073 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1074 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1075 | /* no more events in this frame, advance time */ |
| 1076 | else |
| 1077 | { |
| 1078 | pStream->time = endTime; |
| 1079 | done = EAS_TRUE; |
| 1080 | } |
| 1081 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1082 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1083 | /* check for max workload exceeded */ |
| 1084 | if (VMCheckWorkload(pEASData->pVoiceMgr)) |
| 1085 | { |
| 1086 | /* stop even though we may not have parsed |
| 1087 | * all the events in this frame. The parser will try to |
| 1088 | * catch up on the next frame. |
| 1089 | */ |
| 1090 | break; |
| 1091 | } |
| 1092 | |
| 1093 | /* give host a chance for an early abort */ |
| 1094 | if (--yieldCount == 0) |
| 1095 | { |
| 1096 | if (EAS_HWYield(pEASData->hwInstData)) |
| 1097 | break; |
| 1098 | yieldCount = YIELD_EVENT_COUNT; |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | /* if no early abort, parsing is complete for this frame */ |
| 1103 | if (done) |
| 1104 | pStream->streamFlags |= STREAM_FLAGS_PARSED; |
| 1105 | |
| 1106 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | /*---------------------------------------------------------------------------- |
| 1110 | * EAS_ParseMetaData() |
| 1111 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1112 | * Purpose: |
| 1113 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1114 | * |
| 1115 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1116 | * pEASData - pointer to overall EAS data structure |
| 1117 | * handle - file or stream handle |
| 1118 | * playLength - pointer to variable to store the play length (in msecs) |
| 1119 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1120 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1121 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1122 | * |
| 1123 | * Side Effects: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1124 | * - resets the parser to the start of the file |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1125 | *---------------------------------------------------------------------------- |
| 1126 | */ |
| 1127 | EAS_PUBLIC EAS_RESULT EAS_ParseMetaData (EAS_DATA_HANDLE pEASData, EAS_HANDLE pStream, EAS_I32 *playLength) |
| 1128 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1129 | S_FILE_PARSER_INTERFACE *pParserModule; |
| 1130 | EAS_RESULT result; |
| 1131 | EAS_STATE state; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1132 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1133 | pParserModule = (S_FILE_PARSER_INTERFACE*) pStream->pParserModule; |
| 1134 | if (pParserModule == NULL) |
| 1135 | return EAS_ERROR_FEATURE_NOT_AVAILABLE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1136 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1137 | /* check parser state */ |
| 1138 | if ((result = (*pParserModule->pfState)(pEASData, pStream->handle, &state)) != EAS_SUCCESS) |
| 1139 | return result; |
| 1140 | if (state >= EAS_STATE_OPEN) |
| 1141 | return EAS_ERROR_NOT_VALID_IN_THIS_STATE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1142 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1143 | /* if parser has metadata function, use that */ |
| 1144 | if (pParserModule->pfGetMetaData != NULL) |
| 1145 | return pParserModule->pfGetMetaData(pEASData, pStream->handle, playLength); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1146 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1147 | /* reset the parser to the beginning */ |
| 1148 | if ((result = (*pParserModule->pfReset)(pEASData, pStream->handle)) != EAS_SUCCESS) |
| 1149 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1150 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1151 | /* parse the file to end */ |
| 1152 | pStream->time = 0; |
| 1153 | VMInitWorkload(pEASData->pVoiceMgr); |
| 1154 | if ((result = EAS_ParseEvents(pEASData, pStream, 0x7fffffff, eParserModeMetaData)) != EAS_SUCCESS) |
| 1155 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1156 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1157 | /* get the parser time */ |
| 1158 | if ((result = EAS_GetLocation(pEASData, pStream, playLength)) != EAS_SUCCESS) |
| 1159 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1160 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1161 | /* reset the parser to the beginning */ |
| 1162 | pStream->time = 0; |
| 1163 | return (*pParserModule->pfReset)(pEASData, pStream->handle); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | /*---------------------------------------------------------------------------- |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1167 | * EAS_CloseFile() |
| 1168 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1169 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1170 | * Closes an audio file or stream. Playback should have either paused or |
| 1171 | * completed (EAS_State returns EAS_PAUSED or EAS_STOPPED). |
| 1172 | * |
| 1173 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1174 | * pEASData - pointer to overall EAS data structure |
| 1175 | * handle - file or stream handle |
| 1176 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1177 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1178 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1179 | * |
| 1180 | * Side Effects: |
| 1181 | * |
| 1182 | *---------------------------------------------------------------------------- |
| 1183 | */ |
| 1184 | EAS_PUBLIC EAS_RESULT EAS_CloseFile (EAS_DATA_HANDLE pEASData, EAS_HANDLE pStream) |
| 1185 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1186 | S_FILE_PARSER_INTERFACE *pParserModule; |
| 1187 | EAS_RESULT result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1188 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1189 | /* call the close function */ |
| 1190 | pParserModule = (S_FILE_PARSER_INTERFACE*) pStream->pParserModule; |
| 1191 | if (pParserModule == NULL) |
| 1192 | return EAS_ERROR_FEATURE_NOT_AVAILABLE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1193 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1194 | result = (*pParserModule->pfClose)(pEASData, pStream->handle); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1195 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1196 | /* clear the handle and parser interface pointer */ |
| 1197 | pStream->handle = NULL; |
| 1198 | pStream->pParserModule = NULL; |
| 1199 | return result; |
| 1200 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1201 | |
| 1202 | /*---------------------------------------------------------------------------- |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1203 | * EAS_State() |
| 1204 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1205 | * Purpose: |
| 1206 | * Returns the state of an audio file or stream. |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1207 | * |
| 1208 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1209 | * pEASData - pointer to overall EAS data structure |
| 1210 | * handle - file or stream handle |
| 1211 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1212 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1213 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1214 | * |
| 1215 | * Side Effects: |
| 1216 | * |
| 1217 | *---------------------------------------------------------------------------- |
| 1218 | */ |
| 1219 | EAS_PUBLIC EAS_RESULT EAS_State (EAS_DATA_HANDLE pEASData, EAS_HANDLE pStream, EAS_STATE *pState) |
| 1220 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1221 | S_FILE_PARSER_INTERFACE *pParserModule; |
| 1222 | EAS_RESULT result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1223 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1224 | /* call the parser to return state */ |
| 1225 | pParserModule = (S_FILE_PARSER_INTERFACE*) pStream->pParserModule; |
| 1226 | if (pParserModule == NULL) |
| 1227 | return EAS_ERROR_FEATURE_NOT_AVAILABLE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1228 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1229 | if ((result = (*pParserModule->pfState)(pEASData, pStream->handle, pState)) != EAS_SUCCESS) |
| 1230 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1231 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1232 | /* if repeat count is set for this parser, mask the stopped state from the application */ |
| 1233 | if (pStream->repeatCount && (*pState == EAS_STATE_STOPPED)) |
| 1234 | *pState = EAS_STATE_PLAY; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1235 | |
Marco Nelissen | 3e2bd1f | 2010-12-21 16:00:10 -0800 | [diff] [blame] | 1236 | /* if we're not paused or pausing, we don't need to hide state from host */ |
| 1237 | if (*pState != EAS_STATE_PAUSED && *pState != EAS_STATE_PAUSING) |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1238 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1239 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1240 | /* if stream is about to be paused, report it as paused */ |
| 1241 | if (pStream->streamFlags & STREAM_FLAGS_PAUSE) |
| 1242 | { |
| 1243 | if (pStream->streamFlags & STREAM_FLAGS_LOCATE) |
| 1244 | *pState = EAS_STATE_PAUSED; |
| 1245 | else |
| 1246 | *pState = EAS_STATE_PAUSING; |
| 1247 | } |
| 1248 | |
| 1249 | /* if stream is about to resume, report it as playing */ |
| 1250 | if (pStream->streamFlags & STREAM_FLAGS_RESUME) |
| 1251 | *pState = EAS_STATE_PLAY; |
| 1252 | |
| 1253 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | /*---------------------------------------------------------------------------- |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1257 | * EAS_SetVolume() |
| 1258 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1259 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1260 | * Set the master gain for the mix engine in 1dB increments |
| 1261 | * |
| 1262 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1263 | * pEASData - pointer to overall EAS data structure |
| 1264 | * volume - the desired master gain (100 is max) |
| 1265 | * handle - file or stream handle |
| 1266 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1267 | * Outputs: |
| 1268 | * |
| 1269 | * |
| 1270 | * Side Effects: |
| 1271 | * overrides any previously set master volume from sysex |
| 1272 | * |
| 1273 | *---------------------------------------------------------------------------- |
| 1274 | */ |
| 1275 | EAS_PUBLIC EAS_RESULT EAS_SetVolume (EAS_DATA_HANDLE pEASData, EAS_HANDLE pStream, EAS_I32 volume) |
| 1276 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1277 | EAS_I16 gain; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1278 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1279 | /* check range */ |
| 1280 | if ((volume < 0) || (volume > EAS_MAX_VOLUME)) |
| 1281 | return EAS_ERROR_PARAMETER_RANGE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1282 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1283 | /* stream volume */ |
| 1284 | if (pStream != NULL) |
| 1285 | { |
| 1286 | EAS_I32 gainOffset; |
| 1287 | EAS_RESULT result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1288 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1289 | if (!EAS_StreamReady(pEASData, pStream)) |
| 1290 | return EAS_ERROR_NOT_VALID_IN_THIS_STATE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1291 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1292 | /* get gain offset */ |
| 1293 | pStream->volume = (EAS_U8) volume; |
| 1294 | result = EAS_GetStreamParameter(pEASData, pStream, PARSER_DATA_GAIN_OFFSET, &gainOffset); |
| 1295 | if (result == EAS_SUCCESS) |
| 1296 | volume += gainOffset; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1297 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1298 | /* set stream volume */ |
| 1299 | gain = EAS_VolumeToGain(volume - STREAM_VOLUME_HEADROOM); |
| 1300 | |
| 1301 | /* convert to linear scalar */ |
| 1302 | return EAS_IntSetStrmParam(pEASData, pStream, PARSER_DATA_VOLUME, gain); |
| 1303 | } |
| 1304 | |
| 1305 | /* master volume */ |
| 1306 | pEASData->masterVolume = (EAS_U8) volume; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1307 | #if (NUM_OUTPUT_CHANNELS == 1) |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1308 | /* leave 3dB headroom for mono output */ |
| 1309 | volume -= 3; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1310 | #endif |
| 1311 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1312 | gain = EAS_VolumeToGain(volume - STREAM_VOLUME_HEADROOM); |
| 1313 | pEASData->masterGain = gain; |
| 1314 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | /*---------------------------------------------------------------------------- |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1318 | * EAS_Locate() |
| 1319 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1320 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1321 | * Locate into the file associated with the handle. |
| 1322 | * |
| 1323 | * Inputs: |
| 1324 | * pEASData - pointer to overall EAS data structure |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1325 | * handle - file handle |
| 1326 | * milliseconds - playback offset from start of file in milliseconds |
| 1327 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1328 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1329 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1330 | * |
| 1331 | * Side Effects: |
| 1332 | * the actual offset will be quantized to the closest update period, typically |
| 1333 | * a resolution of 5.9ms. Notes that are started prior to this time will not |
| 1334 | * sound. Any notes currently playing will be shut off. |
| 1335 | * |
| 1336 | *---------------------------------------------------------------------------- |
| 1337 | */ |
| 1338 | EAS_PUBLIC EAS_RESULT EAS_Locate (EAS_DATA_HANDLE pEASData, EAS_HANDLE pStream, EAS_I32 milliseconds, EAS_BOOL offset) |
| 1339 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1340 | S_FILE_PARSER_INTERFACE *pParserModule; |
| 1341 | EAS_RESULT result; |
| 1342 | EAS_U32 requestedTime; |
| 1343 | EAS_STATE state; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1344 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1345 | /* get pointer to parser function table */ |
| 1346 | pParserModule = (S_FILE_PARSER_INTERFACE*) pStream->pParserModule; |
| 1347 | if (pParserModule == NULL) |
| 1348 | return EAS_ERROR_FEATURE_NOT_AVAILABLE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1349 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1350 | if ((result = (*pParserModule->pfState)(pEASData, pStream->handle, &state)) != EAS_SUCCESS) |
| 1351 | return result; |
| 1352 | if (state >= EAS_STATE_OPEN) |
| 1353 | return EAS_ERROR_NOT_VALID_IN_THIS_STATE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1354 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1355 | /* handle offset and limit to start of file */ |
| 1356 | /*lint -e{704} use shift for performance*/ |
| 1357 | if (offset) |
| 1358 | milliseconds += (EAS_I32) pStream->time >> 8; |
| 1359 | if (milliseconds < 0) |
| 1360 | milliseconds = 0; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1361 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1362 | /* check to see if the request is different from the current time */ |
| 1363 | requestedTime = (EAS_U32) milliseconds; |
| 1364 | if (requestedTime == (pStream->time >> 8)) |
| 1365 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1366 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1367 | /* set the locate flag */ |
| 1368 | pStream->streamFlags |= STREAM_FLAGS_LOCATE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1369 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1370 | /* use the parser locate function, if available */ |
| 1371 | if (pParserModule->pfLocate != NULL) |
| 1372 | { |
| 1373 | EAS_BOOL parserLocate = EAS_FALSE; |
| 1374 | result = pParserModule->pfLocate(pEASData, pStream->handle, (EAS_I32) requestedTime, &parserLocate); |
| 1375 | if (!parserLocate) |
| 1376 | { |
| 1377 | if (result == EAS_SUCCESS) |
| 1378 | pStream->time = requestedTime << 8; |
| 1379 | return result; |
| 1380 | } |
| 1381 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1382 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1383 | /* if we were paused and not going to resume, set pause request flag */ |
| 1384 | if (((state == EAS_STATE_PAUSING) || (state == EAS_STATE_PAUSED)) && ((pStream->streamFlags & STREAM_FLAGS_RESUME) == 0)) |
| 1385 | pStream->streamFlags |= STREAM_FLAGS_PAUSE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1386 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1387 | /* reset the synth and parser */ |
| 1388 | if ((result = (*pParserModule->pfReset)(pEASData, pStream->handle)) != EAS_SUCCESS) |
| 1389 | return result; |
| 1390 | pStream->time = 0; |
| 1391 | |
| 1392 | /* locating forward, clear parsed flag and parse data until we get to the requested location */ |
| 1393 | if ((result = EAS_ParseEvents(pEASData, pStream, requestedTime << 8, eParserModeLocate)) != EAS_SUCCESS) |
| 1394 | return result; |
| 1395 | |
| 1396 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | /*---------------------------------------------------------------------------- |
| 1400 | * EAS_GetLocation() |
| 1401 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1402 | * Purpose: |
| 1403 | * Returns the current playback offset |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1404 | * |
| 1405 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1406 | * pEASData - pointer to overall EAS data structure |
| 1407 | * handle - file handle |
| 1408 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1409 | * Outputs: |
| 1410 | * The offset in milliseconds from the start of the current sequence, quantized |
| 1411 | * to the nearest update period. Actual resolution is typically 5.9 ms. |
| 1412 | * |
| 1413 | * Side Effects: |
| 1414 | * |
| 1415 | *---------------------------------------------------------------------------- |
| 1416 | */ |
| 1417 | /*lint -esym(715, pEASData) reserved for future use */ |
| 1418 | EAS_PUBLIC EAS_RESULT EAS_GetLocation (EAS_DATA_HANDLE pEASData, EAS_HANDLE pStream, EAS_I32 *pTime) |
| 1419 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1420 | if (!EAS_StreamReady(pEASData, pStream)) |
| 1421 | return EAS_ERROR_NOT_VALID_IN_THIS_STATE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1422 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1423 | *pTime = pStream->time >> 8; |
| 1424 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1425 | } |
| 1426 | |
Marco Nelissen | 2fa59c8 | 2020-04-22 09:33:28 -0700 | [diff] [blame] | 1427 | #ifdef JET_INTERFACE |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1428 | /*---------------------------------------------------------------------------- |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1429 | * EAS_Pause() |
| 1430 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1431 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1432 | * Pauses the playback of the data associated with this handle. The audio |
| 1433 | * is gracefully ramped down to prevent clicks and pops. It may take several |
| 1434 | * buffers of audio before the audio is muted. |
| 1435 | * |
| 1436 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1437 | * psEASData - pointer to overall EAS data structure |
| 1438 | * handle - file or stream handle |
| 1439 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1440 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1441 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1442 | * |
| 1443 | * Side Effects: |
| 1444 | * |
| 1445 | * |
| 1446 | *---------------------------------------------------------------------------- |
| 1447 | */ |
| 1448 | EAS_PUBLIC EAS_RESULT EAS_Pause (EAS_DATA_HANDLE pEASData, EAS_HANDLE pStream) |
| 1449 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1450 | S_FILE_PARSER_INTERFACE *pParserModule; |
| 1451 | EAS_STATE state; |
| 1452 | EAS_RESULT result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1453 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1454 | pParserModule = (S_FILE_PARSER_INTERFACE*) pStream->pParserModule; |
| 1455 | if (pParserModule == NULL) |
| 1456 | return EAS_ERROR_FEATURE_NOT_AVAILABLE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1457 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1458 | /* check for valid state */ |
| 1459 | result = pParserModule->pfState(pEASData, pStream->handle, &state); |
| 1460 | if (result == EAS_SUCCESS) |
| 1461 | { |
| 1462 | if ((state != EAS_STATE_PLAY) && (state != EAS_STATE_READY) && ((pStream->streamFlags & STREAM_FLAGS_RESUME) == 0)) |
| 1463 | return EAS_ERROR_NOT_VALID_IN_THIS_STATE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1464 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1465 | /* make sure parser implements pause */ |
| 1466 | if (pParserModule->pfPause == NULL) |
| 1467 | result = EAS_ERROR_NOT_IMPLEMENTED; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1468 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1469 | /* clear resume flag */ |
| 1470 | pStream->streamFlags &= ~STREAM_FLAGS_RESUME; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1471 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1472 | /* set pause flag */ |
| 1473 | pStream->streamFlags |= STREAM_FLAGS_PAUSE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1474 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1475 | #if 0 |
| 1476 | /* pause the stream */ |
| 1477 | if (pParserModule->pfPause) |
| 1478 | result = pParserModule->pfPause(pEASData, pStream->handle); |
| 1479 | else |
| 1480 | result = EAS_ERROR_NOT_IMPLEMENTED; |
| 1481 | #endif |
| 1482 | } |
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 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | /*---------------------------------------------------------------------------- |
| 1488 | * EAS_Resume() |
| 1489 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1490 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1491 | * Resumes the playback of the data associated with this handle. The audio |
| 1492 | * is gracefully ramped up to prevent clicks and pops. |
| 1493 | * |
| 1494 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1495 | * psEASData - pointer to overall EAS data structure |
| 1496 | * handle - file or stream handle |
| 1497 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1498 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1499 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1500 | * |
| 1501 | * Side Effects: |
| 1502 | * |
| 1503 | * |
| 1504 | *---------------------------------------------------------------------------- |
| 1505 | */ |
| 1506 | EAS_PUBLIC EAS_RESULT EAS_Resume (EAS_DATA_HANDLE pEASData, EAS_HANDLE pStream) |
| 1507 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1508 | S_FILE_PARSER_INTERFACE *pParserModule; |
| 1509 | EAS_STATE state; |
| 1510 | EAS_RESULT result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1511 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1512 | pParserModule = (S_FILE_PARSER_INTERFACE*) pStream->pParserModule; |
| 1513 | if (pParserModule == NULL) |
| 1514 | return EAS_ERROR_FEATURE_NOT_AVAILABLE; |
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 | /* check for valid state */ |
| 1517 | result = pParserModule->pfState(pEASData, pStream->handle, &state); |
| 1518 | if (result == EAS_SUCCESS) |
| 1519 | { |
| 1520 | if ((state != EAS_STATE_PAUSED) && (state != EAS_STATE_PAUSING) && ((pStream->streamFlags & STREAM_FLAGS_PAUSE) == 0)) |
| 1521 | return EAS_ERROR_NOT_VALID_IN_THIS_STATE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1522 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1523 | /* make sure parser implements this function */ |
| 1524 | if (pParserModule->pfResume == NULL) |
| 1525 | result = EAS_ERROR_NOT_IMPLEMENTED; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1526 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1527 | /* clear pause flag */ |
| 1528 | pStream->streamFlags &= ~STREAM_FLAGS_PAUSE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1529 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1530 | /* set resume flag */ |
| 1531 | pStream->streamFlags |= STREAM_FLAGS_RESUME; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1532 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1533 | #if 0 |
| 1534 | /* resume the stream */ |
| 1535 | if (pParserModule->pfResume) |
| 1536 | result = pParserModule->pfResume(pEASData, pStream->handle); |
| 1537 | else |
| 1538 | result = EAS_ERROR_NOT_IMPLEMENTED; |
| 1539 | #endif |
| 1540 | } |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1541 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1542 | return result; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1543 | } |
Marco Nelissen | 2fa59c8 | 2020-04-22 09:33:28 -0700 | [diff] [blame] | 1544 | #endif |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1545 | |
| 1546 | /*---------------------------------------------------------------------------- |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1547 | * EAS_SetParameter() |
| 1548 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1549 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1550 | * Set the parameter of a module. See E_MODULES for a list of modules |
| 1551 | * and the header files of the modules for a list of parameters. |
| 1552 | * |
| 1553 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1554 | * psEASData - pointer to overall EAS data structure |
| 1555 | * handle - file or stream handle |
| 1556 | * module - enumerated module number |
| 1557 | * param - enumerated parameter number |
| 1558 | * value - new parameter value |
| 1559 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1560 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1561 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1562 | * |
| 1563 | * Side Effects: |
| 1564 | * |
| 1565 | * |
| 1566 | *---------------------------------------------------------------------------- |
| 1567 | */ |
| 1568 | EAS_PUBLIC EAS_RESULT EAS_SetParameter (EAS_DATA_HANDLE pEASData, EAS_I32 module, EAS_I32 param, EAS_I32 value) |
| 1569 | { |
| 1570 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1571 | if (module >= NUM_EFFECTS_MODULES) |
| 1572 | return EAS_ERROR_INVALID_MODULE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1573 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1574 | if (pEASData->effectsModules[module].effectData == NULL) |
| 1575 | return EAS_ERROR_INVALID_MODULE; |
| 1576 | |
| 1577 | return (*pEASData->effectsModules[module].effect->pFSetParam) |
| 1578 | (pEASData->effectsModules[module].effectData, param, value); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1579 | } |
| 1580 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1581 | #ifdef _METRICS_ENABLED |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1582 | /*---------------------------------------------------------------------------- |
| 1583 | * EAS_MetricsReport() |
| 1584 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1585 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1586 | * Displays the current metrics through the metrics interface. |
| 1587 | * |
| 1588 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1589 | * p - instance data handle |
| 1590 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1591 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1592 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1593 | * |
| 1594 | * Side Effects: |
| 1595 | * |
| 1596 | *---------------------------------------------------------------------------- |
| 1597 | */ |
| 1598 | EAS_PUBLIC EAS_RESULT EAS_MetricsReport (EAS_DATA_HANDLE pEASData) |
| 1599 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1600 | if (!pEASData->pMetricsModule) |
| 1601 | return EAS_ERROR_INVALID_MODULE; |
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 | return (*pEASData->pMetricsModule->pfReport)(pEASData->pMetricsData); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | /*---------------------------------------------------------------------------- |
| 1607 | * EAS_MetricsReset() |
| 1608 | *---------------------------------------------------------------------------- |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1609 | * Purpose: |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1610 | * Resets the metrics. |
| 1611 | * |
| 1612 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1613 | * p - instance data handle |
| 1614 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1615 | * Outputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1616 | * |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1617 | * |
| 1618 | * Side Effects: |
| 1619 | * |
| 1620 | *---------------------------------------------------------------------------- |
| 1621 | */ |
| 1622 | EAS_PUBLIC EAS_RESULT EAS_MetricsReset (EAS_DATA_HANDLE pEASData) |
| 1623 | { |
| 1624 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1625 | if (!pEASData->pMetricsModule) |
| 1626 | return EAS_ERROR_INVALID_MODULE; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1627 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1628 | return (*pEASData->pMetricsModule->pfReset)(pEASData->pMetricsData); |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1629 | } |
| 1630 | #endif |
| 1631 | |
Marco Nelissen | af41595 | 2020-03-20 17:08:03 -0700 | [diff] [blame] | 1632 | #ifdef FILE_HEADER_SEARCH |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1633 | /*---------------------------------------------------------------------------- |
| 1634 | * EAS_SearchFile |
| 1635 | *---------------------------------------------------------------------------- |
| 1636 | * Search file for specific sequence starting at current file |
| 1637 | * position. Returns offset to start of sequence. |
| 1638 | * |
| 1639 | * Inputs: |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1640 | * pEASData - pointer to EAS persistent data object |
| 1641 | * fileHandle - file handle |
| 1642 | * searchString - pointer to search sequence |
| 1643 | * len - length of search sequence |
| 1644 | * pOffset - pointer to variable to store offset to sequence |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1645 | * |
| 1646 | * Returns EAS_EOF if end-of-file is reached |
| 1647 | *---------------------------------------------------------------------------- |
| 1648 | */ |
| 1649 | EAS_RESULT EAS_SearchFile (S_EAS_DATA *pEASData, EAS_FILE_HANDLE fileHandle, const EAS_U8 *searchString, EAS_I32 len, EAS_I32 *pOffset) |
| 1650 | { |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1651 | EAS_RESULT result; |
| 1652 | EAS_INT index; |
| 1653 | EAS_U8 c; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1654 | |
Dave Sparks | 56c99cd | 2009-08-24 17:35:45 -0700 | [diff] [blame] | 1655 | *pOffset = -1; |
| 1656 | index = 0; |
| 1657 | for (;;) |
| 1658 | { |
| 1659 | result = EAS_HWGetByte(pEASData->hwInstData, fileHandle, &c); |
| 1660 | if (result != EAS_SUCCESS) |
| 1661 | return result; |
| 1662 | if (c == searchString[index]) |
| 1663 | { |
| 1664 | index++; |
| 1665 | if (index == 4) |
| 1666 | { |
| 1667 | result = EAS_HWFilePos(pEASData->hwInstData, fileHandle, pOffset); |
| 1668 | if (result != EAS_SUCCESS) |
| 1669 | return result; |
| 1670 | *pOffset -= len; |
| 1671 | break; |
| 1672 | } |
| 1673 | } |
| 1674 | else |
| 1675 | index = 0; |
| 1676 | } |
| 1677 | return EAS_SUCCESS; |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1678 | } |
Marco Nelissen | af41595 | 2020-03-20 17:08:03 -0700 | [diff] [blame] | 1679 | #endif |
The Android Open Source Project | 7df3010 | 2009-03-03 19:30:38 -0800 | [diff] [blame] | 1680 | |
| 1681 | |