CLAM-Development
1.1
|
00001 /* 00002 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG) 00003 * UNIVERSITAT POMPEU FABRA 00004 * 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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 // Helper template functions for safe pointer releasing and deleting 00050 00051 template < typename PointerType > 00052 bool SafeDelete( PointerType& ptr ) 00053 { 00054 if ( ptr ) // ptr is not null 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 ) // Obj is not null 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 // Handle to a Window's window. This allows us to claim some 00084 // OS resources ( such as access to audio devices ). 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; // The DirectSound Object pointer 00129 LPDIRECTSOUNDCAPTURE mDSCapture; // The DirectSoundCapture Object pointer 00130 LPDIRECTSOUNDBUFFER mDSBPrimary; // The Primary Sound Buffer 00131 LPDIRECTSOUNDBUFFER mDSBOutput; // The Output (Secondary) Sound Buffer 00132 LPDIRECTSOUNDCAPTUREBUFFER mDSBCapture; // The Input ( SoundCapture ) Device Buffer 00133 LPDIRECTSOUNDNOTIFY mDSNotify; // The DirectSound Notify Object 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