00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __DXFULLDUPLEX__
00023 #define __DXFULLDUPLEX__
00024
00025 #include <dsound.h>
00026 #include <dxerr8.h>
00027 #include "Err.hxx"
00028 #include "DataTypes.hxx"
00029 #include "Assert.hxx"
00030
00031 namespace CLAM
00032 {
00033
00034 class ErrDXFullDuplex : public Err
00035 {
00036 public:
00037 const char* mTxt;
00038 HRESULT mHR;
00039 ErrDXFullDuplex(const char* txt,HRESULT hr)
00040 : Err(), mTxt(txt),mHR(hr)
00041 {
00042 const char* dxErrStr = DXGetErrorString8(hr);
00043 mMsg = (char*) malloc(strlen(txt)+strlen(dxErrStr)+1);
00044 strcpy(mMsg,txt);
00045 strcat(mMsg,dxErrStr);
00046 }
00047 };
00048
00049
00050
00051 template < typename PointerType >
00052 bool SafeDelete( PointerType& ptr )
00053 {
00054 if ( ptr )
00055 {
00056 delete ptr;
00057 ptr = NULL;
00058 }
00059 else
00060 return false;
00061
00062 return true;
00063 }
00064
00065 template < typename DXObjectType >
00066 bool SafeRelease( DXObjectType& obj )
00067 {
00068 if ( obj )
00069 {
00070 obj->Release();
00071 obj = NULL;
00072 }
00073 else
00074 return false;
00075
00076 return true;
00077 }
00078
00079 class DXFullDuplex
00080 {
00081 public:
00082
00083
00084
00085 static HWND shMainWnd;
00086
00087 DXFullDuplex( TUInt32 irate, TByte ichannels, TSize latency, LPGUID pGUID );
00088 ~DXFullDuplex();
00089
00090 HRESULT Start( void );
00091 HRESULT Poll( void );
00092 HRESULT Write( short* buf, TSize size );
00093 HRESULT Read ( short* buf, TSize size );
00094
00095 private:
00096
00100 HRESULT RestoreBuffer( LPDIRECTSOUNDBUFFER pDSBuffer,
00101 bool& wasRestored );
00102
00106 virtual void SetWaveFormat( WAVEFORMATEX* pwfx );
00107
00112 HRESULT InitDSoundDevices( void );
00113
00120 HRESULT CreateDXBuffers( void );
00121
00122 void CheckResult( const char* msg, HRESULT hr );
00123
00124 private:
00125
00126 LPGUID mGUID;
00127
00128 LPDIRECTSOUND mDS;
00129 LPDIRECTSOUNDCAPTURE mDSCapture;
00130 LPDIRECTSOUNDBUFFER mDSBPrimary;
00131 LPDIRECTSOUNDBUFFER mDSBOutput;
00132 LPDIRECTSOUNDCAPTUREBUFFER mDSBCapture;
00133 LPDIRECTSOUNDNOTIFY mDSNotify;
00134
00135 DWORD mOutputBufferSize;
00136 DWORD mCaptureBufferSize;
00137 DWORD mNextCaptureOffset;
00138 DWORD mNextOutputOffset;
00139
00140 WAVEFORMATEX mCaptureWaveFormat;
00141 WAVEFORMATEX mOutputFormat;
00142
00143 TUInt32 mSampleRate;
00144 TByte mChannels;
00145
00146 bool mWritingToPrimary;
00147
00148 public:
00149 DWORD mLatency;
00150
00151 };
00152
00153 }
00154
00155 #endif // DXFullDuplex.hxx
00156