// --------------------------------------------------------------
// --------------------------------------------------------------
#ifndef _BLIT_H_
#define	_BLIT_H_

#include "synth_defs.h"
#include "noise.h"
#include "synth_types.h"

#define BLIT_MISC_PROCESS_DOWN_SAMPLE	2
#define BLIT_JITTER_ERROR				0.0000001

// --------------------------------------------------------------
// Types
// --------------------------------------------------------------
typedef struct _sblit_common_t
{
	UINT32 *pTableSizes;
	synth_float_t **ppBLEP;
	synth_float_t N_K[(BLIT_INTEROLATION_ORDER+0)*(BLIT_INTEROLATION_ORDER+1)];
	synth_float_t K[(BLIT_INTEROLATION_ORDER+0)*(BLIT_INTEROLATION_ORDER+1)];
	noise_gen_t noise;

} blit_common_t;


typedef struct _sblit_t
{
	blit_common_t *pCom;
	synth_float_t fs, fm, pwm, dutycycle, pulse_offset;
	synth_float_t saw_x, x2, dx;
	synth_float_t sqr_x1, sqr_x2, tri;
	synth_float_t tri_x, tri_sum;
	UINT32 m, tri_pol, sqr_pol1, sqr_pol2; 
	UINT32 freq_update_req, bufsize;
	synth_float_t jitter;
	UINT32 misc_process_downsammple_counter;
} blit_t;

// --------------------------------------------------------------
#if defined(__cplusplus)
extern "C" {
#endif

// --------------------------------------------------------------
// Exported functions
// --------------------------------------------------------------
void BLIT_ModInit(blit_common_t *pCom);
void BLIT_ModFree(blit_common_t *pCom);
void BLIT_Init(blit_t *pObj, blit_common_t *pCom, synth_float_t fs);
void BLIT_Free(blit_t *pObj);
void BLIT_SetBufsize(blit_t *pObj, UINT32 size);
void BLIT_SetFS(blit_t *pObj, synth_float_t fs);
void BLIT_Reset(blit_t *pObj, synth_float_t phase);
void BLIT_Start(blit_t *pObj);
void BLIT_Prepare(blit_t *pObj, UINT32 len);
void BLIT_SetDutyCycle(blit_t *pObj, synth_float_t duty_cycle);
void BLIT_Process_SAW_Vector(blit_t *pObj, synth_float_t *pPitch, synth_float_t *pCV_fm, UINT32 *pSyncIn, UINT32 *pSyncOut, synth_float_t *pOut, UINT32 len);
void BLIT_Process_SQR_Vector(blit_t *pObj, synth_float_t *pPitch, synth_float_t *pCV_fm, synth_float_t *pCV_pwm, UINT32 *pSyncIn, UINT32 *pSyncOut, synth_float_t *pOut, UINT32 len);
void BLIT_Process_TRI_Vector(blit_t *pObj, synth_float_t *pPitch, synth_float_t *pCV_fm, UINT32 *pSyncIn, UINT32 *pSyncOut, synth_float_t *pOut, UINT32 len);

#if defined(__cplusplus)
}

#endif
// --------------------------------------------------------------

#endif // _BLIT_H_
