// --------------------------------------------------------------
// --------------------------------------------------------------
#ifndef _VCO_H_
#define	_VCO_H_

#include "synth_types.h"
#include "sine.h"
#include "blit.h"
#include "wavetable.h"
 
#define OSC_RECALC_THRESH			0.001f
#define OSC_IMPULS_HEIGHT			100.0f

// --------------------------------------------------------------
// Types
// --------------------------------------------------------------
enum
{	
	OSC_WAVEFORM_SAWTOOTH,
	OSC_WAVEFORM_SQUARE,
	OSC_WAVEFORM_TRIANGLE,
	OSC_WAVEFORM_SINE,
	OSC_WAVEFORM_IMPULSE,
	OSC_WAVEFORM_WAVETABLE,
	OSC_NUM_WAVEFORMS = OSC_WAVEFORM_WAVETABLE+WT_NUM_WAVETABLES
};

enum
{
	OSC_PARAM2_WAVEFORM,
	OSC_PARAM2_DUTYCYCLE,
	OSC_NUM_PARAMS
};

typedef struct _svco_common_t
{
	blit_common_t blit;
	wt_common_t wt;

} vco_common_t;

typedef struct _sosc_t
{
	UINT32 id;
	vco_common_t *pCom;
	synth_float_t param[OSC_NUM_PARAMS];
	synth_float_t fs;
	blit_t blep;
	wt_t wt;
	UINT32 bufsize;
	synth_float_t *pOut;
	sine_gen_t sine;
	synth_float_t impulse;
	
} osc_t;

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

// --------------------------------------------------------------
// Exported functions
// --------------------------------------------------------------
void VCO_ModInit(vco_common_t *pCom);
void VCO_ModFree(vco_common_t *pCom);
void VCO_Init(osc_t *pObj, UINT32 id, vco_common_t *pCom, synth_float_t fs);
void VCO_Free(osc_t *pObj);
void VCO_SetBufsize(osc_t *pObj, UINT32 size);
void VCO_SetFS(osc_t *pObj, synth_float_t fs);
void VCO_Reset(osc_t *pObj, synth_float_t phase);
void VCO_Start(osc_t *pObj);
void VCO_Param2Set(osc_t *pObj, UINT32 type, synth_float_t value);
void VCO_ProcessDataV(osc_t *pObj, synth_float_t *pPitch, synth_float_t *pCV_fm, synth_float_t *pCV_pwm, UINT32 *pSyncIn, UINT32 *pSyncOut, UINT32 len);
synth_float_t* VCO_GetProcessBuffer(osc_t *pObj);
#if defined(__cplusplus)
}

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

#endif // _VCO_H_
