/*
	$Id: soundprovider_recorder_directsound.h,v 1.3 2003/10/14 15:52:13 mbn Exp $

	------------------------------------------------------------------------
	ClanLib, the platform independent game SDK.

	This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
	version 2. See COPYING for details.

	For a total list of contributers see CREDITS.

	See http://www.clanlib.org
	------------------------------------------------------------------------
*/

#ifndef header_soundrecorder_directsound
#define header_soundrecorder_directsound

#if _MSC_VER > 1000
#pragma once
#endif

#include "API/Sound/soundprovider.h"
#include "API/Sound/soundprovider_session.h"
#include "API/Core/System/thread.h"
#include "API/Core/System/mutex.h"
#include <dsound.h>

class CL_SoundProvider_Recorder_DirectSound_Session : public CL_SoundProvider_Session, CL_Runnable
{
//! Construction:
public:
	CL_SoundProvider_Recorder_DirectSound_Session(int frequency);

	virtual ~CL_SoundProvider_Recorder_DirectSound_Session();

//! Attributes:
public:
	virtual int get_num_samples() const;

	virtual int get_frequency() const;

	virtual CL_SoundFormat get_format() const;

	virtual int get_num_channels() const;

	virtual int get_position() const;

//! Operations:
public:
	virtual bool eof() const;
	
	virtual void stop();

	virtual bool play();
		
	virtual bool set_position(int pos);
	
	virtual int get_data(void **data_ptr, int data_requested);

//! Implementation:
private:
	virtual void run();

	int frequency;

	int position;

	LPDIRECTSOUNDCAPTURE8 dsoundcapture;

	LPDIRECTSOUNDCAPTUREBUFFER capturebuffer;

	LPDIRECTSOUNDNOTIFY8 notify;

	HANDLE notify_event;

	int bytes_per_sample;

	int frag_size, num_fragments;

	char *buffer;

	int buffer_size;

	CL_Mutex mutex;

	volatile bool stop_thread;

	CL_Thread thread;
};

#endif
