1 /*****************************************************************************\ 2 Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. 3 This file is licensed under the Snes9x License. 4 For further information, consult the LICENSE file in the root directory. 5 \*****************************************************************************/ 6 7 #ifndef CXHAUDIO2_H 8 #define CXAUDIO2_H 9 #include "XAudio2.h" 10 #include "../snes9x.h" 11 #include <windows.h> 12 #include "IS9xSoundOutput.h" 13 14 class CXAudio2 : public IXAudio2VoiceCallback, public IS9xSoundOutput 15 { 16 private: 17 IXAudio2SourceVoice *pSourceVoice; 18 IXAudio2 *pXAudio2; 19 IXAudio2MasteringVoice* pMasterVoice; 20 21 bool initDone; // has init been called successfully? 22 23 volatile LONG bufferCount; // currently submitted XAudio2 buffers 24 25 UINT32 sum_bufferSize; // the size of soundBuffer 26 UINT32 singleBufferSamples; // samples in one block 27 UINT32 singleBufferBytes; // bytes in one block 28 UINT32 blockCount; // soundBuffer is divided into blockCount blocks 29 // currently set to 8 30 UINT32 writeOffset; // offset into the buffer for the next block 31 UINT32 partialOffset; // offset into non-complete block 32 uint8 *soundBuffer; // the buffer itself 33 34 bool InitVoices(void); 35 void DeInitVoices(void); 36 37 void PushBuffer(UINT32 AudioBytes,BYTE *pAudioData,void *pContext); 38 void BeginPlayback(void); 39 void StopPlayback(void); 40 void ProcessSound(void); 41 bool InitXAudio2(void); 42 void DeInitXAudio2(void); 43 int GetAvailableBytes(); 44 45 public: 46 CXAudio2(void); 47 ~CXAudio2(void); 48 49 // inherited from IXAudio2VoiceCallback - we only use OnBufferEnd 50 STDMETHODIMP_(void) OnBufferEnd(void *pBufferContext); OnBufferStart(void * pBufferContext)51 STDMETHODIMP_(void) OnBufferStart(void *pBufferContext){} OnLoopEnd(void * pBufferContext)52 STDMETHODIMP_(void) OnLoopEnd(void *pBufferContext){} OnStreamEnd()53 STDMETHODIMP_(void) OnStreamEnd() {} OnVoiceError(void * pBufferContext,HRESULT Error)54 STDMETHODIMP_(void) OnVoiceError(void *pBufferContext, HRESULT Error) {} OnVoiceProcessingPassEnd()55 STDMETHODIMP_(void) OnVoiceProcessingPassEnd() {} OnVoiceProcessingPassStart(UINT32 BytesRequired)56 STDMETHODIMP_(void) OnVoiceProcessingPassStart(UINT32 BytesRequired) {} 57 58 59 // Inherited from IS9xSoundOutput InitSoundOutput(void)60 bool InitSoundOutput(void) { return InitXAudio2(); } DeInitSoundOutput(void)61 void DeInitSoundOutput(void) { DeInitXAudio2(); } 62 bool SetupSound(void); 63 void SetVolume(double volume); 64 std::vector<std::wstring> GetDeviceList(); 65 int FindDeviceIndex(TCHAR *audio_device); 66 }; 67 68 #endif 69