// Covox.cpp: implementation of the CCovox class.
//


#include "stdafx.h"
#include "Covox.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction


CCovox::CCovox()
	: m_bStereo(false)
{
	ReInit();
}

CCovox::~CCovox()
{
}

void CCovox::ReInit()
{
	CalcFIR(m_pH, FIR_LENGTH, 8000.0, 0.0, LOWPASS);
}

void CCovox::SetSample(WORD inVal)
{
	if (m_bEnableSound)
	{
		m_dLeftAcc = char((LOBYTE(inVal)) - 128) / 256.0;
		m_dRightAcc = char((HIBYTE(inVal)) - 128) / 256.0;
	}
	else
	{
		m_dLeftAcc = 0.0;
		m_dRightAcc = 0.0;
	}
}

bool CCovox::GetSample(double &sampleL, double &sampleR)
{
	register double fL = m_dLeftAcc;
	register double fR = m_dRightAcc;
	fL = AutoGain(fL, m_dAvgL, m_pdBufferL, m_nBufferPosL);
	fR = AutoGain(fR, m_dAvgR, m_pdBufferR, m_nBufferPosR);
	//фильтр
	fL = FIRFilter(fL, m_LeftBuf, m_nLeftBufPos);
	fR = FIRFilter(fR, m_RightBuf, m_nRightBufPos);

	if (m_bStereo)
	{
		sampleL = fL;
		sampleR = fR;
	}
	else
	{
		sampleL = fL;
		sampleR = fL;
	}

	return true;
}
