/*
 * Copyright 2010 Trident Microsystems (Far East) Ltd. All rights reserved.
 * All prior copyright rights in this work and the accompanying software
 * products transferred to Trident Microsystems (Far East) Ltd. by written
 * agreement.
 */
/*****************************************************************************/
/* Copyright (c) 2010 NXP B.V.  All rights are reserved.                     */
/*                                                                           */
/* Redistribution and use in source and binary forms, with or without        */
/* modification, are permitted provided that the following conditions        */
/* are met:                                                                  */
/*                                                                           */
/* Redistributions of source code must retain the above copyright            */
/* notice, this list of conditions and the following disclaimer.             */
/*                                                                           */
/* Redistributions in binary form must reproduce the above copyright         */
/* notice, this list of conditions and the following disclaimer in the       */
/* documentation and/or other materials provided with the distribution.      */
/*                                                                           */
/* Neither the name of NXP nor the names of its                              */
/* contributors may be used to endorse or promote products derived from      */
/* this software without specific prior written permission.                  */
/*                                                                           */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR     */
/* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      */
/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,     */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT          */
/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,     */
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     */
/* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       */
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE         */
/* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH          */
/* DAMAGE.                                                                   */
/*                                                                           */
/*****************************************************************************/
/*
 * Module name  : tmAudioFormats.h  %version: SOUsb225#3 % 
 *
 * Last Update  : %date_modified: Tue Jul  8 18:07:48 2003 %
 *
 * Description: This header file contains the standard enumerations, types, and
 * structures used for the DVP audio and video software streams.
 *
 * TriMedia audio and video format definitions. The definitions in this file are
 * fundamental to the TM Software Streaming Architecture (TSSA).
 *
 * Document ref: DVP Coding Guidelines Specification
 *
 *############################################################
 */

#ifndef TMAUDIOFORMATS_H
#define TMAUDIOFORMATS_H

//-----------------------------------------------------------------------------
// Standard include files:
//-----------------------------------------------------------------------------
//

//-----------------------------------------------------------------------------
// Project include files:
//-----------------------------------------------------------------------------
//
#ifndef TMNXTYPES_H
#include "tmNxTypes.h"                    // DVP Standard data types/defines
#endif

#ifdef __cplusplus
extern "C"
{
#endif

//-----------------------------------------------------------------------------
// Types and defines:
//-----------------------------------------------------------------------------
//

/* Audio format type definitions */
//DOCNEEDED10
typedef enum tmAudioTypeFormat {
    atfGeneric              = (Int) 0xffffffffu,
    atfNone                 = (Int) 0x80000000u,    /* old */
    atfMuLaw                = 0x00000001,
    atfALaw                 = 0x00000002,
    atfADPCM                = 0x00000004,
    atfMPEG                 = 0x00000008,
    atfG723                 = 0x00000010,
    atfG728                 = 0x00000020,
    atfG729                 = 0x00000040,
    atfQuicktimeAudio       = 0x00000080,
    atfReserved1            = 0x00000100,   /* atfMPEG1Audio is obsolete: use atfMPEG and subtype */
    atfReserved2            = 0x00000200,   /* atfMPEG2Audio is obsolete: use atfMPEG and subtype */
    atfReserved3            = 0x00000400,   /* atfMPEG2AugmentedAudio is obsolete: use atfMPEG and subtype */
    atfSDDS                 = 0x00000800,
    atfAC3                  = 0x00001000,
    atfDTS                  = 0x00002000,
    atfLinearPCM            = 0x00004000,
    atf1937                 = 0x00008000,
    atfSPDIF                = 0x00010000,   /* used with SPDO */
    atfBurst                = 0x00020000,
    atfDvdPcm               = 0x00040000
} tmAudioTypeFormat_t;                           /* can be OR'ed */

//=============================================================================
// Audio PCM Formats:
//=============================================================================

typedef enum tmAudioPcmFormat {
    apfGeneric              = (Int) 0xffffffffu,
    apfNone                 = (Int) 0x80000000u,
    apfMono8                = 0x00000001, //DOCNEEDED11
    apfStereo8              = 0x00000002, //DOCNEEDED12
    apfMono16               = 0x00000004,
    apfStereo16             = 0x00000008,
    apfFourCh_3_1_0_16      = 0x00000010,    /* three front, 1 surround, no sub */
    apfFourCh_2_2_0_16      = 0x00000020,    /* 2 front, 2 surround, no sub */
    apfFourCh_2_1_1_16      = 0x00000040,    /* 2 front, 1 surround, 1 sub */
    apfFourCh_3_0_1_16      = 0x00000080,    /* 3 front, no surround, 1 sub */
    apfFiveDotOne16         = 0x00000100,
    apfSevenDotOne16        = 0x00000200, //DOCNEEDED13
    apfMulti16              = 0x00000400, //DOCNEEDED14

    apfMono32               = 0x00000800,
    apfStereo32             = 0x00001000,
    apfFourCh_3_1_0_32      = 0x00002000,   /* three front, 1 surround, no sub */
    apfFourCh_2_2_0_32      = 0x00004000,   /* 2 front, 2 surround, no sub */
    apfFourCh_2_1_1_32      = 0x00008000,   /* 2 front, 1 surround, 1 sub */
    apfFourCh_3_0_1_32      = 0x00010000,   /* 3 front, no surround, 1 sub */
    apfFiveDotOne32         = 0x00020000,
    apfSevenDotOne32        = 0x00040000, //DOCNEEDED15
    apfMulti32              = 0x00080000, //DOCNEEDED16

    apfMonoFloat            = 0x00100000, //DOCNEEDED17
    apfStereoFloat          = 0x00200000, //DOCNEEDED18
    apfFourCh_3_1_0_float   = 0x00400000,   /* three front, 1 surround, no sub */ //DOCNEEDED19
    apfFourCh_2_2_0_float   = 0x00800000,   /* 2 front, 2 surround, no sub */ //DOCNEEDED20
    apfFourCh_2_1_1_float   = 0x01000000,   /* 2 front, 1 surround, 1 sub */ //DOCNEEDED21
    apfFourCh_3_0_1_float   = 0x02000000,   /* 3 front, no surround, 1 sub */ //DOCNEEDED22
    apfFiveDotOneFloat      = 0x04000000, //DOCNEEDED23
    apfSevenDotOneFloat     = 0x08000000, //DOCNEEDED24
    apfMultiFloat           = 0x10000000, //DOCNEEDED25

    apfReserved             = 0x20000000,
    apfReserved2            = 0x40000000
} tmAudioPcmFormat_t;                        /* can be OR'ed */

/**
 ** Channel offsets in interleaved multi-channel buffers.
 **/
#define AVFORMAT_CHAN_OFFSET_LEFT       0
#define AVFORMAT_CHAN_OFFSET_RIGHT      1
#define AVFORMAT_CHAN_OFFSET_CENTER     2
#define AVFORMAT_CHAN_OFFSET_LFE        3
#define AVFORMAT_CHAN_OFFSET_L_SURROUND 4
#define AVFORMAT_CHAN_OFFSET_R_SURROUND 5

#define AVFORMAT_CHAN_OFFSET_L_CENTER   6
#define AVFORMAT_CHAN_OFFSET_R_CENTER   7

#define AVFORMAT_CHAN_OFFSET_R_FROM_L   1

/* Subtypes to identify MPEG audio formats */
typedef enum tmAudioMPEGFormat {
    amfGeneric              = (Int) 0xffffffffu,
    amfNone                 = (Int) 0x80000000u,
    amfMPEG1_Layer1         = 0x00000001, //DOCNEEDED26
    amfMPEG1_Layer2         = 0x00000002,
    amfMPEG1_Layer3         = 0x00000004,
    amfMPEG2                = 0x00000008, //DOCNEEDED27
    amfMPEG1_Augmented      = 0x00000010, //DOCNEEDED28

//{{TTI
    amfMPEG4_AAC            = 0x00000020, //DOCNEEDED29
    amfMPEG4_CELP           = 0x00000040, //DOCNEEDED30
    amfMPEG2_AAC            = 0x00000080, //DOCNEEDED31

    amfMPEG_AAC             = amfMPEG2_AAC
//}}
} tmAudioMPEGFormat_t;                        /* can be OR'ed */

//{{SSGSVL
//DOCNEEDED32
typedef enum tmAudioSubtypeMicrosoft {
    asmsV7 = 0x00000001,
    asmsV8 = 0x00000002,
    asmsV9 = 0x00000004
} tmAudioSubtypeMicrosoft_t;

//DOCNEEDED33
typedef enum {
    asRealAudio1           = 0x00000001,
    asRealAudio2           = 0x00000002,
    asRealAudio3           = 0x00000004,
    asRealAudioSpeechCoder = 0x00000008,
    asRealAudioG2          = 0x00000010,
    asRealAudio8           = 0x00000020,
    asRealAudio9           = 0x00000040
} tmAudioSubtypeRealNetworks_t;
//}}

typedef enum tmAudioAnalogAdapter {
    aaaGeneric              = (Int) 0xffffffffu,
    aaaNone                 = (Int) 0x80000000u,
    aaaMicInput             = 0x00000001,
    aaaLineInput            = 0x00000002,
    aaaAuxInput1            = 0x00000004,
    aaaAuxInput2            = 0x00000008,
    aaaDigitalInput         = 0x00000010,
    aaaLineOutput1          = 0x00000100,
    aaaLineOutput2          = 0x00000200,
    aaaAuxOutput1           = 0x00000400,
    aaaAuxOutput2           = 0x00000800,
    aaaDigitalOutput        = 0x00001000
} tmAudioAnalogAdapter_t;                     /* can be OR'ed */

/* subclass of tmAvFormat_t */
typedef
    struct tmAudioFormat
    {
        tmAvFormatVARIABLES;
        Float sampleRate;
    }
    tmAudioFormat_t, *ptmAudioFormat_t;

/* These are used in the description field of tmAudioFormat_t */
#define AVFORMAT_PROLOGIC_ENCODED       0x100
#define AVFORMAT_NUMBER_OF_BITS_MASK    0xFF
#define AVFORMAT_DUAL_MONO              0x200

/**
 ** Type definition of the Circular Channel Buffer.
 ** Used in the core of audio signal processing (ASP) modules,
 ** like mixers to store and exchange working data.
 ** The circular feature allows natural support of the delay memory
 ** that is required in multichannel systems for speaker alignment.
 ** It might also be useful for reverbs and sample rate convertors.
 ** If a particular system does not need it, set bufferLength equal
 ** to chunkLength, and all code should work correctly.
 **/
//DOCNEEDED34
typedef struct  tmAvAspChanBuff
{
    Int32  *data;           /** Allocated Circular Buffer pointer.
                             ** These buffers are always 32 bit integer.
                             **/
    UInt32  owner;          /** Allows system to keep track of who allocated.
                             **/
    Int     bufferLength;   /** Allocated Buffer length in samples.
                             ** Including delay samples.
                             ** length = chunk length + maxDelay,
                             ** rounded up to the nearest multiple of chunkLength
                             ** Buffer size in bytes is: length * sizeof(Int32)
                             **/
    Int     bufferSize;     /** Allocated Buffer size in bytes.
                             **/
    Int     chunkLength;    /** Processed block length in samples
                             ** Must be a multiple of 8.
                             ** Processors generally process one chunk.
                             **/
    Int     chunkSize;      /** Processed block size in bytes
                             ** Usually, the packet size of TSSA packet.
                             **/
    Int     maxDelay;       /** Maximum delay value, in samples.
                             ** Specify buffer size using this.  Zero is OK.
                             **/
    Int     delay;          /** Current delay value
                             **/
    Int     bitsPerSample;  /** Sample precision in bits.
                             ** can be 16, 18,20 or 24 bits.
                             ** Data is always store on 32 bit boundaries.
                             **/
    Int32  *writePtr;       /** Current write position in the
                             ** circular buffer.
                             ** This position is always aligned to a
                             ** multiple of chunkSize.
                             **/
    Int32  *procPtr;        /** Current process position in the
                             ** circular buffer.
                             ** The pointer is the sane as the writePtr
                             ** just before copying new samples in
                             ** circular buffer. The write pointer
                             ** is moved to the next write position
                             ** while process pointer always point to
                             ** the current chunk to be used by all
                             ** in-place working filter.
                             **/
    Int32  *readPtr;        /** Current read position in the circular
                             ** buffer.
                             ** This pointer is not necessary aligned
                             ** to a multiple of chunkSize. It depends
                             ** on delay value.
                             **/
    Int32  *endPtr;         /** Pointer to the first sample after
                             ** allocated circular buffer
                             ** Use for circular boundery check.
                             **/
} tmAvAspChanBuff_t, *ptmAvAspChanBuff_t;

/* Subtypes to identify audio stream formats */
typedef enum{
    aifGeneric              = 0xffffffff,
    aifNone                 = 0x80000000,
    aifPes                  = 0x00000001, // MPEG2 packetized ES
    aifMpeg1                = 0x00000002, // MPEG1 packet stream
    aifEs                   = 0x00000004, // Elementary stream
    aifOther                = 0x00000008, // Format defined in extension
    aifDvd                  = 0x00000010, // DVD PES stream
    aifDss                  = 0x00000020  // Direct TV stream
}   tmAudioStreamFormat_t;

#ifdef __cplusplus
}
#endif

#endif
