Window::Current->Activated += ref new WindowActivatedEventHandler(this, &App::OnWindowActivationChanged);
Window::Current->Activate();
- simpleSprites_ = ref new SimpleSprites();
- simpleSprites_->Initialize(Window::Current->CoreWindow,mainPage,DisplayProperties::LogicalDpi);
+ gameMain_ = ref new GameMain();
+ gameMain_->Initialize(Window::Current->CoreWindow,mainPage,DisplayProperties::LogicalDpi);
eventToken_ =
CompositionTarget::Rendering::add
(ref new EventHandler<Object^>(this, &App::OnRendering));
+
ApplicationView::GetForCurrentView()->ViewStateChanged +=
ref new TypedEventHandler<ApplicationView^, ApplicationViewStateChangedEventArgs^>(
this,
)
{
timer_->Update();
- simpleSprites_->Update(timer_->Total,timer_->Delta);
- simpleSprites_->Render();
- simpleSprites_->Present();
+ gameMain_->Update(timer_->Total,timer_->Delta);
+ gameMain_->Render();
+ gameMain_->Present();
}
//--------------------------------------------------------------------------------------
_In_ WindowSizeChangedEventArgs^ args
)
{
- simpleSprites_->UpdateForWindowSizeChange();
+ gameMain_->UpdateForWindowSizeChange();
}
//--------------------------------------------------------------------------------------
_In_ Object^ sender
)
{
- simpleSprites_->SetDpi(DisplayProperties::LogicalDpi);
+ gameMain_->SetDpi(DisplayProperties::LogicalDpi);
}
//--------------------------------------------------------------------------------------
void App::OnWindowActivationChanged(
#include "pch.h"
#include "App.g.h"
-#include "SimpleSprites.h"
+#include "SoundDriver.h"
+#include "GameMain.h"
#include "BasicTimer.h"
namespace ShootingGame
private:
void OnSuspending(Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e);
- SimpleSprites^ simpleSprites_;
+ GameMain^ gameMain_;
BasicTimer^ timer_;
Windows::Foundation::EventRegistrationToken eventToken_;
void OnResuming(
//// Copyright (c) Microsoft Corporation. All rights reserved
#include "pch.h"
-#include "SimpleSprites.h"
+#include "SoundDriver.h"
+#include "GameMain.h"
#include "BasicLoader.h"
#include "windows.ui.xaml.media.dxinterop.h"
using namespace BasicSprites;
-const float SimpleSprites::BACKBUFFER_WIDTH = 320.0f;
-const float SimpleSprites::BACKBUFFER_HEIGHT = 240.0f;
+const float GameMain::BACKBUFFER_WIDTH = 320.0f;
+const float GameMain::BACKBUFFER_HEIGHT = 240.0f;
-SimpleSprites::SimpleSprites() : backBufferViewPort_(0.0f,0.0f,BACKBUFFER_WIDTH,BACKBUFFER_HEIGHT)
+GameMain::GameMain() : backBufferViewPort_(0.0f,0.0f,BACKBUFFER_WIDTH,BACKBUFFER_HEIGHT)
{
+ soundDriver_.reset(new sf::SoundDriver());
}
-void SimpleSprites::CreateDeviceIndependentResources()
+void GameMain::CreateDeviceIndependentResources()
{
DirectXBase::CreateDeviceIndependentResources();
autoThrottle_ = ref new AutoThrottle(1.0f / 60.0f);
}
- void SimpleSprites::Initialize(
+ void GameMain::Initialize(
_In_ Windows::UI::Core::CoreWindow^ window,
_In_ Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ swapChainPanel,
_In_ float dpi
Initialize(window,dpi);
}
-void SimpleSprites::CreateDeviceResources()
+void GameMain::CreateDeviceResources()
{
DirectXBase::CreateDeviceResources();
}
-void SimpleSprites::CreateWindowSizeDependentResources()
+void GameMain::CreateWindowSizeDependentResources()
{
// DirectXBase::CreateWindowSizeDependentResources();
// Store the window bounds so the next time we get a SizeChanged event we can
}
-void SimpleSprites::Update(float timeTotal, float timeDelta)
+void GameMain::Update(float timeTotal, float timeDelta)
{
// Update the performance throttler.
//}
}
-void SimpleSprites::Render()
+void GameMain::Render()
{
static int frame_count = 0;
sampleOverlay_->Render();
}
-float SimpleSprites::RandFloat(float min, float max)
+float GameMain::RandFloat(float min, float max)
{
return (static_cast<float>(rand() % RAND_MAX) / static_cast<float>(RAND_MAX)) * (max - min) + min;
}
float scale;
};
-ref class SimpleSprites : public DirectXBase
+ref class GameMain : public DirectXBase
{
public:
- SimpleSprites();
+ GameMain();
virtual void CreateDeviceIndependentResources() override;
virtual void CreateDeviceResources() override;
virtual void CreateWindowSizeDependentResources() override;
CD3D11_VIEWPORT swapChainViewPort_;
std::vector<CharacterData> characters_;
Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ panel_;
+ std::unique_ptr<sf::SoundDriver> soundDriver_;
};
<ClInclude Include="DDSTextureLoader.h" />
<ClInclude Include="DirectXBase.h" />
<ClInclude Include="DirectXSample.h" />
+ <ClInclude Include="exception.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="Common\BindableBase.h" />
<ClInclude Include="Common\BooleanToVisibilityConverter.h" />
<DependentUpon>MainPage.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="SampleOverlay.h" />
- <ClInclude Include="SimpleSprites.h" />
+ <ClInclude Include="GameMain.h" />
+ <ClInclude Include="SoundDriver.h" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="SampleOverlay.cpp" />
- <ClCompile Include="SimpleSprites.cpp" />
+ <ClCompile Include="GameMain.cpp" />
+ <ClCompile Include="SoundDriver.cpp" />
</ItemGroup>
<ItemGroup>
<FxCompile Include="BasicSprites.GeometryShader.gs.hlsl">
--- /dev/null
+#include "pch.h"
+#include "sf_memory.h"
+#include "SoundDriver.h"
+
+using namespace std;
+using namespace Windows::Foundation;
+using namespace Windows::Foundation::Collections;
+using namespace Windows::Devices::Enumeration;
+using namespace Windows::Media::Devices;
+using namespace Concurrency;
+using namespace Platform;
+#pragma comment(lib, "mmdevapi.lib")
+
+namespace sf {
+
+ void makeWaveFormat(WAVEFORMATEXTENSIBLE& format,
+ int sample_rate = 44100,int channels = 2,int bits_per_sample = 32,int valid_bits_per_sample = 32,
+ uint32_t type = WAVE_FORMAT_EXTENSIBLE,
+ const GUID& sub_type = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)
+ {
+ ZeroMemory(&format,sizeof(WAVEFORMATEXTENSIBLE));
+ format.Format.wFormatTag = type;
+ format.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
+ format.SubFormat = sub_type;
+ format.Format.nSamplesPerSec = sample_rate;
+ format.Format.nChannels = channels;
+ format.Format.wBitsPerSample = bits_per_sample;
+ format.Format.nBlockAlign = (format.Format.wBitsPerSample / 8) * format.Format.nChannels;
+ format.Format.nAvgBytesPerSec = format.Format.nSamplesPerSec * format.Format.nBlockAlign;
+ format.Samples.wValidBitsPerSample = valid_bits_per_sample;
+ format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
+ }
+
+ void makeWaveFormat(WAVEFORMATEX& format,int sample_rate = 44100,int channels = 2,int bits = 16,uint32_t type = WAVE_FORMAT_PCM)
+ {
+ ZeroMemory(&format,sizeof(WAVEFORMATEX));
+ format.wFormatTag = type;
+ format.nSamplesPerSec = sample_rate;
+ format.nChannels = channels;
+ format.wBitsPerSample = bits;
+ format.nBlockAlign = (format.wBitsPerSample / 8) * format.nChannels;
+ format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
+ };
+
+
+SoundDriver::SoundDriver() : rateConvert_(false)
+{
+ //::AvMMAvSetMmThreadCharacteristics
+ String^ deviceID = MediaDevice::GetDefaultAudioRenderId(AudioDeviceRole::Default);
+ ActivateAudioInterface(deviceID->Data(),__uuidof(IAudioClient2),&audioClient_);
+ if(!audioClient_)
+ {
+ throw AudioClientNullException(L"\8aù\92è\82ÌAudioClient\82ð\83A\83N\83e\83B\83x\81[\83g\82Å\82«\82Ü\82¹\82ñ\82Å\82µ\82½\81B");
+ }
+
+ // \83I\81[\83f\83B\83I\83t\83H\81[\83}\83b\83g\82Ì\83`\83F\83b\83N
+ // KSDATAFORMAT_SUBTYPE_IEEE_FLOAT,2CH\83X\83e\83\8c\83I,44100KHz\82ð\95W\8f\80\82Æ\82·\82é
+ WAVEFORMATEXTENSIBLE format;
+ makeWaveFormat(format);
+ sf::co_task_memory<WAVEFORMATEXTENSIBLE> mix_format;
+ audioClient_->GetMixFormat(reinterpret_cast<WAVEFORMATEX**>(&mix_format));
+
+ sf::co_task_memory<WAVEFORMATEXTENSIBLE> alt_format;
+ HRESULT hr = audioClient_->IsFormatSupported(
+ AUDCLNT_SHAREMODE_SHARED,
+ reinterpret_cast<WAVEFORMATEX*>(&format),
+ reinterpret_cast<WAVEFORMATEX**>(&alt_format));
+ int sample_rate_backup = 0;
+ if(hr == S_FALSE) // FALSE\82Ì\8e\9e\82Í\82¨\82»\82ç\82\83T\83\93\83v\83\8a\83\93\83O\83\8c\81[\83g\82ª\88á\82¤
+ {
+ // \83T\83\93\83v\83\8a\83\93\83O\83\8c\81[\83g\82Ì\82Ý\82ª\88Ù\82È\82é\82©\83`\83F\83b\83N\82·\82é
+ if( alt_format->Format.wFormatTag == format.Format.wFormatTag &&
+ alt_format->Format.nChannels == format.Format.nChannels &&
+ alt_format->Format.wBitsPerSample == format.Format.wBitsPerSample &&
+ alt_format->Samples.wValidBitsPerSample == format.Samples.wValidBitsPerSample &&
+ alt_format->Format.nSamplesPerSec != format.Format.nSamplesPerSec
+ )
+ {
+ sample_rate_backup = format.Format.nSamplesPerSec;
+ // \91ã\91Ö\83t\83H\81[\83}\83b\83g\82Ì\83T\83\93\83v\83\8b\83\8c\81[\83g\82ð\83Z\83b\83g\82·\82é
+ format.Format.nSamplesPerSec = alt_format->Format.nSamplesPerSec;
+ // \8dÄ\8cv\8eZ\82·\82é
+ format.Format.nAvgBytesPerSec = alt_format->Format.nSamplesPerSec * format.Format.nBlockAlign;
+ // \82à\82¤\88ê\89ñ\83`\83F\83b\83N\82·\82é\81B
+ // \83T\83\93\83v\83\8b\83\8c\81[\83g\88È\8aO\82Å\83T\83|\81[\83g\82µ\82Ä\82¢\82È\82¢\93_\82ª\82 \82ê\82Î\97á\8aO\82ª\94\90¶\82·\82é\81B
+ alt_format.reset();
+ ThrowIfErr(audioClient_->IsFormatSupported(
+ AUDCLNT_SHAREMODE_SHARED,
+ reinterpret_cast<WAVEFORMATEX*>(&format),
+ reinterpret_cast<WAVEFORMATEX**>(&alt_format)));
+ rateConvert_ = true;
+ } else {
+ throw AudioFormatNotSupportedException(L"\82±\82Ì\83I\81[\83f\83B\83I\83f\83o\83C\83X\82Å\90Ý\92è\82µ\82Ä\82¢\82é\83t\83H\81[\83}\83b\83g\82Í\91Î\89\9e\82µ\82Ä\82¢\82Ü\82¹\82ñ\81B");
+ }
+ }
+
+ // Audio Client\82Ì\8f\89\8aú\89»
+
+ REFERENCE_TIME defaultDevicePeriod,minDevicePriod;
+ audioClient_->GetDevicePeriod(&defaultDevicePeriod,&minDevicePriod);
+ hr = audioClient_->Initialize(
+ AUDCLNT_SHAREMODE_SHARED,
+ AUDCLNT_STREAMFLAGS_NOPERSIST |
+ AUDCLNT_STREAMFLAGS_EVENTCALLBACK |
+ rateConvert_?AUDCLNT_STREAMFLAGS_RATEADJUST:0 ,
+ minDevicePriod,0,
+ reinterpret_cast<WAVEFORMATEX*>(&format),NULL);
+ if(hr == AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED)
+ {
+ ThrowIfErr(audioClient_->GetBufferSize(&bufferSize_));
+ latency_ = (double)10000000 * (bufferSize_) / format.Format.nSamplesPerSec;
+ audioClient_.Reset();
+ ActivateAudioInterface(deviceID->Data(),__uuidof(IAudioClient2),&audioClient_);
+ if(!audioClient_)
+ {
+ throw AudioClientNullException(L"\8aù\92è\82ÌAudioClient\82ð\83A\83N\83e\83B\83x\81[\83g\82Å\82«\82Ü\82¹\82ñ\82Å\82µ\82½\81B");
+ }
+ ThrowIfErr(audioClient_->Initialize(
+ AUDCLNT_SHAREMODE_SHARED,
+ AUDCLNT_STREAMFLAGS_NOPERSIST |
+ AUDCLNT_STREAMFLAGS_EVENTCALLBACK |
+ rateConvert_?AUDCLNT_STREAMFLAGS_RATEADJUST:0,
+ latency_,0,
+ reinterpret_cast<WAVEFORMATEX*>(&format),NULL));
+ } else {
+ throw Platform::Exception::CreateException(hr);
+ }
+
+ ThrowIfErr(audioClient_->GetBufferSize(&bufferSize_));
+
+ //// \83T\83\93\83v\83\8b\83\8c\81[\83g\83R\83\93\83o\81[\83^
+ //if(rateConvert_)
+ //{
+ // ThrowIfErr(audioClient_->GetService(__uuidof(IAudioClockAdjustment),&audioClockAdjustment_));
+ // // \96{\97\88\82Ì\83T\83\93\83v\83\8b\83\8c\81[\83g\82ð\83Z\83b\83g\82·\82é
+ // audioClockAdjustment_->SetSampleRate(sample_rate_backup);
+ //}
+
+ audioClient_->GetStreamLatency(&latency_);
+ ThrowIfErr(audioClient_->GetService(__uuidof(IAudioRenderClient),&audioRenderClient_));
+}
+
+SoundDriver::~SoundDriver()
+{
+ audioClient_->Stop();
+ audioRenderClient_.Reset();
+ audioClient_->Reset();
+}
+}
--- /dev/null
+#pragma once
+
+typedef Microsoft::WRL::ComPtr<IAudioClient2> IAudioClient2Ptr;
+typedef Microsoft::WRL::ComPtr<IAudioClock2> IAudioClock2Ptr;
+typedef Microsoft::WRL::ComPtr<IAudioRenderClient> IAudioRenderClientPtr;
+typedef Microsoft::WRL::ComPtr<IAudioCaptureClient> IAudioCaptureClientPtr;
+//typedef Microsoft::WRL::ComPtr<IAudioClockAdjustment> IAudioClockAdjustmentPtr;
+
+namespace sf {
+
+DefineException(AudioClientNull);
+DefineException(AudioFormatNotSupported);
+
+struct SoundDriver
+{
+ SoundDriver();
+ ~SoundDriver();
+
+private:
+ IAudioClient2Ptr audioClient_;
+ bool rateConvert_;
+ uint32_t bufferSize_;
+ REFERENCE_TIME latency_;
+// IAudioClockAdjustmentPtr audioClockAdjustment_;
+ IAudioRenderClientPtr audioRenderClient_;
+};
+}
+
--- /dev/null
+#include "pch.h"
+#include "exception.h"
+#include <objbase.h>
+#include <wtypes.h>
+#include <winerror.h>
+#include <avrt.h>
+#include <strsafe.h>
+#include <audioclient.h>
+#include <audiopolicy.h>
+
+
+
+#define BOOST_ASSIGN_MAX_PARAMS 7
+#include <boost/assign.hpp>
+#include <boost/assign/ptr_list_of.hpp>
+#include <boost/assign/ptr_list_inserter.hpp>
+#include <boost/foreach.hpp>
+
+#if _DEBUG
+#define _CRTDBG_MAP_ALLOC
+#include <crtdbg.h>
+#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
+#endif
+
+#include "sf_memory.h"
+
+using namespace boost;
+
+namespace sf
+{
+//typedef CComPtr<IAudioClient> IAudioClientPtr;
+std::map<HRESULT,std::wstring> com_error_ = boost::assign::list_of<std::pair<HRESULT,std::wstring> >
+ (E_POINTER,L"E_POINTER")
+ (E_INVALIDARG,L"E_INVALIDARG")
+ (DWRITE_E_FILEFORMAT,L"DWRITE_E_FILEFORMAT")
+ (DWRITE_E_UNEXPECTED,L"DWRITE_E_UNEXPECTED")
+ (DWRITE_E_NOFONT,L"DWRITE_E_NOFONT")
+ (DWRITE_E_FILENOTFOUND,L"DWRITE_E_FILENOTFOUND")
+ (DWRITE_E_FILEACCESS,L"DWRITE_E_FILEACCESS")
+ (DWRITE_E_FONTCOLLECTIONOBSOLETE,L"DWRITE_E_FONTCOLLECTIONOBSOLETE")
+ (DWRITE_E_ALREADYREGISTERED,L"DWRITE_E_ALREADYREGISTERED")
+ (AUDCLNT_E_NOT_INITIALIZED,L"AUDCLNT_E_NOT_INITIALIZED")
+ (AUDCLNT_E_ALREADY_INITIALIZED,L"AUDCLNT_E_ALREADY_INITIALIZED")
+ (AUDCLNT_E_WRONG_ENDPOINT_TYPE,L"AUDCLNT_E_WRONG_ENDPOINT_TYPE")
+ (AUDCLNT_E_DEVICE_INVALIDATED,L"AUDCLNT_E_DEVICE_INVALIDATED")
+ (AUDCLNT_E_NOT_STOPPED,L"AUDCLNT_E_NOT_STOPPED")
+ (AUDCLNT_E_BUFFER_TOO_LARGE,L"AUDCLNT_E_BUFFER_TOO_LARGE")
+ (AUDCLNT_E_OUT_OF_ORDER,L"AUDCLNT_E_OUT_OF_ORDER")
+ (AUDCLNT_E_UNSUPPORTED_FORMAT,L"AUDCLNT_E_UNSUPPORTED_FORMAT")
+ (AUDCLNT_E_INVALID_SIZE,L"AUDCLNT_E_INVALID_SIZE")
+ (AUDCLNT_E_DEVICE_IN_USE,L"AUDCLNT_E_DEVICE_IN_USE")
+ (AUDCLNT_E_BUFFER_OPERATION_PENDING,L"AUDCLNT_E_BUFFER_OPERATION_PENDING")
+ (AUDCLNT_E_THREAD_NOT_REGISTERED,L"AUDCLNT_E_THREAD_NOT_REGISTERED")
+ (AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED,L"AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED")
+ (AUDCLNT_E_ENDPOINT_CREATE_FAILED,L"AUDCLNT_E_ENDPOINT_CREATE_FAILED")
+ (AUDCLNT_E_SERVICE_NOT_RUNNING,L"AUDCLNT_E_SERVICE_NOT_RUNNING")
+ (AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED,L"AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED")
+ (AUDCLNT_E_EXCLUSIVE_MODE_ONLY,L"AUDCLNT_E_EXCLUSIVE_MODE_ONLY")
+ (AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL,L"AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL")
+ (AUDCLNT_E_EVENTHANDLE_NOT_SET,L"AUDCLNT_E_EVENTHANDLE_NOT_SET")
+ (AUDCLNT_E_INCORRECT_BUFFER_SIZE,L"AUDCLNT_E_INCORRECT_BUFFER_SIZE")
+ (AUDCLNT_E_CPUUSAGE_EXCEEDED,L"AUDCLNT_E_CPUUSAGE_EXCEEDED")
+ (AUDCLNT_E_BUFFER_ERROR,L"AUDCLNT_E_BUFFER_ERROR")
+ (AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED,L"AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED")
+ (AUDCLNT_E_BUFFER_SIZE_ERROR,L"AUDCLNT_E_BUFFER_SIZE_ERROR")
+ (AUDCLNT_E_INVALID_DEVICE_PERIOD,L"AUDCLNT_E_INVALID_DEVICE_PERIOD")
+ (AUDCLNT_S_BUFFER_EMPTY,L"AUDCLNT_S_BUFFER_EMPTY")
+ (AUDCLNT_S_THREAD_ALREADY_REGISTERED,L"AUDCLNT_S_THREAD_ALREADY_REGISTERED")
+ (AUDCLNT_S_POSITION_STALLED,L"AUDCLNT_S_POSITION_STALLED")
+ (DXGI_ERROR_UNSUPPORTED,L"DXGI_ERROR_UNSUPPORTED ")
+ (DXGI_STATUS_OCCLUDED,L"DXGI_STATUS_OCCLUDED")
+ (DXGI_STATUS_CLIPPED,L"DXGI_STATUS_CLIPPED")
+ ;
+
+
+win32_error_exception::win32_error_exception(uint32_t hr)
+: std::exception("HRESULT ERROR"),hresult_(hr)
+{
+ local_memory<wchar_t> mem;
+ DWORD 結果 = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,0,hr,0,(LPWSTR)&mem,0,0);
+ if(結果 != 0){
+ error_ = mem.get();
+ } else {
+ std::map<HRESULT,std::wstring>::iterator it = com_error_.find(hr);
+ if(it != com_error_.end())
+ {
+ error_ = it->second;
+ } else {
+ error_ = (boost::wformat(L"0x%x 不明なCOMエラー") % hr).str();
+ }
+#ifdef _DEBUG
+ wdout << L"#### Exception Occured ####" << error_ << std::endl;
+#endif
+ }
+
+};
+
+win32_error_exception::win32_error_exception()
+{
+ hresult_ = ::GetLastError();
+ local_memory<wchar_t> mem;
+ DWORD rv = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,0,hresult_,0,(LPWSTR)&mem,0,0);
+ error_ = mem.get();
+#ifdef _DEBUG
+ wdout << L"#### Exception Occured ####" << error_ << std::endl;
+#endif
+
+ //Logger::outputDebugPrintf(L"Win32 Error %x %s",hresult_,mem.Get() );
+};
+
+std::wstring win32_error_exception::get_last_error_str(uint32_t err)
+{
+// DWORD err = ::GetLastError();
+ std::wstring err_str;
+ local_memory<wchar_t> mem;
+ DWORD rv = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,0,err,0,(LPWSTR)&mem,0,0);
+ err_str = mem.get();
+#ifdef _DEBUG
+ wdout << L"#### Exception Occured ####" << err_str << std::endl;
+#endif
+ return err_str;
+}
+
+}
\ No newline at end of file
--- /dev/null
+#pragma once
+
+namespace sf
+{
+ template <typename ExceptionTag> class ExceptionT : public std::exception
+ {
+ public:
+ typedef ExceptionTag tag;
+ explicit ExceptionT(const std::wstring& reason)
+ {
+ m_reason = reason;
+ };
+ const wchar_t * what() {return m_reason.c_str();};
+ const std::wstring& what_str() { return m_reason;};
+ protected:
+ std::wstring m_reason;
+ };
+
+ #define DefineException(x) struct x {}; typedef ExceptionT<x> x## Exception;
+
+ inline void ThrowIfErr(HRESULT hr) {if(hr != S_OK){throw Platform::Exception::CreateException(hr);}}
+
+}
+
#include <stdio.h>
#include <vector>
#include <memory>
+
+#include <ppltasks.h>
+
+// Core Audio
+
+#include "avrt.h"
+#include "mmsystem.h"
+#include <mmdeviceapi.h>
+#include <AudioClient.h>
+#include <audiopolicy.h>
+#include "exception.h"
+
#include "App.xaml.h"
--- /dev/null
+#pragma once
+namespace sf {
+// policy class
+struct heap_memory_free_policy
+{
+template< typename T >
+void operator()( const T* AMemory ) const
+{
+if( NULL != AMemory )
+::HeapFree( ::GetProcessHeap(), 0, AMemory );
+}
+};
+// policy class
+struct local_memory_free_policy
+{
+template< typename T >
+void operator()( const T* AMemory ) const
+{
+if( NULL != AMemory )
+::LocalFree( AMemory );
+}
+};
+// policy class
+struct co_task_memory_free_policy
+{
+template< typename T >
+void operator()( const T* AMemory ) const
+{
+if( NULL != AMemory )
+::CoTaskMemFree( AMemory );
+}
+};
+// base guard class
+template< typename T,class TFreePolicy >
+class base_memory
+{
+private:
+T *FMemory;
+
+public:
+base_memory( T* AMemory = NULL )
+: FMemory( AMemory ) {}
+
+virtual ~base_memory( void )
+{ reset(); }
+
+T* release( void )
+{
+T *tmp = FMemory;
+FMemory = NULL;
+return tmp;
+}
+
+void reset( T* AMemory = NULL )
+{
+if( AMemory != FMemory )
+{
+if( NULL != FMemory )
+TFreePolicy( FMemory );
+
+FMemory = AMemory;
+}
+}
+
+T* get( void )
+{ return FMemory; }
+
+T* operator ->(void)
+{
+ return FMemory;
+}
+
+T** operator&( void )
+{ return &FMemory; }
+
+};
+template< typename T >
+class heap_memory : public base_memory< T,
+heap_memory_free_policy >
+{
+public:
+heap_memory( T* AMemory = NULL )
+: base_memory< T, heap_memory_free_policy >( AMemory )
+{ }
+};
+template< typename T >
+class local_memory : public base_memory< T,
+local_memory_free_policy >
+{
+public:
+local_memory( T* AMemory = NULL )
+: base_memory< T, local_memory_free_policy >( AMemory )
+{ }
+};
+template< typename T >
+class co_task_memory : public base_memory< T, co_task_memory_free_policy >
+{
+public:
+co_task_memory( T* AMemory = NULL )
+: base_memory< T, co_task_memory_free_policy >( AMemory )
+{ }
+};
+
+struct handle_deleter {
+ typedef HANDLE pointer;
+ void operator ()(HANDLE handle) {
+ if (handle != INVALID_HANDLE_VALUE) {
+ CloseHandle(handle);
+ }
+ }
+};
+
+typedef std::unique_ptr<HANDLE,handle_deleter> handle_holder;
+
+};
+
+template <class COM_SMART_PTR > inline void safe_release(COM_SMART_PTR& ptr)
+{
+if(ptr)
+{
+ ptr.Reset();
+}
+};
+