/******************************************************************************
Copyright (c) 2006 Analog Devices, Inc.  All Rights Reserved.  This software is
proprietary and confidential to Analog Devices, Inc. and its licensors.
*******************************************************************************

$Revision: 1.1 $
$Date: 2008/03/17 14:50:34 $
$LastChangedBy: cjakob $

Project:    HE-AAC Decoder
Title:      riff_format.h
Author:     Cong Van Nguyen

Description:
            <Brief description of the purpose of this file>

References:
            RIFFheader.c
            REPAACPP-006 HE-AAC Decoder Test System Modifications.doc

******************************************************************************/

#ifndef RIFF_FORMAT_H
#define RIFF_FORMAT_H

#include<stdio.h>
#include<stdlib.h>

/****************************************************************************
 *      #defines                                                            *
 ****************************************************************************/


/****************************************************************************
 *      #defines                                                            *
 ****************************************************************************/


/****************************************************************************
 *      Typedefs/Enumerations                                               *
 ****************************************************************************/


/****************************************************************************
 *      Structure Declarations                                              *
 ****************************************************************************/


/****************************************************************************
 *      Function Declarations                                               *
 ****************************************************************************/

/*
**
** Function:            write_riff_buffer()
**
** Description:         Convert the output buffer of HE-AAC decoder to WAV-RIFF format
**
** Arguments:
**
**  fp1                 Handle of output WAV-RIFF file
**  x                   Output buffer of HE-AAC decoder
**  outbuf              Buffer for WAV-RIFF format
**  ch_dist             Distance (in 16-bit words) between channels in x
**  numSample           Number of samples in the buffer
**  chan                Number of channels
**  mono_dup            Indicate if the mono channel will be duplicated
**
**
** Outputs:             When chan>1, the data contained in seperate channels (in x)
**                      is multiplexed sample by sample according to the structure
**                      of WAV-RIFF PCM format, and then written out to the WAV-RIFF 
**                      file. When chan=1 and mono_dup=0, the single channel is simply
**                      written out. When chan=1 and mono_dup=1, the single channel is 
**                      duplicated before being written out.
**
** Return value:        0 is returned if data is written out successfully.
**                      -1 is returned if the parameter combination is illegal.
**
**
**
*/

int write_riff_buffer(FILE  *fp1,
                       short *x,     
                       short *outbuf,                  
                       int   ch_dist,
                       int   numSample,
                       int   chan,
                       int   mono_dup);


/*
**
** Function:            initialize_riff_header()
**
** Description:         Initialise the RIFF header for the output WAV-RIFF file
**
** Arguments:
**
**  fp1                 Handle of output WAV-RIFF file
**
**
** Outputs:             44 bytes in the beginnning of the WAV-RIFF file is
**                      reserved for the RIFF header, which is updated later
**                      when finalize_riff_header() is called.
**
** Return value:        None
**
**
**
*/

void initialize_riff_header(FILE *fp1);


/*
**
** Function:            finalize_riff_header()
**
** Description:         Finalise the RIFF header for the output WAV-RIFF file
**
** Arguments:
**
**  fp1                 Handle of output WAV-RIFF file
**  fs                  Sampling frequency (in Hz)
**  chan                Number of channels
**  mono_dup            Indicate if the mono channel will be duplicated
**
**
** Outputs:             The RIFF header is created after the whole audio sequence 
**                      is decoded.
**
** Return value:        None
**
**
**
*/

void finalize_riff_header(FILE *fp1,int fs,int chan,int mono_dup);


#endif /* RIFF_FORMAT_H */

/*
**
** EOF: $HeadURL: svn://dingofiles.spd.analog.com/audio/branches/aac-decoder/0.2.0/demo/bf533/riff_format.h $
**
*/

