Home | History | Annotate | Download | only in lib_src
      1 /*----------------------------------------------------------------------------
      2  *
      3  * File:
      4  * eas_pcmdata.h
      5  *
      6  * Contents and purpose:
      7  * Data declarations for the PCM engine
      8  *
      9  *
     10  * Copyright Sonic Network Inc. 2005
     11 
     12  * Licensed under the Apache License, Version 2.0 (the "License");
     13  * you may not use this file except in compliance with the License.
     14  * You may obtain a copy of the License at
     15  *
     16  *      http://www.apache.org/licenses/LICENSE-2.0
     17  *
     18  * Unless required by applicable law or agreed to in writing, software
     19  * distributed under the License is distributed on an "AS IS" BASIS,
     20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     21  * See the License for the specific language governing permissions and
     22  * limitations under the License.
     23  *
     24  *----------------------------------------------------------------------------
     25  * Revision Control:
     26  *   $Revision: 847 $
     27  *   $Date: 2007-08-27 21:30:08 -0700 (Mon, 27 Aug 2007) $
     28  *----------------------------------------------------------------------------
     29 */
     30 
     31 #ifndef _EAS_PCMDATA_H
     32 #define _EAS_PCMDATA_H
     33 
     34 /* sets the maximum number of simultaneous PCM streams */
     35 #ifndef MAX_PCM_STREAMS
     36 #define MAX_PCM_STREAMS             16
     37 #define PCM_STREAM_THRESHOLD        (MAX_PCM_STREAMS - 4)
     38 #endif
     39 
     40 /* coefficents for high-pass filter in ADPCM */
     41 #define INTEGRATOR_COEFFICIENT      100     /* coefficient for leaky integrator */
     42 
     43 /* additional flags in S_PCM_STATE.flags used internal to module */
     44 #define PCM_FLAGS_EMPTY             0x01000000  /* unsigned format */
     45 
     46 /*----------------------------------------------------------------------------
     47  * S_PCM_STATE
     48  *
     49  * Retains state information for PCM streams.
     50  *----------------------------------------------------------------------------
     51 */
     52 typedef struct s_decoder_state_tag
     53 {
     54     EAS_I32             output;             /* last output for DC offset filter */
     55     EAS_I32             acc;                /* accumulator for DC offset filter */
     56     EAS_I32             step;               /* current ADPCM step size */
     57     EAS_PCM             x1;                 /* current generated sample */
     58     EAS_PCM             x0;                 /* previous generated sample */
     59 } S_DECODER_STATE;
     60 
     61 typedef enum
     62 {
     63     PCM_ENV_START = 0,
     64     PCM_ENV_ATTACK,
     65     PCM_ENV_DECAY,
     66     PCM_ENV_SUSTAIN,
     67     PCM_ENV_RELEASE,
     68     PCM_ENV_END
     69 } E_PCM_ENV_STATE;
     70 
     71 typedef struct s_pcm_state_tag
     72 {
     73 #ifdef _CHECKED_BUILD
     74     EAS_U32             handleCheck;        /* signature check for checked build */
     75 #endif
     76     EAS_FILE_HANDLE     fileHandle;         /* pointer to input file */
     77     EAS_PCM_CALLBACK    pCallback;          /* pointer to callback function */
     78     EAS_VOID_PTR        cbInstData;         /* instance data for callback function */
     79     struct s_decoder_interface_tag EAS_CONST * pDecoder;    /* pointer to decoder interface */
     80     EAS_STATE           state;              /* stream state */
     81     EAS_I32             time;               /* media time */
     82     EAS_I32             startPos;           /* start of PCM stream */
     83     EAS_I32             loopLocation;       /* file location where loop starts */
     84     EAS_I32             byteCount;          /* size of file */
     85     EAS_U32             loopStart;          /* loop start, offset in samples from startPos */
     86                                             /* NOTE: For CMF, we use this to store total sample size */
     87     EAS_U32             loopSamples;        /* total loop length, in samples, 0 means no loop */
     88                                             /* NOTE: For CMF, non-zero means looped */
     89     EAS_U32             samplesInLoop;      /* samples left in the loop to play back */
     90     EAS_I32             samplesTilLoop;     /* samples left to play until top of loop */
     91     EAS_I32             bytesLeft;          /* count of bytes left in stream */
     92     EAS_I32             bytesLeftLoop;      /* count of bytes left in stream, value at start of loop */
     93     EAS_U32             phase;              /* current phase for interpolator */
     94     EAS_U32             basefreq;           /* frequency multiplier */
     95     EAS_U32             flags;              /* stream flags */
     96     EAS_U32             envData;            /* envelope data (and LFO data) */
     97     EAS_U32             envValue;           /* current envelope value */
     98     EAS_U32             envScale;           /* current envelope scale */
     99     EAS_U32             startOrder;         /* start order index, first is 0, next is 1, etc. */
    100     S_DECODER_STATE     decoderL;           /* left (mono) ADPCM state */
    101     S_DECODER_STATE     decoderR;           /* right ADPCM state */
    102     S_DECODER_STATE     decoderLLoop;       /* left (mono) ADPCM state, value at start of loop */
    103     S_DECODER_STATE     decoderRLoop;       /* right ADPCM state, value at start of loop */
    104     E_PCM_ENV_STATE     envState;           /* current envelope state */
    105     EAS_I16             volume;             /* volume for stream */
    106     EAS_I16             pitch;              /* relative pitch in cents - zero is unity playback */
    107     EAS_I16             gainLeft;           /* requested gain */
    108     EAS_I16             gainRight;          /* requested gain */
    109     EAS_I16             currentGainLeft;    /* current gain for anti-zipper filter */
    110     EAS_I16             currentGainRight;   /* current gain for anti-zipper filter */
    111     EAS_U16             blockSize;          /* block size for ADPCM decoder */
    112     EAS_U16             blockCount;         /* block counter for ADPCM decoder */
    113     EAS_U16             sampleRate;         /* input sample rate */
    114     EAS_U8              srcByte;            /* source byte */
    115     EAS_U8              msBitCount;         /* count keeps track of MS bits */
    116     EAS_U8              msBitMask;          /* mask keeps track of MS bits */
    117     EAS_U8              msBitValue;         /* value keeps track of MS bits */
    118     EAS_U8              msBitCountLoop;     /* count keeps track of MS bits, value at loop start */
    119     EAS_U8              msBitMaskLoop;      /* mask keeps track of MS bits, value at loop start */
    120     EAS_U8              msBitValueLoop;     /* value keeps track of MS bits, value at loop start */
    121     EAS_BOOL8           hiNibble;           /* indicates high/low nibble is next */
    122     EAS_BOOL8           hiNibbleLoop;       /* indicates high/low nibble is next, value loop start */
    123     EAS_U8              rateShift;          /* for playback rate greater than 1.0 */
    124 } S_PCM_STATE;
    125 
    126 /*----------------------------------------------------------------------------
    127  * S_DECODER_INTERFACE
    128  *
    129  * Generic interface for audio decoders
    130  *----------------------------------------------------------------------------
    131 */
    132 typedef struct s_decoder_interface_tag
    133 {
    134     EAS_RESULT (* EAS_CONST pfInit)(EAS_DATA_HANDLE pEASData, S_PCM_STATE *pState);
    135     EAS_RESULT (* EAS_CONST pfDecodeSample)(EAS_DATA_HANDLE pEASData, S_PCM_STATE *pState);
    136     EAS_RESULT (* EAS_CONST pfLocate)(EAS_DATA_HANDLE pEASData, S_PCM_STATE *pState, EAS_I32 time);
    137 } S_DECODER_INTERFACE;
    138 
    139 
    140 /* header chunk for SMAF ADPCM */
    141 #define TAG_YAMAHA_ADPCM    0x4d776100
    142 #define TAG_MASK            0xffffff00
    143 #define TAG_RIFF_FILE       0x52494646
    144 #define TAG_WAVE_CHUNK      0x57415645
    145 #define TAG_FMT_CHUNK       0x666d7420
    146 
    147 /*----------------------------------------------------------------------------
    148  * EAS_PESeek
    149  *----------------------------------------------------------------------------
    150  * Purpose:
    151  * Locate to a particular byte in a PCM stream
    152  *----------------------------------------------------------------------------
    153 */
    154 EAS_RESULT EAS_PESeek (EAS_DATA_HANDLE pEASData, S_PCM_STATE *pState, EAS_I32 *pLocation);
    155 
    156 #endif /* _EAS_PCMDATA_H */
    157 
    158