///////////////////////////////////////////////////////////////////////////////
/// @file DirectSound.hpp
///
/// @brief Destiny Sound System DirectSound interface
///
/// @author paradoxnj
///
/// This file is the intellectual property of Novus Delta, LLC.. Usage of the
/// contents of this file is subject to the Destiny3D Member License which
/// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
///
/// This file is distributed "AS IS" without warranty of any kind.  Novus
/// Delta, LLC. does not guarantee the fitness of the contents of this file
/// for any particular purpose.
///
/// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
///
/// <hr>
///                                 Change History
/// <hr>
///
/// @date Jan 2002
/// @author paradoxnj
/// @remarks Creation
///
///////////////////////////////////////////////////////////////////////////////

#ifndef DIRECTSOUND_H
#define DIRECTSOUND_H

//#include <windows.h>
#include <dsound.h>

#include "deSound_priv.hpp"
#include "Channels.hpp"

class IdeSoundSystem_DS : public IdeSoundSystem, public deRefCountBase
{
public:
	IdeSoundSystem_DS();
	virtual ~IdeSoundSystem_DS();

public:
	IDirectSound8				*m_pDS;
	IDirectSoundBuffer			*m_pPrimaryBuffer;
	IDirectSound3DListener		*m_pListener;

	WAVEFORMATEX				m_Format;
	int							m_RefCount;

public:
	void						*GetInterface(int interface_id);

	deBoolean					Initialize(HWND hWnd);
	void						Destroy();

	IdeSoundBuffer				*CreateSoundBuffer(IdeSoundData *sndData);

	float						GetRollOffFactor();
	float						GetDopplerFactor();
	float						GetDistanceFactor();

	void						SetRollOffFactor(float factor);
	void						SetDopplerFactor(float factor);
	void						SetDistanceFactor(float factor);

	deBoolean					GetListenerPosition(float *x, float *y, float *z);
	deBoolean					GetListenerPosition(deVec3d *pos);

	deBoolean					GetListenerVelocity(float *x, float *y, float *z);
	deBoolean					GetListenerVelocity(deVec3d *vel);

	deBoolean					GetListenerOrientation(float *Fx, float *Fy, float *Fz, float *Tx, float *Ty, float *Tz);
	deBoolean					GetListenerOrientation(deVec3d *Front, deVec3d *Top);

	void						SetListenerPosition(float x, float y, float z);
	void						SetListenerPosition(deVec3d pos);

	void						SetListenerVelocity(float x, float y, float z);
	void						SetListenerVelocity(deVec3d vel);

	void						SetListenerOrientation(float Fx, float Fy, float Fz, float Tx, float Ty, float Tz);
	void						SetListenerOrientation(deVec3d Front, deVec3d Top);
};

class IdeSoundBuffer_DS : public IdeSoundBuffer, public deRefCountBase
{
public:
	IdeSoundBuffer_DS();
	IdeSoundBuffer_DS(IdeSoundSystem *ss, IdeSoundData *data);
	virtual ~IdeSoundBuffer_DS();

public:
	IDirectSoundBuffer			*m_pBuffer;
	IDirectSound3DBuffer		*m_p3DBuffer;
	WAVEFORMATEX				m_Format;
	DSBUFFERDESC				m_Desc;

	deSoundCfg					m_Cfg;

	IdeSoundSystem_DS			*m_pSS;
	int							m_RefCount;

	IdeSoundData				*m_pData;

	DWORD						m_BufferSize;
	int							m_CurrWritePos;
	DWORD						m_DataPosition;
	DWORD						m_SecureDistance;
	u32							m_LastPlayPos;
	u32							m_BufferLoops;

	deBoolean					m_Loop;

public:
	deBoolean					Initialize(IdeSoundSystem *ss, IdeSoundData *data);
	deBoolean					Destroy();

	IdeResourceBase				*MakeCopy();
	void						*GetInterface(int interface_id);

	void						GetConfig(deSoundCfg &Cfg);
	void						SetConfig(deSoundCfg Cfg);

	deBoolean					SetVolume(long vol);
	deBoolean					SetPan(long pan);
	deBoolean					SetFrequency(long freq);

	long						GetVolume();
	long						GetPan();
	long						GetFrequency();

	deBoolean					ApplySettings();

	deBoolean					Play(deBoolean loop = deFALSE);
	deBoolean					Update();
	deBoolean					Stop(deBoolean rewind = deTRUE);
	deBoolean					IsPlaying();
	deBoolean					Rewind();
};
	
#endif

