/*---------------------------------------------------------------------------*/
/*
  File: resample.h

  HD audio resampling.
*/
/*---------------------------------------------------------------------------*/

#ifndef RESAMPLE_H_
#define RESAMPLE_H_

#ifdef __cplusplus
extern "C" {
#endif
/*---------------------------------------------------------------------------*/

#define RESAMPLE_LIGHTWEIGHT

#define RESAMPLE_MAX_RATIO           6

#define RESAMPLE_MODE_2              0
#define RESAMPLE_MODE_3              1
#define RESAMPLE_MODE_4              2
#define RESAMPLE_MODE_6              3
#define RESAMPLE_MODE_3_2            4
#define RESAMPLE_MODE_4_3            5
#define RESAMPLE_MODE_8_3            6

#ifdef RESAMPLE_LIGHTWEIGHT
#define RESAMPLE_FILTER_TAPS_HALF    8
#define RESAMPLE_FILTER_TAPS_HALF3   9
#else
#define RESAMPLE_FILTER_TAPS_HALF    24
#define RESAMPLE_FILTER_TAPS_HALF3   24
#endif
#define RESAMPLE_FILTER_TAPS         (2 * RESAMPLE_FILTER_TAPS_HALF)
#define RESAMPLE_FILTER_TAPS3        (2 * RESAMPLE_FILTER_TAPS_HALF3)
#define RESAMPLE_FILTER_COEFS        (RESAMPLE_MAX_RATIO * RESAMPLE_FILTER_TAPS)

#define RESAMPLE_DELAY               RESAMPLE_FILTER_TAPS_HALF

typedef struct resample_down_s
{
  word mode;
  word filter_pos;
  short filter_buffer[RESAMPLE_FILTER_COEFS + 1];
} t_resample_down;

typedef struct resample_up_s
{
  word mode;
  word filter_pos;
  short filter_buffer[RESAMPLE_FILTER_TAPS];
} t_resample_up;


void resample_down_init (t_resample_down *p_resample, word mode);
void resample_down (t_resample_down *p_resample,
  const short *in_sample_buffer, word out_sample_count, short *out_sample_buffer);
void resample_up_init (t_resample_up *p_resample, word mode);
void resample_up (t_resample_up *p_resample,
  const short *in_sample_buffer, word in_sample_count, short *out_sample_buffer);
void resample_up_put_sample (t_resample_up *p_resample, short in_sample);


/*---------------------------------------------------------------------------*/
#ifdef __cplusplus
}
#endif

#endif

/*---------------------------------------------------------------------------*/
