
#include "../SDK/foobar2000.h"

#include "Common.h"
#include "ssrc/ssrc.h"

struct
PARAM_GLOBAL
{
	int		srate;
	int		quality;
};

class
dsp_ssrc_entry : public resampler_entry
{
public:
	dsp_ssrc_entry(void);

	virtual void	get_name(pfc::string_base& p_out);
	virtual bool	get_default_preset(dsp_preset& p_out);
	virtual bool	instantiate(service_ptr_t<dsp>& p_out, const dsp_preset& p_preset);
	virtual GUID
	get_guid(void)
	{
		// {2CD0EDC5-07A7-4b2b-914E-8766CCB62105}
		static const GUID	guid =
		{0x2cd0edc5, 0x7a7, 0x4b2b, {0x91, 0x4e, 0x87, 0x66, 0xcc, 0xb6, 0x21, 0x5}};

		return guid;
	}
	virtual bool
	have_config_popup(void)
	{
		return true;
	}
	virtual bool	show_config_popup(dsp_preset& p_data, HWND p_parent);
	virtual bool	is_conversion_supported(unsigned int src_srate, unsigned int dst_srate);
	virtual bool	create_preset(dsp_preset& p_out, unsigned p_target_srate, float p_qualityscale);
	virtual float
	get_priority(void)
	{
		return 1.;
	}
};

class
dsp_ssrc : public dsp_impl_base_t<dsp_v2>
{
public:
	dsp_ssrc(PARAM_GLOBAL* ParamGlobal);
	~dsp_ssrc(void);

	virtual void	on_endoftrack(abort_callback& p_abort);
	virtual void	on_endofplayback(abort_callback& p_abort);
	virtual bool	on_chunk(audio_chunk* chunk, abort_callback& p_abort);
	virtual void	flush(void);
	virtual double	get_latency(void);
	virtual bool	need_track_change_mark(void)
	{
		return false;
	}

private:
	enum
	{
		DATA_FORMAT_LINEAR_PCM,
		DATA_FORMAT_IEEE_FLOAT,
	};
	Resampler_base*	res;
	bool	error;
	int		nch;
	int		srate;
	int		dest_srate;
	int		quality;

	bool	setup_chunk(audio_chunk* chunk);
};

