156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * File:
456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * eas_wavefile.c
556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Contents and purpose:
756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * This file implements the wave file parser.
856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Copyright Sonic Network Inc. 2005
107df30109963092559d3760c0661a020f9daf1030The Android Open Source Project
117df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
127df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * you may not use this file except in compliance with the License.
137df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * You may obtain a copy of the License at
147df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *
157df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
167df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *
177df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
187df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
197df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
207df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * See the License for the specific language governing permissions and
217df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * limitations under the License.
2256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
2356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
2456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Revision Control:
2556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *   $Revision: 852 $
2656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *   $Date: 2007-09-04 11:43:49 -0700 (Tue, 04 Sep 2007) $
2756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
2856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
2956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
3056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_data.h"
3156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_report.h"
3256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_host.h"
3356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_config.h"
3456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_parser.h"
3556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_pcm.h"
3656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_wavefile.h"
3756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
3856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* lint is choking on the ARM math.h file, so we declare the log10 function here */
3956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksextern double log10(double x);
4056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
4156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* increase gain to compensate for loss in mixer */
4256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define WAVE_GAIN_OFFSET            6
4356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
4456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* constant for 1200 / log10(2.0) */
4556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define PITCH_CENTS_CONVERSION      3986.313714
4656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
4756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
4856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * WAVE file defines
4956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
5056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
5156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* RIFF chunks */
5256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define CHUNK_TYPE(a,b,c,d) (   \
5356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        ( ((EAS_U32)(a) & 0xFF) << 24 ) \
5456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    +   ( ((EAS_U32)(b) & 0xFF) << 16 ) \
5556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    +   ( ((EAS_U32)(c) & 0xFF) <<  8 ) \
5656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    +   ( ((EAS_U32)(d) & 0xFF)       ) )
5756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
5856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define CHUNK_RIFF                  CHUNK_TYPE('R','I','F','F')
5956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define CHUNK_WAVE                  CHUNK_TYPE('W','A','V','E')
6056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define CHUNK_FMT                   CHUNK_TYPE('f','m','t',' ')
6156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define CHUNK_DATA                  CHUNK_TYPE('d','a','t','a')
6256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define CHUNK_LIST                  CHUNK_TYPE('L','I','S','T')
6356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define CHUNK_INFO                  CHUNK_TYPE('I','N','F','O')
6456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define CHUNK_INAM                  CHUNK_TYPE('I','N','A','M')
6556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define CHUNK_ICOP                  CHUNK_TYPE('I','C','O','P')
6656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define CHUNK_IART                  CHUNK_TYPE('I','A','R','T')
6756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
6856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* wave file format identifiers */
6956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define WAVE_FORMAT_PCM             0x0001
7056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define WAVE_FORMAT_IMA_ADPCM       0x0011
7156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
7256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* file size for streamed file */
7356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define FILE_SIZE_STREAMING         0x80000000
7456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
7556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
7656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * prototypes
7756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
7856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
7956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveCheckFileType (S_EAS_DATA *pEASData, EAS_FILE_HANDLE fileHandle, EAS_VOID_PTR *pHandle, EAS_I32 offset);
8056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WavePrepare (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData);
8156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveState (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_STATE *pState);
8256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveClose (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData);
8356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveReset (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData);
8456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveLocate (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_I32 time, EAS_BOOL *pParserLocate);
8556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WavePause (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData);
8656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveResume (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData);
8756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveSetData (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_I32 param, EAS_I32 value);
8856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveGetData (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_I32 param, EAS_I32 *pValue);
8956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveParseHeader (S_EAS_DATA *pEASData, EAS_FILE_HANDLE fileHandle, S_WAVE_STATE *pWaveData);
9056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveGetMetaData (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_I32 *pMediaLength);
9156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
9256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifdef MMAPI_SUPPORT
9356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT SaveFmtChunk (S_EAS_DATA *pEASData, EAS_FILE_HANDLE fileHandle, S_WAVE_STATE *pWaveData, EAS_I32 size);
9456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
9556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
9656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
9756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
9856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_Wave_Parser
9956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
10056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * This structure contains the functional interface for the Wave file parser
10156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
10256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
10356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksconst S_FILE_PARSER_INTERFACE EAS_Wave_Parser =
10456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
10556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    WaveCheckFileType,
10656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    WavePrepare,
10756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    NULL,
10856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    NULL,
10956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    WaveState,
11056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    WaveClose,
11156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    WaveReset,
11256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    WavePause,
11356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    WaveResume,
11456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    WaveLocate,
11556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    WaveSetData,
11656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    WaveGetData,
11756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    WaveGetMetaData
11856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks};
11956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
12056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
12156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * WaveCheckFileType()
12256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
12356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
12456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Check the file type to see if we can parse it
12556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
12656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
12756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
12856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
12956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
13056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
13156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
13256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
13356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
13456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
13556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
13656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
13756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveCheckFileType (S_EAS_DATA *pEASData, EAS_FILE_HANDLE fileHandle, EAS_VOID_PTR *pHandle, EAS_I32 offset)
13856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
13956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_WAVE_STATE *pWaveData;
14056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
14156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* zero the memory to insure complete initialization */
14256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    *pHandle = NULL;
14356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
14456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* read the file header */
14556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (WaveParseHeader(pEASData, fileHandle, NULL) == EAS_SUCCESS)
14656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
14756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
14856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* check for static memory allocation */
14956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pEASData->staticMemoryModel)
15056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pWaveData = EAS_CMEnumData(EAS_CM_WAVE_DATA);
15156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else
15256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pWaveData = EAS_HWMalloc(pEASData->hwInstData, sizeof(S_WAVE_STATE));
15356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (!pWaveData)
15456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_ERROR_MALLOC_FAILED;
15556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        EAS_HWMemSet(pWaveData, 0, sizeof(S_WAVE_STATE));
15656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
15756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* return a pointer to the instance data */
15856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pWaveData->fileHandle = fileHandle;
15956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pWaveData->fileOffset = offset;
16056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        *pHandle = pWaveData;
16156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
16256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
16356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
16456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
16556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
16656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
16756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * WavePrepare()
16856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
16956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
17056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Prepare to parse the file.
17156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
17256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
17356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
17456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
17556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
17656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
17756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
17856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
17956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
18056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
18156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
18256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
18356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WavePrepare (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData)
18456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
18556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_WAVE_STATE *pWaveData;
18656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
18756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
18856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* validate parser state */
18956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pWaveData = (S_WAVE_STATE*) pInstData;
19056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pWaveData->streamHandle != NULL)
19156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_NOT_VALID_IN_THIS_STATE;
19256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
19356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* back to start of file */
19456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pWaveData->time = 0;
19556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWFileSeek(pEASData->hwInstData, pWaveData->fileHandle, pWaveData->fileOffset)) != EAS_SUCCESS)
19656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
19756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
19856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* parse the file header */
19956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = WaveParseHeader(pEASData, pWaveData->fileHandle, pWaveData)) != EAS_SUCCESS)
20056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
20156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
20256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
20356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
20456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
20556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
20656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * WaveState()
20756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
20856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
20956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Returns the current state of the stream
21056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
21156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
21256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
21356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
21456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pState           - pointer to variable to store state
21556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
21656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
21756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
21856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
21956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
22056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
22156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Notes:
22256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * This interface is also exposed in the internal library for use by the other modules.
22356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
22456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
22556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveState (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_STATE *pState)
22656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
22756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_WAVE_STATE *pWaveData;
22856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
22956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* return current state */
23056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pWaveData = (S_WAVE_STATE*) pInstData;
23156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pWaveData->streamHandle)
23256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_PEState(pEASData, pWaveData->streamHandle, pState);
23356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
23456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* if no stream handle, and time is not zero, we are done */
23556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pWaveData->time > 0)
23656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        *pState = EAS_STATE_STOPPED;
23756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    else
23856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        *pState = EAS_STATE_OPEN;
23956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
24056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
24156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
24256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
24356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * WaveClose()
24456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
24556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
24656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Close the file and clean up
24756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
24856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
24956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
25056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
25156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
25256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
25356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
25456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
25556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
25656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
25756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
25856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
25956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveClose (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData)
26056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
26156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_WAVE_STATE *pWaveData;
26256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
26356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
26456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pWaveData = (S_WAVE_STATE*) pInstData;
26556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
26656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* close the stream */
26756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pWaveData->streamHandle)
26856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
26956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = EAS_PEClose(pEASData, pWaveData->streamHandle)) != EAS_SUCCESS)
27056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
27156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pWaveData->streamHandle = NULL;
27256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
27356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
27456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* if using dynamic memory, free it */
27556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (!pEASData->staticMemoryModel)
27656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
27756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
27856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifdef MMAPI_SUPPORT
27956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* need to free the fmt chunk */
28056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pWaveData->fmtChunk != NULL)
28156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            EAS_HWFree(pEASData->hwInstData, pWaveData->fmtChunk);
28256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
28356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
28456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* free the instance data */
28556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        EAS_HWFree(pEASData->hwInstData, pWaveData);
28656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
28756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
28856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
28956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
29056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
29156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
29256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * WaveReset()
29356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
29456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
29556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Reset the sequencer. Used for locating backwards in the file.
29656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
29756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
29856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
29956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
30056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
30156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
30256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
30356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
30456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
30556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
30656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
30756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
30856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveReset (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData)
30956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
31056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_PCM_HANDLE streamHandle;
31156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
31256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* reset to first byte of data in the stream */
31356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    streamHandle = ((S_WAVE_STATE*)pInstData)->streamHandle;
31456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (streamHandle)
31556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_PEReset(pEASData, streamHandle);
31656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_ERROR_NOT_VALID_IN_THIS_STATE;
31756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
31856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
31956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
32056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * WaveLocate()
32156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
32256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
32356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Rewind/fast-forward in file.
32456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
32556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
32656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
32756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
32856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * time             - time (in msecs)
32956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
33056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
33156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
33256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
33356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
33456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
33556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
33656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
33756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pParserLocate) reserved for future use */
33856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveLocate (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_I32 time, EAS_BOOL *pParserLocate)
33956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
34056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_PCM_HANDLE streamHandle;
34156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
34256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* reset to first byte of data in the stream */
34356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    streamHandle = ((S_WAVE_STATE*)pInstData)->streamHandle;
34456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (streamHandle)
34556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_PELocate(pEASData, streamHandle, time);
34656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_ERROR_NOT_VALID_IN_THIS_STATE;
34756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
34856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
34956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
35056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * WavePause()
35156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
35256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
35356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Mute and stop rendering a PCM stream. Sets the gain target to zero and stops the playback
35456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * at the end of the next audio frame.
35556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
35656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
35756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to EAS library instance data
35856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to S_WAVE_STATE for this stream
35956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
36056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
36156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
36256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
36356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
36456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
36556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
36656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
36756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
36856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WavePause (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData)
36956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
37056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_PCM_HANDLE streamHandle;
37156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
37256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* pause the stream */
37356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    streamHandle = ((S_WAVE_STATE*)pInstData)->streamHandle;
37456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (streamHandle)
37556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_PEPause(pEASData, streamHandle);
37656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_ERROR_NOT_VALID_IN_THIS_STATE;
37756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
37856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
37956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
38056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * WaveResume()
38156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
38256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
38356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Resume rendering a PCM stream. Sets the gain target back to its
38456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * previous setting and restarts playback at the end of the next audio
38556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * frame.
38656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
38756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
38856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to EAS library instance data
38956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to S_WAVE_STATE for this stream
39056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
39156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
39256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
39356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
39456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
39556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
39656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
39756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
39856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
39956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveResume (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData)
40056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
40156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_PCM_HANDLE streamHandle;
40256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
40356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* resume the stream */
40456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    streamHandle = ((S_WAVE_STATE*)pInstData)->streamHandle;
40556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (streamHandle)
40656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_PEResume(pEASData, streamHandle);
40756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_ERROR_NOT_VALID_IN_THIS_STATE;
40856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
40956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
41056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
41156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * WaveSetData()
41256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
41356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
41456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
41556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
41656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to EAS library instance data
41756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to S_WAVE_STATE for this stream
41856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
41956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
42056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
42156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
42256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
42356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
42456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
42556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
42656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveSetData (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_I32 param, EAS_I32 value)
42756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
42856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_WAVE_STATE *pWaveData = (S_WAVE_STATE*) pInstData;
42956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
43056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    switch (param)
43156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
43256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* set metadata callback */
43356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        case PARSER_DATA_METADATA_CB:
43456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            EAS_HWMemCpy(&pWaveData->metadata, (void*) value, sizeof(S_METADATA_CB));
43556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_SUCCESS;
43656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
43756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        case PARSER_DATA_PLAYBACK_RATE:
43856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            value = (EAS_I32) (PITCH_CENTS_CONVERSION * log10((double) value / (double) (1 << 28)));
43956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_PEUpdatePitch(pEASData, pWaveData->streamHandle, (EAS_I16) value);
44056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
44156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        case PARSER_DATA_VOLUME:
44256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_PEUpdateVolume(pEASData, pWaveData->streamHandle, (EAS_I16) value);
44356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
44456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        default:
44556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_ERROR_INVALID_PARAMETER;
44656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
44756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
44856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
44956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
45056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * WaveGetData()
45156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
45256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
45356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
45456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
45556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to EAS library instance data
45656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to S_WAVE_STATE for this stream
45756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
45856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
45956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
46056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
46156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
46256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
46356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
46456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
46556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
46656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveGetData (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_I32 param, EAS_I32 *pValue)
46756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
46856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_WAVE_STATE *pWaveData;
46956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
47056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pWaveData = (S_WAVE_STATE*) pInstData;
47156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    switch (param)
47256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
47356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* return file type as WAVE */
47456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        case PARSER_DATA_FILE_TYPE:
47556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            *pValue = pWaveData->fileType;
47656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            break;
47756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
47856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifdef MMAPI_SUPPORT
47956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* return pointer to 'fmt' chunk */
48056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        case PARSER_DATA_FORMAT:
48156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            *pValue = (EAS_I32) pWaveData->fmtChunk;
48256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            break;
48356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
48456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
48556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        case PARSER_DATA_GAIN_OFFSET:
48656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            *pValue = WAVE_GAIN_OFFSET;
48756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            break;
48856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
48956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        default:
49056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_ERROR_INVALID_PARAMETER;
49156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
49256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
49356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
49456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
49556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
49656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
49756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * WaveParseHeader()
49856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
49956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
50056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Parse the WAVE file header.
50156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
50256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
50356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to EAS library instance data
50456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to S_WAVE_STATE for this stream
50556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
50656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
50756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
50856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
50956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
51056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
51156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
51256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
51356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveParseHeader (S_EAS_DATA *pEASData, EAS_FILE_HANDLE fileHandle, S_WAVE_STATE *pWaveData)
51456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
51556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_PCM_OPEN_PARAMS params;
51656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
51756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U32 tag;
51856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U32 fileSize;
51956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U32 size;
52056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 pos;
52156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 audioOffset;
52256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U16 usTemp;
52356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_BOOL parseDone;
52456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U32 avgBytesPerSec;
52556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
52656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* init some data (and keep lint happy) */
52756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    params.sampleRate = 0;
52856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    params.size = 0;
52956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    audioOffset = 0;
53056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    params.decoder = 0;
53156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    params.blockSize = 0;
53256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    params.pCallbackFunc = NULL;
53356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    params.cbInstData = NULL;
53456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    params.loopSamples = 0;
53556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    params.fileHandle = fileHandle;
53656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    params.volume = 0x7fff;
53756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    params.envData = 0;
53856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    avgBytesPerSec = 8000;
53956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
54056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* check for 'RIFF' tag */
54156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWGetDWord(pEASData->hwInstData, fileHandle, &tag, EAS_TRUE)) != EAS_FALSE)
54256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
54356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (tag != CHUNK_RIFF)
54456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_UNRECOGNIZED_FORMAT;
54556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
54656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* get size */
54756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWGetDWord(pEASData->hwInstData, fileHandle, &fileSize, EAS_FALSE)) != EAS_FALSE)
54856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
54956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
55056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* check for 'WAVE' tag */
55156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWGetDWord(pEASData->hwInstData, fileHandle, &tag, EAS_TRUE)) != EAS_FALSE)
55256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
55356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (tag != CHUNK_WAVE)
55456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_UNRECOGNIZED_FORMAT;
55556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
55656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* this is enough to say we recognize the file */
55756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pWaveData == NULL)
55856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_SUCCESS;
55956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
56056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* check for streaming mode */
56156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pWaveData->flags = 0;
56256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pWaveData->mediaLength = -1;
56356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pWaveData->infoChunkPos = -1;
56456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pWaveData->infoChunkSize = -1;
56556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (fileSize== FILE_SIZE_STREAMING)
56656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
56756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pWaveData->flags |= PCM_FLAGS_STREAMING;
56856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        fileSize = 0x7fffffff;
56956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
57056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
57156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* find out where we're at */
57256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWFilePos(pEASData->hwInstData, fileHandle, &pos)) != EAS_SUCCESS)
57356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
57456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    fileSize -= 4;
57556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
57656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    parseDone = EAS_FALSE;
57756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    for (;;)
57856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
57956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* get tag and size for next chunk */
58056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = EAS_HWGetDWord(pEASData->hwInstData, fileHandle, &tag, EAS_TRUE)) != EAS_FALSE)
58156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
58256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = EAS_HWGetDWord(pEASData->hwInstData, fileHandle, &size, EAS_FALSE)) != EAS_FALSE)
58356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
58456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
58556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* process chunk */
58656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pos += 8;
58756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        switch (tag)
58856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
58956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            case CHUNK_FMT:
59056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
59156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifdef MMAPI_SUPPORT
59256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = SaveFmtChunk(pEASData, fileHandle, pWaveData, (EAS_I32) size)) != EAS_SUCCESS)
59356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
59456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
59556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
59656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* get audio format */
59756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = EAS_HWGetWord(pEASData->hwInstData, fileHandle, &usTemp, EAS_FALSE)) != EAS_FALSE)
59856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
59956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if (usTemp == WAVE_FORMAT_PCM)
60056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                {
60156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    params.decoder = EAS_DECODER_PCM;
60256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    pWaveData->fileType = EAS_FILE_WAVE_PCM;
60356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                }
60456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                else if (usTemp == WAVE_FORMAT_IMA_ADPCM)
60556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                {
60656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    params.decoder = EAS_DECODER_IMA_ADPCM;
60756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    pWaveData->fileType = EAS_FILE_WAVE_IMA_ADPCM;
60856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                }
60956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                else
61056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return EAS_ERROR_UNRECOGNIZED_FORMAT;
61156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
61256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* get number of channels */
61356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = EAS_HWGetWord(pEASData->hwInstData, fileHandle, &usTemp, EAS_FALSE)) != EAS_FALSE)
61456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
61556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if (usTemp == 2)
61656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    pWaveData->flags |= PCM_FLAGS_STEREO;
61756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                else if (usTemp != 1)
61856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return EAS_ERROR_UNRECOGNIZED_FORMAT;
61956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
62056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* get sample rate */
62156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = EAS_HWGetDWord(pEASData->hwInstData, fileHandle, &params.sampleRate, EAS_FALSE)) != EAS_FALSE)
62256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
62356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
62456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* get stream rate */
62556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = EAS_HWGetDWord(pEASData->hwInstData, fileHandle, &avgBytesPerSec, EAS_FALSE)) != EAS_FALSE)
62656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
62756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
62856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* get block alignment */
62956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = EAS_HWGetWord(pEASData->hwInstData, fileHandle, &usTemp, EAS_FALSE)) != EAS_FALSE)
63056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
63156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                params.blockSize = usTemp;
63256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
63356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* get bits per sample */
63456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = EAS_HWGetWord(pEASData->hwInstData, fileHandle, &usTemp, EAS_FALSE)) != EAS_FALSE)
63556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
63656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
63756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* PCM, must be 8 or 16 bit samples */
63856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if (params.decoder == EAS_DECODER_PCM)
63956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                {
64056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    if (usTemp == 8)
64156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                        pWaveData->flags |= PCM_FLAGS_8_BIT | PCM_FLAGS_UNSIGNED;
64256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    else if (usTemp != 16)
64356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                        return EAS_ERROR_UNRECOGNIZED_FORMAT;
64456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                }
64556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
64656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* for IMA ADPCM, we only support mono 4-bit ADPCM */
64756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                else
64856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                {
64956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    if ((usTemp != 4) || (pWaveData->flags & PCM_FLAGS_STEREO))
65056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                        return EAS_ERROR_UNRECOGNIZED_FORMAT;
65156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                }
65256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
65356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                break;
65456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
65556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            case CHUNK_DATA:
65656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                audioOffset = pos;
65756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if (pWaveData->flags & PCM_FLAGS_STREAMING)
65856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                {
65956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    params.size = 0x7fffffff;
66056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    parseDone = EAS_TRUE;
66156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                }
66256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                else
66356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                {
66456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    params.size = (EAS_I32) size;
66556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    params.loopStart = size;
66656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    /* use more accurate method if possible */
66756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    if (size <= (0x7fffffff / 1000))
66856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                        pWaveData->mediaLength = (EAS_I32) ((size * 1000) / avgBytesPerSec);
66956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    else
67056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                        pWaveData->mediaLength = (EAS_I32) (size / (avgBytesPerSec / 1000));
67156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                }
67256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                break;
67356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
67456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            case CHUNK_LIST:
67556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* get the list type */
67656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = EAS_HWGetDWord(pEASData->hwInstData, fileHandle, &tag, EAS_TRUE)) != EAS_FALSE)
67756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
67856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if (tag == CHUNK_INFO)
67956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                {
68056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    pWaveData->infoChunkPos = pos + 4;
68156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    pWaveData->infoChunkSize = (EAS_I32) size - 4;
68256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                }
68356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                break;
68456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
68556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            default:
68656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                { /* dpp: EAS_ReportEx(_EAS_SEVERITY_INFO, "WaveParseHeader: %c%c%c%c chunk - %d byte(s) ignored\n",
68756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    (char) (tag >> 24), (char) (tag >> 16), (char) (tag >> 8), (char) tag, size); */ }
68856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                break;
68956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
69056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
69156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (parseDone)
69256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            break;
69356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
69456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* subtract header size */
69556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        fileSize -= 8;
69656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
69756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* account for zero-padding on odd length chunks */
69856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (size & 1)
69956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            size++;
70056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
70156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* this check works for files with odd length last chunk and no zero-pad */
70256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (size >= fileSize)
70356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
70456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if (size > fileSize)
70556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                { /* dpp: EAS_ReportEx(_EAS_SEVERITY_INFO, "WaveParseHeader: '%c%c%c%c' chunk size exceeds length of file or is not zero-padded\n",
70656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    (char) (tag >> 24), (char) (tag >> 16), (char) (tag >> 8), (char) tag, size); */ }
70756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            break;
70856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
70956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
71056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* subtract size of data chunk (including any zero-pad) */
71156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        fileSize -= size;
71256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
71356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* seek to next chunk */
71456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pos += (EAS_I32) size;
71556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = EAS_HWFileSeek(pEASData->hwInstData, fileHandle, pos)) != EAS_SUCCESS)
71656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
71756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
71856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
71956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* check for valid header */
72056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((params.sampleRate == 0) || (params.size == 0))
72156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_UNRECOGNIZED_FORMAT;
72256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
72356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* save the pertinent information */
72456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pWaveData->audioOffset = audioOffset;
72556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    params.flags = pWaveData->flags;
72656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
72756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* seek to data */
72856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWFileSeek(pEASData->hwInstData, fileHandle, audioOffset)) != EAS_SUCCESS)
72956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
73056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
73156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* open a stream in the PCM engine */
73256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_PEOpenStream(pEASData, &params, &pWaveData->streamHandle);
73356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
73456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
73556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
73656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * WaveGetMetaData()
73756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
73856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
73956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Process the INFO chunk and return metadata to host
74056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
74156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
74256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT WaveGetMetaData (S_EAS_DATA *pEASData, EAS_VOID_PTR pInstData, EAS_I32 *pMediaLength)
74356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
74456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_WAVE_STATE *pWaveData;
74556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
74656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 pos;
74756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U32 size;
74856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 infoSize;
74956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U32 tag;
75056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 restorePos;
75156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    E_EAS_METADATA_TYPE metaType;
75256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 metaLen;
75356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
75456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* get current position so we can restore it */
75556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pWaveData = (S_WAVE_STATE*) pInstData;
75656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
75756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* return media length */
75856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    *pMediaLength = pWaveData->mediaLength;
75956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
76056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* did we encounter an INFO chunk? */
76156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pWaveData->infoChunkPos < 0)
76256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_SUCCESS;
76356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
76456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWFilePos(pEASData->hwInstData, pWaveData->fileHandle, &restorePos)) != EAS_SUCCESS)
76556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
76656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
76756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* offset to start of first chunk in INFO chunk */
76856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pos = pWaveData->infoChunkPos;
76956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    infoSize = pWaveData->infoChunkSize;
77056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
77156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* read all the chunks in the INFO chunk */
77256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    for (;;)
77356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
77456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
77556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* seek to next chunk */
77656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = EAS_HWFileSeek(pEASData->hwInstData, pWaveData->fileHandle, pos)) != EAS_SUCCESS)
77756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
77856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
77956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* get tag and size for next chunk */
78056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = EAS_HWGetDWord(pEASData->hwInstData, pWaveData->fileHandle, &tag, EAS_TRUE)) != EAS_FALSE)
78156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
78256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = EAS_HWGetDWord(pEASData->hwInstData, pWaveData->fileHandle, &size, EAS_FALSE)) != EAS_FALSE)
78356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
78456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
78556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* process chunk */
78656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pos += 8;
78756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        metaType = EAS_METADATA_UNKNOWN;
78856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        switch (tag)
78956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
79056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            case CHUNK_INAM:
79156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                metaType = EAS_METADATA_TITLE;
79256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                break;
79356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
79456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            case CHUNK_IART:
79556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                metaType = EAS_METADATA_AUTHOR;
79656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                break;
79756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
79856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            case CHUNK_ICOP:
79956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                metaType = EAS_METADATA_COPYRIGHT;
80056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                break;
80156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
80256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            default:
80356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                { /* dpp: EAS_ReportEx(_EAS_SEVERITY_INFO, "WaveParseHeader: %c%c%c%c chunk - %d byte(s) ignored\n",
80456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    (char) (tag >> 24), (char) (tag >> 16), (char) (tag >> 8), (char) tag, size); */ }
80556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                break;
80656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
80756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
80856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* process known metadata */
80956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (metaType != EAS_METADATA_UNKNOWN)
81056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
81156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            metaLen = pWaveData->metadata.bufferSize - 1;
81256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if (metaLen > (EAS_I32) size)
81356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                metaLen = (EAS_I32) size;
81456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if ((result = EAS_HWReadFile(pEASData->hwInstData, pWaveData->fileHandle, pWaveData->metadata.buffer, metaLen, &metaLen)) != EAS_SUCCESS)
81556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                return result;
81656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pWaveData->metadata.buffer[metaLen] = 0;
81756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pWaveData->metadata.callback(metaType, pWaveData->metadata.buffer, pWaveData->metadata.pUserData);
81856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
81956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
82056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* subtract this block */
82156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (size & 1)
82256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            size++;
82356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        infoSize -= (EAS_I32) size + 8;
82456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (infoSize == 0)
82556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            break;
82656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pos += (EAS_I32) size;
82756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
82856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
82956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
83056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* restore original position */
83156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_HWFileSeek(pEASData->hwInstData, pWaveData->fileHandle, restorePos);
83256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
83356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
83456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifdef MMAPI_SUPPORT
83556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
83656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * SaveFmtChunk()
83756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
83856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
83956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Save the fmt chunk for the MMAPI library
84056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
84156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
84256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT SaveFmtChunk (S_EAS_DATA *pEASData, EAS_FILE_HANDLE fileHandle, S_WAVE_STATE *pWaveData, EAS_I32 fmtSize)
84356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
84456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
84556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 pos;
84656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 count;
84756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
84856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* save current file position */
84956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWFilePos(pEASData->hwInstData, fileHandle, &pos)) != EAS_SUCCESS)
85056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
85156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
85256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* allocate a chunk of memory */
85356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pWaveData->fmtChunk = EAS_HWMalloc(pEASData->hwInstData, fmtSize);
85456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (!pWaveData->fmtChunk)
85556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_MALLOC_FAILED;
85656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
85756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* read the fmt chunk into memory */
85856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWReadFile(pEASData->hwInstData, fileHandle, pWaveData->fmtChunk, fmtSize, &count)) != EAS_SUCCESS)
85956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
86056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (count != fmtSize)
86156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_FILE_READ_FAILED;
86256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
86356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* restore file position */
86456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_HWFileSeek(pEASData->hwInstData, fileHandle, pos);
86556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
86656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
86756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
868