156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * File:
456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * eas_pcm.c
556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Contents and purpose:
756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Implements the PCM engine including ADPCM decode for SMAF and CMX audio playback.
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: 849 $
2656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *   $Date: 2007-08-28 08:59:11 -0700 (Tue, 28 Aug 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_math.h"
3756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_mixer.h"
3856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
3956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define PCM_MIXER_GUARD_BITS (NUM_MIXER_GUARD_BITS + 1)
4056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
4156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
4256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Decoder interfaces
4356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
4456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
4556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
4656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT LinearPCMDecode (EAS_DATA_HANDLE pEASData, S_PCM_STATE *pState);
4756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT LinearPCMLocate (EAS_DATA_HANDLE pEASData, S_PCM_STATE *pState, EAS_I32 time);
4856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
4956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic const S_DECODER_INTERFACE PCMDecoder =
5056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
5156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    NULL,
5256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    LinearPCMDecode,
5356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    LinearPCMLocate,
5456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks};
5556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
5656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* SMAF ADPCM decoder */
5756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifdef _SMAF_PARSER
5856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksextern S_DECODER_INTERFACE SmafDecoder;
5956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define SMAF_DECODER &SmafDecoder
6056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksextern S_DECODER_INTERFACE Smaf7BitDecoder;
6156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define SMAF_7BIT_DECODER &Smaf7BitDecoder
6256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#else
6356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define SMAF_DECODER NULL
6456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define SMAF_7BIT_DECODER NULL
6556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
6656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
6756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* IMA ADPCM decoder */
6856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifdef _IMA_DECODER
6956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksextern S_DECODER_INTERFACE IMADecoder;
7056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define IMA_DECODER &IMADecoder
7156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#else
7256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define IMA_DECODER NULL
7356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
7456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
7556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic const S_DECODER_INTERFACE * const decoders[] =
7656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
7756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    &PCMDecoder,
7856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    SMAF_DECODER,
7956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    IMA_DECODER,
8056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    SMAF_7BIT_DECODER
8156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks};
8256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
8356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
8456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Sample rate conversion
8556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
8656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
8756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
8856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define SRC_RATE_MULTIPLER (0x40000000 / _OUTPUT_SAMPLE_RATE)
8956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
9056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifdef _LOOKUP_SAMPLE_RATE
9156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic const EAS_U32 srcConvRate[][2] =
9256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
9356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    4000L, (4000L << 15) / _OUTPUT_SAMPLE_RATE,
9456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    8000L, (8000L << 15) / _OUTPUT_SAMPLE_RATE,
9556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    11025L, (11025L << 15) / _OUTPUT_SAMPLE_RATE,
9656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    12000L, (12000L << 15) / _OUTPUT_SAMPLE_RATE,
9756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    16000L, (16000L << 15) / _OUTPUT_SAMPLE_RATE,
9856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    22050L, (22050L << 15) / _OUTPUT_SAMPLE_RATE,
9956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    24000L, (24000L << 15) / _OUTPUT_SAMPLE_RATE,
10056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    32000L, (32000L << 15) / _OUTPUT_SAMPLE_RATE
10156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks};
10256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_U32 CalcBaseFreq (EAS_U32 sampleRate);
10356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define SRC_CONV_RATE_ENTRIES (sizeof(srcConvRate)/sizeof(EAS_U32)/2)
10456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
10556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
10656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
10756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* interface prototypes */
10856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RenderPCMStream (S_EAS_DATA *pEASData, S_PCM_STATE *pState, EAS_I32 numSamples);
10956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
11056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
11156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* local prototypes */
11256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic S_PCM_STATE *FindSlot (S_EAS_DATA *pEASData, EAS_FILE_HANDLE fileHandle, EAS_PCM_CALLBACK pCallbackFunc, EAS_VOID_PTR cbInstData);
11356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT InitPCMStream (S_EAS_DATA *pEASData, S_PCM_STATE *pState);
11456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
11556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
11656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PEInit()
11756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
11856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
11956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Initializes the PCM engine
12056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
12156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
12256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
12356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
12456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
12556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
12656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
12756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
12856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
12956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
13056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
13156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PEInit (S_EAS_DATA *pEASData)
13256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
13356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_PCM_STATE *pState;
13456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_INT i;
13556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
13656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* check for static memory allocation */
13756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pEASData->staticMemoryModel)
13856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pEASData->pPCMStreams = EAS_CMEnumData(EAS_CM_PCM_DATA);
13956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* allocate dynamic memory */
14056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    else
14156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pEASData->pPCMStreams = EAS_HWMalloc(pEASData->hwInstData, sizeof(S_PCM_STATE) * MAX_PCM_STREAMS);
14256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
14356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (!pEASData->pPCMStreams)
14456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
14556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        { /* dpp: EAS_ReportEx(_EAS_SEVERITY_FATAL, "Failed to allocate memory for PCM streams\n"); */ }
14656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_MALLOC_FAILED;
14756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
14856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
14956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    //zero the memory to insure complete initialization
15056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_HWMemSet((void *)(pEASData->pPCMStreams),0, sizeof(S_PCM_STATE) * MAX_PCM_STREAMS);
15156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
15256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* initialize the state data */
15356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    for (i = 0, pState = pEASData->pPCMStreams; i < MAX_PCM_STREAMS; i++, pState++)
15456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->fileHandle = NULL;
15556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
15656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
15756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
15856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
15956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
16056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PEShutdown()
16156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
16256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
16356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Shuts down the PCM engine
16456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
16556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
16656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
16756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
16856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
16956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
17056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
17156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
17256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
17356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
17456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
17556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PEShutdown (S_EAS_DATA *pEASData)
17656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
17756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
17856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* free any dynamic memory */
17956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (!pEASData->staticMemoryModel)
18056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
18156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pEASData->pPCMStreams)
18256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
18356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            EAS_HWFree(pEASData->hwInstData, pEASData->pPCMStreams);
18456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pEASData->pPCMStreams = NULL;
18556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
18656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
18756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
18856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
18956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
19056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
19156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PERender()
19256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
19356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
19456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Render a buffer of PCM audio
19556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
19656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
19756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
19856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
19956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
20056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
20156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
20256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
20356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
20456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
20556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
20656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PERender (S_EAS_DATA* pEASData, EAS_I32 numSamples)
20756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
20856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_PCM_STATE *pState;
20956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
21056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_INT i;
21156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
21256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* render all the active streams */
21356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    for (i = 0, pState = pEASData->pPCMStreams; i < MAX_PCM_STREAMS; i++, pState++)
21456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
21556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((pState->fileHandle) && (pState->state != EAS_STATE_STOPPED) && (pState->state != EAS_STATE_PAUSED))
21656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if ((result = RenderPCMStream(pEASData, pState, numSamples)) != EAS_SUCCESS)
21756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                return result;
21856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
21956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
22056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
22156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
22256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
22356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
22456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PEState()
22556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
22656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
22756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Returns the current state of the stream
22856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
22956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
23056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
23156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
23256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pState           - pointer to variable to store state
23356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
23456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
23556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
23656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
23756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
23856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
23956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Notes:
24056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * This interface is also exposed in the internal library for use by the other modules.
24156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
24256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
24356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
24456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PEState (S_EAS_DATA *pEASData, EAS_PCM_HANDLE pInstData, EAS_STATE *pState)
24556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
24656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* return current state */
24756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    *pState = pInstData->state;
24856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
24956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
25056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
25156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
25256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PEClose()
25356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
25456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
25556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Close the file and clean up
25656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
25756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
25856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
25956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
26056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
26156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
26256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
26356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
26456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
26556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
26656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
26756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
26856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PEClose (S_EAS_DATA *pEASData, EAS_PCM_HANDLE pState)
26956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
27056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
27156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
27256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWCloseFile(pEASData->hwInstData, pState->fileHandle)) != EAS_SUCCESS)
27356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
27456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
27556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->fileHandle = NULL;
27656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
27756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
27856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
27956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
28056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * PCM_Reset()
28156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
28256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
28356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Reset the sequencer. Used for locating backwards in the file.
28456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
28556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
28656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
28756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to file handle
28856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
28956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
29056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
29156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
29256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
29356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
29456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
29556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
29656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PEReset (S_EAS_DATA *pEASData, EAS_PCM_HANDLE pState)
29756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
29856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
29956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
30056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* reset file position to first byte of data in the stream */
30156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWFileSeek(pEASData->hwInstData, pState->fileHandle, pState->startPos)) != EAS_SUCCESS)
30256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
30356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Error %d seeking to start of PCM file\n", result); */ }
30456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
30556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
30656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
30756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* re-initialize stream */
30856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return InitPCMStream(pEASData, pState);
30956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
31056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
31156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
31256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PEOpenStream()
31356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
31456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
31556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Starts up a PCM playback
31656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
31756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
31856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
31956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
32056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
32156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
32256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
32356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
32456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
32556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
32656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
32756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PEOpenStream (S_EAS_DATA *pEASData, S_PCM_OPEN_PARAMS *pParams, EAS_PCM_HANDLE *pHandle)
32856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
32956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
33056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_PCM_STATE *pState;
33156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 filePos;
33256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
33356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* make sure we support this decoder */
33456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pParams->decoder >= NUM_DECODER_MODULES)
33556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
33656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Decoder selector out of range\n"); */ }
33756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_PARAMETER_RANGE;
33856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
33956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (decoders[pParams->decoder] == NULL)
34056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
34156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Decoder module not available\n"); */ }
34256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_FEATURE_NOT_AVAILABLE;
34356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
34456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
34556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* find a slot for the new stream */
34656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((pState = FindSlot(pEASData, pParams->fileHandle, pParams->pCallbackFunc, pParams->cbInstData)) == NULL)
34756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
34856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Unable to open ADPCM stream, too many streams open\n"); */ }
34956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_MAX_PCM_STREAMS;
35056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
35156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
35256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* get the current file position */
35356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWFilePos(pEASData->hwInstData, pState->fileHandle, &filePos)) != EAS_SUCCESS)
35456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
35556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        { /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "EAS_HWFilePos returned %ld\n",result); */ }
35656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->fileHandle = NULL;
35756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
35856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
35956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
36056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->pDecoder = decoders[pParams->decoder];
36156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->startPos = filePos;
36256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->bytesLeftLoop = pState->byteCount = pParams->size;
36356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->loopStart = pParams->loopStart;
36456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->samplesTilLoop = (EAS_I32) pState->loopStart;
36556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->loopSamples = pParams->loopSamples;
36656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->samplesInLoop = 0;
36756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->blockSize = (EAS_U16) pParams->blockSize;
36856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->flags = pParams->flags;
36956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->envData = pParams->envData;
37056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->volume = pParams->volume;
37156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->sampleRate = (EAS_U16) pParams->sampleRate;
37256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
37356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* set the base frequency */
37456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->basefreq = (SRC_RATE_MULTIPLER * (EAS_U32) pParams->sampleRate) >> 15;
37556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
37656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* calculate shift for frequencies > 1.0 */
37756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->rateShift = 0;
37856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    while (pState->basefreq > 32767)
37956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
38056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->basefreq = pState->basefreq >> 1;
38156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->rateShift++;
38256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
38356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
38456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* initialize */
38556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = InitPCMStream(pEASData, pState)) != EAS_SUCCESS)
38656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
38756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
38856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    *pHandle = pState;
38956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
39056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    { /* dpp: EAS_ReportEx(_EAS_SEVERITY_DETAIL, "EAS_PEOpenStream: StartPos=%d, byteCount = %d, loopSamples=%d\n",
39156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->startPos, pState->byteCount, pState->loopSamples); */ }
39256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
39356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
39456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
39556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
39656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PEContinueStream()
39756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
39856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
39956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Continues a PCM stream
40056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
40156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
40256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
40356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
40456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
40556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
40656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
40756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
40856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
40956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
41056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
41156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -e{715} reserved for future use */
41256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PEContinueStream (S_EAS_DATA *pEASData, EAS_PCM_HANDLE pState, EAS_I32 size)
41356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
41456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
41556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* add new samples to count */
41656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->bytesLeft += size;
41756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pState->bytesLeft > 0)
41856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->flags &= ~PCM_FLAGS_EMPTY;
41956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
42056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
42156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
42256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
42356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PEGetFileHandle()
42456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
42556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
42656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Returns the file handle of a stream
42756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
42856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
42956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
43056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
43156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
43256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
43356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
43456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
43556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
43656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
43756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
43856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
43956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PEGetFileHandle (S_EAS_DATA *pEASData, EAS_PCM_HANDLE pState, EAS_FILE_HANDLE *pFileHandle)
44056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
44156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    *pFileHandle = pState->fileHandle;
44256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
44356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
44456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
44556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
44656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PEUpdateParams()
44756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
44856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
44956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Update the pitch and volume parameters for a PCM stream
45056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
45156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
45256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to EAS library instance data
45356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to S_PCM_STATE for this stream
45456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * gainLeft         - linear gain multipler in 1.15 fraction format
45556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * gainRight        - linear gain multipler in 1.15 fraction format
45656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pitch            - pitch shift in cents
45756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * initial          - initial settings, set current gain
45856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
45956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
46056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
46156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
46256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
46356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
46456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Notes
46556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * In mono mode, leftGain controls the output gain and rightGain is ignored
46656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
46756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
46856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
46956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, gainRight) used only in 2-channel version */
47056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PEUpdateParams (S_EAS_DATA* pEASData, EAS_PCM_HANDLE pState, EAS_I16 pitch, EAS_I16 gainLeft, EAS_I16 gainRight)
47156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
47256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
47356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->gainLeft = gainLeft;
47456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
47556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if (NUM_OUTPUT_CHANNELS == 2)
47656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->gainRight = gainRight;
47756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
47856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
47956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->pitch = pitch;
48056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
48156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
48256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
48356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
48456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PELocate()
48556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
48656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
48756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * This function seeks to the requested place in the file. Accuracy
48856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * is dependent on the sample rate and block size.
48956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
49056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
49156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to overall EAS data structure
49256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pState           - stream handle
49356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * time             - media time in milliseconds
49456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
49556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
49656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PELocate (S_EAS_DATA *pEASData, EAS_PCM_HANDLE pState, EAS_I32 time)
49756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
49856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pState->pDecoder->pfLocate == NULL)
49956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return EAS_ERROR_FEATURE_NOT_AVAILABLE;
50056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
50156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return pState->pDecoder->pfLocate(pEASData, pState, time);
50256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
50356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
50456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
50556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PEUpdateVolume()
50656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
50756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
50856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Update the volume parameters for a PCM stream
50956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
51056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
51156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to EAS library instance data
51256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to S_PCM_STATE for this stream
51356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * gainLeft         - linear gain multipler in 1.15 fraction format
51456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * gainRight        - linear gain multipler in 1.15 fraction format
51556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * initial          - initial settings, set current gain
51656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
51756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
51856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
51956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
52056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
52156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
52256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Notes
52356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * In mono mode, leftGain controls the output gain and rightGain is ignored
52456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
52556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
52656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
52756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PEUpdateVolume (S_EAS_DATA* pEASData, EAS_PCM_HANDLE pState, EAS_I16 volume)
52856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
52956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->volume = volume;
53056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
53156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
53256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
53356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
53456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PEUpdatePitch()
53556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
53656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
53756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Update the pitch parameter for a PCM stream
53856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
53956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
54056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to EAS library instance data
54156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pState           - pointer to S_PCM_STATE for this stream
54256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pitch            - new pitch value in pitch cents
54356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
54456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
54556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
54656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PEUpdatePitch (S_EAS_DATA* pEASData, EAS_PCM_HANDLE pState, EAS_I16 pitch)
54756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
54856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->pitch = pitch;
54956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
55056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
55156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
55256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
55356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PEPause()
55456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
55556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
55656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Mute and stop rendering a PCM stream. Sets the gain target to zero and stops the playback
55756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * at the end of the next audio frame.
55856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
55956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
56056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to EAS library instance data
56156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to S_PCM_STATE for this stream
56256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
56356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
56456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
56556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
56656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
56756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
56856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
56956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
57056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
57156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PEPause (S_EAS_DATA *pEASData, EAS_PCM_HANDLE pState)
57256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
57356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* set state to stopping */
57456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->state = EAS_STATE_PAUSING;
57556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
57656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
57756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
57856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
57956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PEResume()
58056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
58156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
58256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Resume rendering a PCM stream. Sets the gain target back to its
58356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * previous setting and restarts playback at the end of the next audio
58456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * frame.
58556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
58656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
58756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to EAS library instance data
58856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to S_PCM_STATE for this stream
58956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
59056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
59156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
59256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
59356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
59456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
59556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
59656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
59756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
59856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PEResume (S_EAS_DATA *pEASData, EAS_PCM_HANDLE pState)
59956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
60056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* set state to stopping */
60156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->state = EAS_STATE_PLAY;
60256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
60356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
60456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
60556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_U32 getDecayScale(EAS_U32 index)
60656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
60756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U32 utemp;
60856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
60956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    //envelope decay segment
61056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    switch (index)
61156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
61256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 0: //no decay
61356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 512;//32768;
61456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
61556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 1: //.0156 dB per update
61656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 511;//32709;
61756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
61856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 2: //.03125
61956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 510;//32649;
62056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
62156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 3: //.0625
62256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 508;//32532;
62356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
62456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 4: //.125
62556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 505;//32298;
62656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
62756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 5: //.25
62856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 497;//31835;
62956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
63056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 6: //.5
63156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 483;//30929;
63256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
63356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 7: //1.0
63456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 456;//29193;
63556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
63656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 8: //2.0
63756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 406;//26008;
63856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
63956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 9: //4.0
64056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 323;//20642;
64156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
64256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 10: //8.0
64356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 203;//13004;
64456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
64556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 11: //16.0
64656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 81;//5160;
64756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
64856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 12: //32.0
64956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 13;//813;
65056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
65156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 13: //64.0
65256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 0;//20;
65356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
65456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 14: //128.0
65556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 0;
65656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
65756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 15: //256.0
65856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    default:
65956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 0;
66056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
66156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
66256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    //printf("getdecayscale returned %d\n",utemp);
66356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return utemp;
66456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
66556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
66656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_U32 getAttackIncrement(EAS_U32 index)
66756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
66856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U32 utemp;
66956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
67056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    //envelope decay segment
67156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    switch (index)
67256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
67356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 0:
67456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 32;
67556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
67656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 1:
67756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 64;
67856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
67956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 2:
68056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 128;
68156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
68256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 3:
68356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 256;
68456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
68556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 4:
68656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 512;
68756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
68856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 5:
68956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 1024;
69056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
69156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 6:
69256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 2048;
69356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
69456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 7:
69556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 4096;
69656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
69756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 8:
69856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 8192;
69956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
70056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 9:
70156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 16384;
70256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
70356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 10:
70456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 32768;
70556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
70656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 11:
70756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 65536;
70856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
70956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 12:
71056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 65536;
71156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
71256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 13:
71356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 65536;
71456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
71556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 14:
71656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 65535;
71756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
71856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    case 15:
71956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    default:
72056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = 0;
72156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        break;
72256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
72356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    //printf("getattackincrement returned %d\n",utemp);
72456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return utemp;
72556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
72656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
72756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
72856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PERelease()
72956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
73056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
73156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Put the PCM stream envelope into release.
73256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
73356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
73456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to EAS library instance data
73556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * handle           - pointer to S_PCM_STATE for this stream
73656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
73756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
73856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
73956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
74056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
74156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
74256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
74356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
74456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*lint -esym(715, pEASData) reserved for future use */
74556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PERelease (S_EAS_DATA *pEASData, EAS_PCM_HANDLE pState)
74656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
74756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U32 utemp;
74856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
74956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    //printf("handling note-off part of envelope\n");
75056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /*if the note is not ignore release or sustained*/
75156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (((pState->envData >> 24) & 0x0F)==0)
75256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
75356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* set envelope state to release */
75456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->envState = PCM_ENV_RELEASE;
75556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = ((pState->envData >> 20) & 0x0F);
75656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->envScale = getDecayScale(utemp); //getReleaseScale(utemp);
75756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
75856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    else
75956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
76056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /*else change envelope state to sustain */
76156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->envState = PCM_ENV_SUSTAIN;
76256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = ((pState->envData >> 28) & 0x0F);
76356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->envScale = getDecayScale(utemp); //getSustainScale(utemp);
76456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
76556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    //since we are in release, don't let anything hang around too long
76656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    //printf("checking env scale, val = %d\n",((S_PCM_STATE*) handle)->envScale);
76756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pState->envScale > 505)
76856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->envScale = 505;
76956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
77056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
77156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
77256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
77356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * FindSlot()
77456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
77556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
77656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Locates an empty stream slot and assigns the file handle
77756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
77856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
77956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pEASData         - pointer to EAS library instance data
78056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * fileHandle       - file handle
78156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pCallbackFunc    - function to be called back upon EAS_STATE_STOPPED
78256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
78356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
78456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * returns handle to slot or NULL if all slots are used
78556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
78656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
78756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
78856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
78956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
79056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic S_PCM_STATE *FindSlot (S_EAS_DATA *pEASData, EAS_FILE_HANDLE fileHandle, EAS_PCM_CALLBACK pCallbackFunc, EAS_VOID_PTR cbInstData)
79156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
79256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_INT i;
79356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_PCM_STATE *pState;
79456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
79556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifndef NO_PCM_STEAL
79656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_PCM_STATE *foundState = NULL;
79756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_INT count = 0;
79856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U32 startOrder = 0xFFFFFFFF;
79956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    S_PCM_STATE *stealState = NULL;
80056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U32 youngest = 0;
80156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
80256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* find an empty slot, count total in use, and find oldest in use (lowest start order) */
80356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    for (i = 0, pState = pEASData->pPCMStreams; i < MAX_PCM_STREAMS; i++, pState++)
80456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
80556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* if this one is available */
80656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->fileHandle == NULL)
80756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
80856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            foundState = pState;
80956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
81056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* else this one is in use, so see if it is the oldest, and count total in use */
81156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* also find youngest */
81256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else
81356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
81456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /*one more voice in use*/
81556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            count++;
81656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* is this the oldest? (lowest start order) */
81756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if ((pState->state != EAS_STATE_STOPPING) && (pState->startOrder < startOrder))
81856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            {
81956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* remember this one */
82056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                stealState = pState;
82156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* remember the oldest so far */
82256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                startOrder = pState->startOrder;
82356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            }
82456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* is this the youngest? (highest start order) */
82556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if (pState->startOrder >= youngest)
82656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            {
82756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                youngest = pState->startOrder;
82856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            }
82956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
83056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
83156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
83256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* if there are too many voices active, stop the oldest one */
83356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (count > PCM_STREAM_THRESHOLD)
83456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
83556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //printf("stealing!!!\n");
83656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* make sure we got one, although we should always have one at this point */
83756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (stealState != NULL)
83856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
83956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            //flag this as stopping, so it will get shut off
84056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            stealState->state = EAS_STATE_STOPPING;
84156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
84256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
84356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
84456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* if there are no available open streams (we won't likely see this, due to stealing) */
84556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (foundState == NULL)
84656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return NULL;
84756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
84856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* save info */
84956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    foundState->startOrder = youngest + 1;
85056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    foundState->fileHandle = fileHandle;
85156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    foundState->pCallback = pCallbackFunc;
85256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    foundState->cbInstData = cbInstData;
85356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return foundState;
85456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#else
85556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* find an empty slot*/
85656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    for (i = 0; i < MAX_PCM_STREAMS; i++)
85756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
85856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState = &pEASData->pPCMStreams[i];
85956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->fileHandle != NULL)
86056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            continue;
86156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
86256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->fileHandle = fileHandle;
86356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->pCallback = pCallbackFunc;
86456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->cbInstData = cbInstData;
86556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return pState;
86656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
86756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return NULL;
86856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
86956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
87056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
87156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifdef _LOOKUP_SAMPLE_RATE
87256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
87356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * CalcBaseFreq()
87456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
87556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
87656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Calculates the fractional phase increment for the sample rate converter
87756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
87856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
87956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * sampleRate       - sample rate in samples/sec
88056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
88156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
88256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Returns fractional sample rate with a 15-bit fraction
88356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
88456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
88556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
88656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
88756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
88856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_U32 CalcBaseFreq (EAS_U32 sampleRate)
88956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
89056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_INT i;
89156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
89256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* look up the conversion rate */
89356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    for (i = 0; i < (EAS_INT)(SRC_CONV_RATE_ENTRIES); i ++)
89456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
89556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (srcConvRate[i][0] == sampleRate)
89656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return srcConvRate[i][1];
89756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
89856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
89956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* if not found in table, do it the long way */
90056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    { /* dpp: EAS_ReportEx(_EAS_SEVERITY_WARNING, "Sample rate %u not in table, calculating by division\n", sampleRate); */ }
90156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
90256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return (SRC_RATE_MULTIPLER * (EAS_U32) sampleRate) >> 15;
90356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
90456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
90556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
90656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
90756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * InitPCMStream()
90856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
90956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
91056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Start an ADPCM stream playback. Decodes the header, preps the engine.
91156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
91256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
91356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
91456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
91556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
91656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
91756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
91856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
91956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
92056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
92156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
92256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT InitPCMStream (S_EAS_DATA *pEASData, S_PCM_STATE *pState)
92356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
92456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
92556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* initialize the data structure */
92656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->bytesLeft = pState->byteCount;
92756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->phase = 0;
92856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->srcByte = 0;
92956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->decoderL.acc = 0;
93056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->decoderL.output = 0;
93156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->decoderL.x0 = pState->decoderL.x1 = 0;
93256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->decoderL.step = 0;
93356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->decoderR.acc = 0;
93456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->decoderR.output = 0;
93556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->decoderR.x0 = pState->decoderR.x1 = 0;
93656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->decoderR.step = 0;
93756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->hiNibble = EAS_FALSE;
93856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->pitch = 0;
93956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->blockCount = 0;
94056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->gainLeft = PCM_DEFAULT_GAIN_SETTING;
94156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks//  pState->currentGainLeft = PCM_DEFAULT_GAIN_SETTING;
94256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->envValue = 0;
94356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->envState = PCM_ENV_START;
94456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
94556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if (NUM_OUTPUT_CHANNELS == 2)
94656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->gainRight = PCM_DEFAULT_GAIN_SETTING;
94756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks//  pState->currentGainRight = PCM_DEFAULT_GAIN_SETTING;
94856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
94956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->state = EAS_STATE_READY;
95056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
95156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* initialize the decoder */
95256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pState->pDecoder->pfInit)
95356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return (*pState->pDecoder->pfInit)(pEASData, pState);
95456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
95556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
95656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
95756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
95856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * RenderPCMStream()
95956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
96056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
96156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Decodes a buffer of ADPCM data.
96256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
96356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
96456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
96556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
96656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
96756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
96856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
96956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
97056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
97156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
97256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
97356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT RenderPCMStream (S_EAS_DATA *pEASData, S_PCM_STATE *pState, EAS_I32 numSamples)
97456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
97556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
97656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U32 phaseInc;
97756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 gainLeft, gainIncLeft;
97856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 *pOut;
97956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 temp;
98056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_U32 utemp;
98156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
98256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if (NUM_OUTPUT_CHANNELS == 2)
98356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 gainRight, gainIncRight;
98456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
98556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
98656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if 0
98756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    printf("env data: AR = %d, DR = %d, SL = %d, SR = %d, RR = %d\n",
98856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        ((pState->envData >> 12) & 0x0F),
98956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        ((pState->envData >> 16) & 0x0F),
99056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        ((pState->envData >> 8) & 0x0F),
99156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        ((pState->envData >> 28) & 0x0F),
99256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        ((pState->envData >> 20) & 0x0F));
99356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
99456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
99556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pState->envState == PCM_ENV_START)
99656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
99756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //printf("env start\n");
99856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = ((pState->envData >> 12) & 0x0F);
99956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //if fastest rate, attack is already completed
100056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //do the same for slowest rate, since that allows zero to be passed for default envelope
100156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (utemp == 0x0F || utemp == 0x00)
100256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
100356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            //start envelope at full
100456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->envValue = (32768<<7);
100556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            //jump right into decay
100656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            utemp = ((pState->envData >> 16) & 0x0F);
100756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->envScale = getDecayScale(utemp);
100856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->envState = PCM_ENV_DECAY;
100956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->currentGainLeft = (EAS_I16) FMUL_15x15(pState->gainLeft, pState->volume);
101056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->currentGainRight = (EAS_I16) FMUL_15x15(pState->gainRight, pState->volume);
101156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
101256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //else attack has a ramp
101356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else
101456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
101556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            //start the envelope very low
101656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->envValue = (2<<7);
101756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->currentGainLeft = 0;
101856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->currentGainRight = 0;
101956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            //get envelope attack scaling value
102056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->envScale = getAttackIncrement(utemp);
102156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            //go to attack state
102256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->envState = PCM_ENV_ATTACK;
102356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
102456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
102556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pState->envState == PCM_ENV_ATTACK)
102656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
102756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //printf("env attack, env value = %d, env scale = %d\n",pState->envValue>>7,pState->envScale);
102856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //update envelope value
102956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->envValue = pState->envValue + (pState->envScale << 7);
103056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //check envelope level and update state if needed
103156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->envValue >= (32768<<7))
103256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
103356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->envValue = (32768<<7);
103456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            utemp = ((pState->envData >> 16) & 0x0F);
103556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->envScale = getDecayScale(utemp);
103656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->envState = PCM_ENV_DECAY;
103756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
103856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
103956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    else if (pState->envState == PCM_ENV_DECAY)
104056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
104156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //printf("env decay, env value = %d, env scale = %d\n",pState->envValue>>7,pState->envScale);
104256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //update envelope value
104356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->envValue = (pState->envValue * pState->envScale)>>9;
104456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //check envelope level against sustain level and update state if needed
104556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        utemp = ((pState->envData >> 8) & 0x0F);
104656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (utemp == (EAS_U32)0x0F)
104756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            utemp = (2<<7);
104856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else
104956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
105056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            utemp = ((32769<<7) >> (utemp>>1));
105156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
105256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->envValue <= utemp)
105356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
105456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            utemp = ((pState->envData >> 28) & 0x0F);
105556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->envScale = getDecayScale(utemp); //getSustainScale(utemp);
105656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->envState = PCM_ENV_SUSTAIN;
105756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
105856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
105956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    else if (pState->envState == PCM_ENV_SUSTAIN)
106056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
106156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //printf("env sustain, env value = %d, env scale = %d\n",pState->envValue>>7,pState->envScale);
106256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //update envelope value
106356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->envValue = (pState->envValue * pState->envScale)>>9;
106456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //check envelope level against bottom level and update state if needed
106556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->envValue <= (2<<7))
106656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
106756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            //no more decay
106856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->envScale = 512;
106956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->envState = PCM_ENV_END;
107056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
107156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
107256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    else if (pState->envState == PCM_ENV_RELEASE)
107356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
107456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //printf("env release, env value = %d, env scale = %d\n",pState->envValue>>7,pState->envScale);
107556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //update envelope value
107656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->envValue = (pState->envValue * pState->envScale)>>9;
107756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //check envelope level against bottom level and update state if needed
107856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->envValue <= (2<<7))
107956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
108056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            //no more decay
108156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->envScale = 512;
108256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->envState = PCM_ENV_END;
108356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
108456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
108556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    else if (pState->envState == PCM_ENV_END)
108656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
108756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        //printf("env end\n");
108856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* set state to stopping, already ramped down */
108956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->state = EAS_STATE_STOPPING;
109056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
109156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
109256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    //pState->gainLeft = (EAS_U16)((pState->gainLeft * (pState->envValue>>7))>>15);
109356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    //pState->gainRight = (EAS_U16)((pState->gainRight * (pState->envValue>>7))>>15);
109456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
109556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* gain to 32-bits to increase resolution on anti-zipper filter */
109656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /*lint -e{703} use shift for performance */
109756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    gainLeft = (EAS_I32) pState->currentGainLeft << SYNTH_UPDATE_PERIOD_IN_BITS;
109856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if (NUM_OUTPUT_CHANNELS == 2)
109956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /*lint -e{703} use shift for performance */
110056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    gainRight = (EAS_I32) pState->currentGainRight << SYNTH_UPDATE_PERIOD_IN_BITS;
110156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
110256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
110356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* calculate a new gain increment, gain target is zero if pausing */
110456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((pState->state == EAS_STATE_PAUSING) || (pState->state == EAS_STATE_PAUSED))
110556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
110656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        gainIncLeft = -pState->currentGainLeft;
110756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if (NUM_OUTPUT_CHANNELS == 2)
110856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        gainIncRight= -pState->currentGainRight;
110956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
111056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
111156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    else
111256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
111356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        EAS_I32 gain = FMUL_15x15(pState->envValue >> 7, pState->volume);
111456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        gainIncLeft = FMUL_15x15(pState->gainLeft, gain) - pState->currentGainLeft;
111556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if (NUM_OUTPUT_CHANNELS == 2)
111656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        gainIncRight = FMUL_15x15(pState->gainRight, gain) - pState->currentGainRight;
111756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
111856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
111956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
112056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* calculate phase increment */
112156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    phaseInc = pState->basefreq;
112256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
112356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* convert pitch cents to linear multiplier */
112456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pState->pitch)
112556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
112656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        temp = EAS_Calculate2toX(pState->pitch);
112756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        phaseInc = FMUL_15x15(phaseInc, temp);
112856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
112956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    phaseInc = phaseInc << pState->rateShift;
113056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
113156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* pointer to mix buffer */
113256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pOut = pEASData->pMixBuffer;
113356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
113456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* render a buffer of samples */
113556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    while (numSamples--)
113656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
113756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
113856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* interpolate an output sample */
113956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->decoderL.output = pState->decoderL.x0 + FMUL_15x15((pState->decoderL.x1 - pState->decoderL.x0), pState->phase & PHASE_FRAC_MASK);
114056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
114156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* stereo output */
114256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if (NUM_OUTPUT_CHANNELS == 2)
114356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
114456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* stereo stream? */
114556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->flags & PCM_FLAGS_STEREO)
114656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->decoderR.output = pState->decoderR.x0 + FMUL_15x15((pState->decoderR.x1 - pState->decoderR.x0), pState->phase & PHASE_FRAC_MASK);
114756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
114856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* gain scale and mix */
114956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /*lint -e{704} use shift instead of division */
115056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        *pOut++ += (pState->decoderL.output * (gainLeft >> SYNTH_UPDATE_PERIOD_IN_BITS)) >> PCM_MIXER_GUARD_BITS;
115156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        gainLeft += gainIncLeft;
115256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
115356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /*lint -e{704} use shift instead of division */
115456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->flags & PCM_FLAGS_STEREO)
115556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            *pOut++ += (pState->decoderR.output * (gainRight >> SYNTH_UPDATE_PERIOD_IN_BITS)) >> PCM_MIXER_GUARD_BITS;
115656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else
115756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            *pOut++ += (pState->decoderL.output * (gainRight >> SYNTH_UPDATE_PERIOD_IN_BITS)) >> PCM_MIXER_GUARD_BITS;
115856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
115956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        gainRight += gainIncRight;
116056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
116156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* mono output */
116256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#else
116356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* if stereo stream, decode right channel and mix to mono */
116456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->flags & PCM_FLAGS_STEREO)
116556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
116656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->decoderR.output= pState->decoderR.x0 + FMUL_15x15((pState->decoderR.x1 - pState->decoderR.x0), pState->phase & PHASE_FRAC_MASK);
116756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
116856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* for mono, sum stereo ADPCM to mono */
116956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /*lint -e{704} use shift instead of division */
117056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            *pOut++ += ((pState->decoderL.output + pState->decoderR.output) * (gainLeft >> SYNTH_UPDATE_PERIOD_IN_BITS)) >> PCM_MIXER_GUARD_BITS;
117156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
117256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else
117356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /*lint -e{704} use shift instead of division */
117456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            *pOut++ += (pState->decoderL.output * (gainLeft >> SYNTH_UPDATE_PERIOD_IN_BITS)) >> PCM_MIXER_GUARD_BITS;
117556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
117656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        gainLeft += gainIncLeft;
117756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
117856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
117956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* advance phase accumulator */
118056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->phase += phaseInc;
118156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
118256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* if integer part of phase accumulator is non-zero, advance to next sample */
118356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        while (pState->phase & ~PHASE_FRAC_MASK)
118456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
118556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->decoderL.x0 = pState->decoderL.x1;
118656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->decoderR.x0 = pState->decoderR.x1;
118756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
118856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* give the source a chance to continue the stream */
118956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if (!pState->bytesLeft && pState->pCallback && ((pState->flags & PCM_FLAGS_EMPTY) == 0))
119056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            {
119156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                pState->flags |= PCM_FLAGS_EMPTY;
119256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                (*pState->pCallback)(pEASData, pState->cbInstData, pState, EAS_STATE_EMPTY);
119356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                { /* dpp: EAS_ReportEx(_EAS_SEVERITY_DETAIL, "RenderPCMStream: After empty callback, bytesLeft = %d\n", pState->bytesLeft); */ }
119456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            }
119556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
119656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* decode the next sample */
119756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if ((result = (*pState->pDecoder->pfDecodeSample)(pEASData, pState)) != EAS_SUCCESS)
119856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                return result;
119956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
120056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* adjust phase by one sample */
120156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->phase -= (1L << NUM_PHASE_FRAC_BITS);
120256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
120356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
120456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
120556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
120656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* save new gain */
120756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /*lint -e{704} use shift instead of division */
120856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->currentGainLeft = (EAS_I16) (gainLeft >> SYNTH_UPDATE_PERIOD_IN_BITS);
120956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
121056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if (NUM_OUTPUT_CHANNELS == 2)
121156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /*lint -e{704} use shift instead of division */
121256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->currentGainRight = (EAS_I16) (gainRight >> SYNTH_UPDATE_PERIOD_IN_BITS);
121356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif
121456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
121556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* if pausing, set new state and notify */
121656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pState->state == EAS_STATE_PAUSING)
121756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
121856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->state = EAS_STATE_PAUSED;
121956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->pCallback)
122056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            (*pState->pCallback)(pEASData, pState->cbInstData, pState, pState->state);
122156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
122256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
122356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* if out of data, set stopped state and notify */
122456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pState->bytesLeft == 0 || pState->state == EAS_STATE_STOPPING)
122556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
122656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->state = EAS_STATE_STOPPED;
122756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
122856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* do callback unless the file has already been closed */
122956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->pCallback && pState->fileHandle)
123056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            (*pState->pCallback)(pEASData, pState->cbInstData, pState, pState->state);
123156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
123256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
123356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pState->state == EAS_STATE_READY)
123456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->state = EAS_STATE_PLAY;
123556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
123656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
123756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
123856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
123956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
124056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * LinearPCMDecode()
124156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
124256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
124356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Decodes a PCM sample
124456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
124556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs:
124656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
124756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
124856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Outputs:
124956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
125056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
125156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Side Effects:
125256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
125356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
125456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
125556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT LinearPCMDecode (EAS_DATA_HANDLE pEASData, S_PCM_STATE *pState)
125656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
125756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
125856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_HW_DATA_HANDLE hwInstData;
125956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
126056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    hwInstData = ((S_EAS_DATA*) pEASData)->hwInstData;
126156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
126256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* if out of data, check for loop */
126356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((pState->bytesLeft == 0) && (pState->loopSamples != 0))
126456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
126556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = EAS_HWFileSeek(pEASData->hwInstData, pState->fileHandle, (EAS_I32) (pState->startPos + pState->loopLocation))) != EAS_SUCCESS)
126656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
126756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->bytesLeft = pState->byteCount = (EAS_I32) pState->bytesLeftLoop;
126856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->flags &= ~PCM_FLAGS_EMPTY;
126956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        { /* dpp: EAS_ReportEx(_EAS_SEVERITY_DETAIL, "LinearPCMDecode: Rewind file to %d, bytesLeft = %d\n", pState->startPos, pState->bytesLeft); */ }
127056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
127156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
127256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pState->bytesLeft)
127356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
127456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
127556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* check format byte for 8-bit samples */
127656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->flags & PCM_FLAGS_8_BIT)
127756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
127856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* fetch left or mono sample */
127956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if ((result = EAS_HWGetByte(hwInstData, pState->fileHandle, &pState->srcByte)) != EAS_SUCCESS)
128056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                return result;
128156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
128256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* if unsigned */
128356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if (pState->flags & PCM_FLAGS_UNSIGNED)
128456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            {
128556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /*lint -e{734} converting unsigned 8-bit to signed 16-bit */
128656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                pState->decoderL.x1 = (EAS_PCM)(((EAS_PCM) pState->srcByte << 8) ^ 0x8000);
128756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            }
128856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            else
128956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            {
129056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /*lint -e{734} converting signed 8-bit to signed 16-bit */
129156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                pState->decoderL.x1 = (EAS_PCM)((EAS_PCM) pState->srcByte << 8);
129256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            }
129356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->bytesLeft--;
129456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
129556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* fetch right sample */
129656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if(pState->flags & PCM_FLAGS_STEREO)
129756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            {
129856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = EAS_HWGetByte(hwInstData, pState->fileHandle, &pState->srcByte)) != EAS_SUCCESS)
129956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
130056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
130156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                /* if unsigned */
130256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if (pState->flags & PCM_FLAGS_UNSIGNED)
130356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                {
130456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    /*lint -e{734} converting unsigned 8-bit to signed 16-bit */
130556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    pState->decoderR.x1 = (EAS_PCM)(((EAS_PCM) pState->srcByte << 8) ^ 0x8000);
130656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                }
130756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                else
130856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                {
130956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    /*lint -e{734} converting signed 8-bit to signed 16-bit */
131056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    pState->decoderR.x1 = (EAS_PCM)((EAS_PCM) pState->srcByte << 8);
131156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                }
131256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                pState->bytesLeft--;
131356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            }
131456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
131556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
131656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* must be 16-bit samples */
131756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else
131856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
131956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            //unsigned 16 bit currently not supported
132056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if (pState->flags & PCM_FLAGS_UNSIGNED)
132156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            {
132256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                return EAS_ERROR_INVALID_PCM_TYPE;
132356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            }
132456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
132556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* fetch left or mono sample */
132656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if ((result = EAS_HWGetWord(hwInstData, pState->fileHandle, &pState->decoderL.x1, EAS_FALSE)) != EAS_SUCCESS)
132756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                return result;
132856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->bytesLeft -= 2;
132956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
133056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            /* fetch right sample */
133156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            if(pState->flags & PCM_FLAGS_STEREO)
133256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            {
133356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                if ((result = EAS_HWGetWord(hwInstData, pState->fileHandle, &pState->decoderR.x1, EAS_FALSE)) != EAS_SUCCESS)
133456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                    return result;
133556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks                pState->bytesLeft -= 2;
133656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            }
133756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
133856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
133956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
134056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* no more data, force zero samples */
134156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    else
134256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->decoderL.x1 = pState->decoderR.x1 = 0;
134356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
134456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
134556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
134656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
134756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
134856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * LinearPCMLocate()
134956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
135056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
135156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Locate in a linear PCM stream
135256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
135356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
135456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic EAS_RESULT LinearPCMLocate (EAS_DATA_HANDLE pEASData, S_PCM_STATE *pState, EAS_I32 time)
135556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
135656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
135756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 temp;
135856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_I32 secs, msecs;
135956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_INT shift;
136056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
136156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* calculate size of sample frame */
136256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pState->flags & PCM_FLAGS_8_BIT)
136356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        shift = 0;
136456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    else
136556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        shift = 1;
136656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (pState->flags & PCM_FLAGS_STEREO)
136756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        shift++;
136856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
136956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* break down into secs and msecs */
137056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    secs = time / 1000;
137156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    msecs = time - (secs * 1000);
137256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
137356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* calculate sample number fraction from msecs */
137456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    temp = (msecs * pState->sampleRate);
137556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    temp = (temp >> 10) + ((temp * 49) >> 21);
137656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
137756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* add integer sample count */
137856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    temp += secs * pState->sampleRate;
137956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
138056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* calculate the position based on sample frame size */
138156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /*lint -e{703} use shift for performance */
138256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    temp <<= shift;
138356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
138456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* past end of sample? */
138556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (temp > (EAS_I32) pState->loopStart)
138656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
138756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* if not looped, flag error */
138856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->loopSamples == 0)
138956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
139056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->bytesLeft = 0;
139156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->flags |= PCM_FLAGS_EMPTY;
139256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_ERROR_LOCATE_BEYOND_END;
139356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
139456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
139556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* looped sample - calculate position in loop */
139656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        while (temp > (EAS_I32) pState->loopStart)
139756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            temp -= (EAS_I32) pState->loopStart;
139856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
139956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
140056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* seek to new position */
140156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_PESeek(pEASData, pState, &temp)) != EAS_SUCCESS)
140256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
140356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
140456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* reset state */
140556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((pState->state != EAS_STATE_PAUSING) && (pState->state != EAS_STATE_PAUSED))
140656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->state = EAS_STATE_READY;
140756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
140856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
140956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
141056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
141156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*----------------------------------------------------------------------------
141256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * EAS_PESeek
141356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
141456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose:
141556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Locate to a particular byte in a PCM stream
141656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
141756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * This bit is tricky because the chunks may not be contiguous,
141856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * so we have to rely on the parser to position in the file. We
141956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * do this by seeking to the end of each chunk and simulating an
142056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * empty buffer condition until we get to where we want to go.
142156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *
142256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * A better solution would be a parser API for re-positioning,
142356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * but there isn't time at the moment to re-factor all the
142456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * parsers to support a new API.
142556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *----------------------------------------------------------------------------
142656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/
142756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_RESULT EAS_PESeek (S_EAS_DATA *pEASData, S_PCM_STATE *pState, EAS_I32 *pLocation)
142856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{
142956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    EAS_RESULT result;
143056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
143156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* seek to start of audio */
143256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if ((result = EAS_HWFileSeek(pEASData->hwInstData, pState->fileHandle, pState->startPos)) != EAS_SUCCESS)
143356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
143456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->state = EAS_STATE_ERROR;
143556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        return result;
143656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
143756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    pState->bytesLeft = pState->bytesLeftLoop;
143856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
143956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* skip through chunks until we find the right chunk */
144056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    while (*pLocation > (EAS_I32) pState->bytesLeft)
144156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
144256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* seek to end of audio chunk */
144356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        { /* dpp: EAS_ReportEx(_EAS_SEVERITY_DETAIL, "EAS_PESeek: Seek to offset = %d\n", pState->bytesLeft); */ }
144456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = EAS_HWFileSeekOfs(pEASData->hwInstData, pState->fileHandle, pState->bytesLeft)) != EAS_SUCCESS)
144556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
144656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->state = EAS_STATE_ERROR;
144756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
144856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
144956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        *pLocation -= pState->bytesLeft;
145056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->bytesLeft = 0;
145156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        pState->flags |= PCM_FLAGS_EMPTY;
145256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
145356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* retrieve more data */
145456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->pCallback)
145556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            (*pState->pCallback)(pEASData, pState->cbInstData, pState, EAS_STATE_EMPTY);
145656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
145756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        { /* dpp: EAS_ReportEx(_EAS_SEVERITY_DETAIL, "EAS_PESeek: bytesLeft=%d, byte location = %d\n", pState->bytesLeft, *pLocation); */ }
145856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
145956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* no more samples */
146056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->bytesLeft == 0)
146156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return EAS_ERROR_LOCATE_BEYOND_END;
146256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
146356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
146456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    /* seek to new offset in current chunk */
146556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    if (*pLocation > 0)
146656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    {
146756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        { /* dpp: EAS_ReportEx(_EAS_SEVERITY_DETAIL, "EAS_PESeek: Seek to offset = %d\n", *pLocation); */ }
146856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if ((result = EAS_HWFileSeekOfs(pEASData->hwInstData, pState->fileHandle, *pLocation)) != EAS_SUCCESS)
146956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        {
147056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->state = EAS_STATE_ERROR;
147156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            return result;
147256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        }
147356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
147456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        /* if not streamed, calculate number of bytes left */
147556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        if (pState->flags & PCM_FLAGS_STREAMING)
147656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->bytesLeft = 0x7fffffff;
147756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks        else
147856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks            pState->bytesLeft -= *pLocation;
147956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    }
148056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks    return EAS_SUCCESS;
148156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks}
148256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks
1483