/**
 * Audio processing blocks for channel simulation.
 *
 * @copyright 2008, Research In Motion Ltd.
 *
 * @version $Id: //depot/rel/dsp/ecall/2/c/testlab/audio.h#1 $
 */

#ifndef __AUDIO_H__
#define __AUDIO_H__

#include <stdio.h>
#include "process.h"
#include "msg.h"

#define FRAME_SIZE 160

/*
 * 30ms @ 8kHz = 240 samples 
 */
#define MAX_DELAY 240

#define DELAY_BUF_SIZE (MAX_DELAY + FRAME_SIZE)

typedef struct {
    float inHistory[2]; 
    float outHistory[2];  
    float inCoef[3];
    float outCoef[3];
} BiquadState;

typedef struct {
    int read; 
    int write;  
    Int16 buffer[DELAY_BUF_SIZE];
} DelayState;

typedef struct {
    CodecType codecType;
    CodecMode codecMode;
    Process e;       // encoder process
    Process d;       // decoder process
    FILE *errorFile;
} CodecState;

//Delay
void DelayInit(DelayState *state, Ord16 nSamples);
void DelayProcess(DelayState *state, Int16 *samples);

//Filter
void BiquadInit(BiquadState *state, const float a[3], const float b[3]);
void BiquadProcess(BiquadState *state, Int16 *samples);

//Channel
BOOL CodecInit(
    CodecState *state, 
    CodecType type,
    CodecMode mode,
    VadType vad,
    const char *errorPattern,
    Ord32 errorPatternIndex);
void CodecProcess(CodecState *state, Int16 *samples);
void CodecFinal(CodecState *channelState);

#endif
