+++ /dev/null
-#include "stdafx.h"\r
-/*\r
-* Copyright (c) 2007-2010 SlimDX Group\r
-* \r
-* Permission is hereby granted, free of charge, to any person obtaining a copy\r
-* of this software and associated documentation files (the "Software"), to deal\r
-* in the Software without restriction, including without limitation the rights\r
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-* copies of the Software, and to permit persons to whom the Software is\r
-* furnished to do so, subject to the following conditions:\r
-* \r
-* The above copyright notice and this permission notice shall be included in\r
-* all copies or substantial portions of the Software.\r
-* \r
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-* THE SOFTWARE.\r
-*/\r
-#include <windows.h>\r
-#include <dsound.h>\r
-\r
-#include "../stack_array.h"\r
-#include "../ComObject.h"\r
-#include "../Utilities.h"\r
-#include "../DataStream.h"\r
-\r
-#include "../multimedia/WaveFormat.h"\r
-#include "../multimedia/WaveFormatExtensible.h"\r
-\r
-#include "DirectSoundException.h"\r
-\r
-#include "CaptureBuffer.h"\r
-\r
-using namespace System;\r
-using namespace System::Reflection;\r
-using namespace SlimDX::Multimedia;\r
-\r
-namespace SlimDX\r
-{\r
-namespace DirectSound\r
-{\r
- CaptureBuffer::CaptureBuffer( DirectSoundCapture^ capture, CaptureBufferDescription description )\r
- {\r
- DSCBUFFERDESC value = description.ToUnmanaged();\r
- IDirectSoundCaptureBuffer* buffer;\r
-\r
- HRESULT hr = capture->InternalPointer->CreateCaptureBuffer( &value, &buffer, NULL );\r
-\r
- delete[] value.lpDSCFXDesc;\r
- delete[] value.lpwfxFormat;\r
-\r
- if( RECORD_DSOUND( hr ).IsFailure )\r
- throw gcnew DirectSoundException( Result::Last );\r
-\r
- IDirectSoundCaptureBuffer8* dsCapture;\r
- hr = buffer->QueryInterface( IID_IDirectSoundCaptureBuffer8, reinterpret_cast<void**>( &dsCapture ) );\r
-\r
- if( RECORD_DSOUND( hr ).IsFailure )\r
- throw gcnew DirectSoundException( Result::Last );\r
-\r
- Construct( dsCapture );\r
- }\r
- \r
- Result CaptureBuffer::Start( bool looping )\r
- {\r
- HRESULT hr = InternalPointer->Start( looping ? DSCBSTART_LOOPING : 0 );\r
- return RECORD_DSOUND( hr );\r
- }\r
-\r
- Result CaptureBuffer::Stop()\r
- {\r
- HRESULT hr = InternalPointer->Stop();\r
- return RECORD_DSOUND( hr );\r
- }\r
-\r
- DataStream^ CaptureBuffer::Lock( int offset, int sizeBytes, bool lockEntireBuffer, [Out] DataStream^% secondPart )\r
- {\r
- void* buffer1;\r
- void* buffer2;\r
- DWORD size1, size2;\r
-\r
- secondPart = nullptr;\r
-\r
- HRESULT hr = InternalPointer->Lock( offset, sizeBytes, &buffer1, &size1, &buffer2, &size2, lockEntireBuffer ? DSCBLOCK_ENTIREBUFFER : 0 );\r
- if( RECORD_DSOUND( hr ).IsFailure )\r
- return nullptr;\r
-\r
- DataStream^ stream1 = gcnew DataStream( buffer1, size1, true, false, false );\r
- if( buffer2 != NULL )\r
- secondPart = gcnew DataStream( buffer2, size2, true, false, false );\r
-\r
- return stream1;\r
- }\r
-\r
- Result CaptureBuffer::Unlock( DataStream^ firstPart, DataStream^ secondPart )\r
- {\r
- void* buffer2 = NULL;\r
- int size2 = 0;\r
-\r
- if( secondPart != nullptr )\r
- {\r
- buffer2 = secondPart->RawPointer;\r
- size2 = static_cast<int>( secondPart->Length );\r
- }\r
-\r
- HRESULT hr = InternalPointer->Unlock( firstPart->RawPointer, static_cast<int>( firstPart->Length ), buffer2, size2 );\r
- return RECORD_DSOUND( hr );\r
- }\r
-\r
- generic<typename T>\r
- Result CaptureBuffer::Read( array<T>^ data, int bufferOffset, bool lockEntireBuffer )\r
- {\r
- return InternalRead( data, 0, 0, bufferOffset, lockEntireBuffer );\r
- }\r
-\r
- generic<typename T>\r
- Result CaptureBuffer::Read( array<T>^ data, int startIndex, int count, int bufferOffset )\r
- {\r
- return InternalRead( data, startIndex, count, bufferOffset, false );\r
- }\r
-\r
- generic<typename T>\r
- Result CaptureBuffer::InternalRead( array<T>^ data, int startIndex, int count, int bufferOffset, bool lockEntireBuffer )\r
- {\r
- Utilities::CheckArrayBounds( data, startIndex, count );\r
- int bytes = static_cast<int>(sizeof(T) * count);\r
-\r
- DataStream^ stream2;\r
- DataStream^ stream1 = Lock( bufferOffset, bytes, lockEntireBuffer, stream2 );\r
-\r
- if( stream1 == nullptr )\r
- return Result::Last;\r
-\r
- int count1 = static_cast<int>( stream1->Length ) / sizeof(T);\r
- stream1->ReadRange( data, startIndex, count1 );\r
-\r
- if( stream2 != nullptr && count > count1 )\r
- stream2->ReadRange( data, count1 + startIndex, count - count1 );\r
-\r
- return Unlock( stream1, stream2 );\r
- }\r
-\r
- Result CaptureBuffer::SetNotificationPositions( array<NotificationPosition>^ positions )\r
- {\r
- IDirectSoundNotify *pointer;\r
- HRESULT hr = InternalPointer->QueryInterface( IID_IDirectSoundNotify, reinterpret_cast<void**>( &pointer ) );\r
-\r
- if( FAILED( hr ) )\r
- return RECORD_DSOUND( hr );\r
-\r
- stack_array<DSBPOSITIONNOTIFY> notifies = stackalloc( DSBPOSITIONNOTIFY, positions->Length );\r
- for( int i = 0; i < positions->Length; i++ )\r
- {\r
- notifies[i].dwOffset = positions[i].Offset;\r
- notifies[i].hEventNotify = positions[i].Event->SafeWaitHandle->DangerousGetHandle().ToPointer();\r
- }\r
-\r
- hr = pointer->SetNotificationPositions( positions->Length, ¬ifies[0] );\r
- pointer->Release();\r
-\r
- return RECORD_DSOUND( hr );\r
- }\r
-\r
- WaveFormat^ CaptureBuffer::Format::get()\r
- {\r
- WaveFormat^ result;\r
- WAVEFORMATEX* format;\r
- DWORD size;\r
-\r
- HRESULT hr = InternalPointer->GetFormat( NULL, 0, &size );\r
- if( RECORD_DSOUND( hr ).IsFailure )\r
- return nullptr;\r
-\r
- // Manual Allocation: handled properly in the try/finally clause below\r
- format = reinterpret_cast<WAVEFORMATEX*>( new char[size] );\r
-\r
- try\r
- {\r
- hr = InternalPointer->GetFormat( format, size, NULL );\r
-\r
- if( RECORD_DSOUND( hr ).IsFailure )\r
- return nullptr;\r
-\r
- if( format->wFormatTag == WAVE_FORMAT_EXTENSIBLE )\r
- result = WaveFormatExtensible::FromBase( format );\r
- else \r
- result = WaveFormat::FromUnmanaged( *format );\r
-\r
- return result;\r
- }\r
- finally\r
- {\r
- delete[] format;\r
- }\r
- }\r
-\r
- array<CaptureEffectResult>^ CaptureBuffer::GetEffectStatus( int effectCount )\r
- {\r
- stack_array<DWORD> results = stackalloc( DWORD, effectCount );\r
-\r
- HRESULT hr = InternalPointer->GetFXStatus( effectCount, &results[0] );\r
- if( RECORD_DSOUND( hr ).IsFailure )\r
- return nullptr;\r
-\r
- array<CaptureEffectResult>^ output = gcnew array<CaptureEffectResult>( effectCount );\r
-\r
- for( int i = 0; i < effectCount; i++ )\r
- output[i] = static_cast<CaptureEffectResult>( results[i] );\r
-\r
- return output;\r
- }\r
-\r
- generic<typename T>\r
- T CaptureBuffer::GetEffect( int index )\r
- {\r
- GUID guid = Utilities::GetNativeGuidForType( T::typeid );\r
- void *resultPointer;\r
-\r
- HRESULT hr = InternalPointer->GetObjectInPath( GUID_All_Objects, index, guid, &resultPointer );\r
- if( RECORD_DSOUND( hr ).IsFailure )\r
- return T();\r
-\r
- MethodInfo^ method = T::typeid->GetMethod( "FromPointer", BindingFlags::Public | BindingFlags::Static );\r
- return safe_cast<T>( method->Invoke( nullptr, gcnew array<Object^> { IntPtr( resultPointer ) } ) );\r
- }\r
-\r
- bool CaptureBuffer::WaveMapped::get()\r
- {\r
- DSCBCAPS caps;\r
- caps.dwSize = sizeof( DSCBCAPS );\r
- HRESULT hr = InternalPointer->GetCaps( &caps );\r
-\r
- if( RECORD_DSOUND( hr ).IsFailure )\r
- return false;\r
-\r
- return caps.dwFlags == DSCBCAPS_WAVEMAPPED;\r
- }\r
-\r
- int CaptureBuffer::SizeInBytes::get()\r
- {\r
- DSCBCAPS caps;\r
- caps.dwSize = sizeof( DSCBCAPS );\r
- HRESULT hr = InternalPointer->GetCaps( &caps );\r
-\r
- if( RECORD_DSOUND( hr ).IsFailure )\r
- return 0;\r
-\r
- return caps.dwBufferBytes;\r
- }\r
-\r
- bool CaptureBuffer::Capturing::get()\r
- {\r
- DWORD status;\r
- HRESULT hr = InternalPointer->GetStatus( &status );\r
- \r
- if( RECORD_DSOUND( hr ).IsFailure )\r
- return false;\r
-\r
- return ( status & DSCBSTATUS_CAPTURING ) != 0;\r
- }\r
-\r
- bool CaptureBuffer::Looping::get()\r
- {\r
- DWORD status;\r
- HRESULT hr = InternalPointer->GetStatus( &status );\r
- \r
- if( RECORD_DSOUND( hr ).IsFailure )\r
- return false;\r
-\r
- return ( status & DSCBSTATUS_LOOPING ) != 0;\r
- }\r
-\r
- int CaptureBuffer::CurrentCapturePosition::get()\r
- {\r
- DWORD capturePosition;\r
- HRESULT hr = InternalPointer->GetCurrentPosition( &capturePosition, NULL );\r
- \r
- if( RECORD_DSOUND( hr ).IsFailure )\r
- return 0;\r
-\r
- return capturePosition;\r
- }\r
-\r
- int CaptureBuffer::CurrentReadPosition::get()\r
- {\r
- DWORD readPosition;\r
- HRESULT hr = InternalPointer->GetCurrentPosition( NULL, &readPosition );\r
- \r
- if( RECORD_DSOUND( hr ).IsFailure )\r
- return 0;\r
-\r
- return readPosition;\r
- }\r
-}\r
-}
\ No newline at end of file