#ifndef Sound_H
#define Sound_H

#include "Include/GSLSoundV.h"
#ifdef WIN32
#include <mmsystem.h>
#endif
#include "GSLDatei.h"
#include <Critical.h>

using namespace Framework;

namespace GSL
{
	class GSLSound : public GSLSoundV
	{
	private:
		Datei *dat;
		SoundKopf kpf;
#ifdef WIN32
        int status;
		HWAVEOUT hAudioId;
		unsigned int uAudioDelay;
		unsigned int uAudioCount;
		WAVEHDR *aAudioHdr[ 16 ];
		char *aAudioPtr[ 16 ];
		unsigned int uAudioPlay;
		Critical hAudioCs;
		HANDLE hAudioEvent;
		WAVEOUTCAPS sAudioCaps;
		unsigned int uAudioWrite;
		unsigned int uAudioStop;
		int lAudioDone;
		unsigned int uAudioWrOk;
		volatile int iAudioThEnd;
		unsigned int aAudioSize[ 8 ];
		float linksV;
		float rechtsV;
#endif

		// privat
		int audioOpen();
		int audioClose();
		int audioStop();
		int audioSchreiben( unsigned int uCount );
		int audioLesen( char *buff, int len );

	public:
		// Konstruktor
		GSLSound( const SoundKopf &skpf );
		// Destruktor
		virtual ~GSLSound();
		// nicht constant
		void playSound() override;
		void setPause( bool p ) override;
		void stopSound() override;
		void warteAufSound( int zeit ) override;
		void setVolume( unsigned int links, unsigned int rechts ) override;
#ifdef WIN32
		void msg( UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2 );
#endif
		void thread() override;
		// zum Speichern
		void open() override;
		int getDaten( char *buffer, int len ) override;
		void close() override;
		bool istMono() const override;
		int getSampleRate() const override;
        __int64 getDatLength() const override;
		// constant
#ifdef WIN32
		HWAVEOUT getHandle() const;
#endif
		// Reference Counting
        Thread *getThis() override;
        Thread *release() override;
	};
}

#endif