2 * Copyright (c) 2007-2010 SlimDX Group
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "../DataStream.h"
25 #include "IAudioProcessor.h"
27 using namespace System;
28 using namespace SlimDX::Multimedia;
34 XAPOShim::XAPOShim( IAudioProcessor^ wrappedInterface )
36 m_interface = wrappedInterface;
39 if( IParameterProvider::typeid->IsAssignableFrom( wrappedInterface->GetType() ) )
40 m_parameters = safe_cast<IParameterProvider^>( wrappedInterface );
42 m_parameters = nullptr;
45 HRESULT XAPOShim::QueryInterface( const IID &iid, LPVOID *ppv )
47 if( iid == __uuidof(IXAPO) )
50 *ppv = static_cast<IXAPO*>( this );
53 else if( iid == __uuidof(IUnknown) )
56 *ppv = static_cast<IUnknown*>( static_cast<IXAPO*>( this ) );
59 else if( iid == __uuidof(IXAPOParameters) && safe_cast<IParameterProvider^>( m_parameters ) != nullptr )
62 *ppv = static_cast<IXAPOParameters*>( this );
69 ULONG XAPOShim::AddRef()
71 return InterlockedIncrement( &refCount );
74 ULONG XAPOShim::Release()
76 if( InterlockedDecrement( &refCount ) == 0 )
81 UINT32 WINAPI XAPOShim::CalcInputFrames( UINT32 OutputFrameCount )
85 return m_interface->CalculateInputFrames( OutputFrameCount );
94 UINT32 WINAPI XAPOShim::CalcOutputFrames( UINT32 InputFrameCount )
98 return m_interface->CalculateOutputFrames( InputFrameCount );
107 HRESULT WINAPI XAPOShim::GetRegistrationProperties( XAPO_REGISTRATION_PROPERTIES **ppRegistrationProperties )
111 XAPO_REGISTRATION_PROPERTIES *ptr = reinterpret_cast<XAPO_REGISTRATION_PROPERTIES*>( XAPOAlloc( sizeof( XAPO_REGISTRATION_PROPERTIES ) ) );
112 XAPO_REGISTRATION_PROPERTIES properties = m_interface->RegistrationProperties.ToUnmanaged();
113 memcpy( ptr, &properties, sizeof( XAPO_REGISTRATION_PROPERTIES ) );
115 *ppRegistrationProperties = ptr;
117 catch( SlimDXException^ ex )
119 return ex->ResultCode.Code;
129 HRESULT WINAPI XAPOShim::Initialize( const void *pData, UINT32 DataByteSize )
133 DataStream^ data = gcnew DataStream( pData, DataByteSize, true, false );
135 return m_interface->Initialize( data ).Code;
137 catch( SlimDXException^ ex )
139 return ex->ResultCode.Code;
149 HRESULT WINAPI XAPOShim::IsInputFormatSupported( const WAVEFORMATEX *pOutputFormat, const WAVEFORMATEX *pRequestedInputFormat, WAVEFORMATEX **ppSupportedInputFormat )
154 bool result = m_interface->IsInputFormatSupported( WaveFormat::FromUnmanaged( *pOutputFormat ), WaveFormat::FromUnmanaged( *pRequestedInputFormat ), format );
156 auto_array<WAVEFORMATEX> native = WaveFormat::ToUnmanaged( format );
157 *ppSupportedInputFormat = native.release();
159 return result ? S_OK : XAPO_E_FORMAT_UNSUPPORTED;
161 catch( SlimDXException^ ex )
163 return ex->ResultCode.Code;
173 HRESULT WINAPI XAPOShim::IsOutputFormatSupported( const WAVEFORMATEX *pInputFormat, const WAVEFORMATEX *pRequestedOutputFormat, WAVEFORMATEX **ppSupportedOutputFormat )
178 bool result = m_interface->IsOutputFormatSupported( WaveFormat::FromUnmanaged( *pInputFormat ), WaveFormat::FromUnmanaged( *pRequestedOutputFormat ), format );
180 auto_array<WAVEFORMATEX> native = WaveFormat::ToUnmanaged( format );
181 *ppSupportedOutputFormat = native.release();
183 return result ? S_OK : XAPO_E_FORMAT_UNSUPPORTED;
185 catch( SlimDXException^ ex )
187 return ex->ResultCode.Code;
197 HRESULT WINAPI XAPOShim::LockForProcess( UINT32 InputLockedParameterCount, const XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS *pInputLockedParameters, UINT32 OutputLockedParameterCount, const XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS *pOutputLockedParameters )
201 array<LockParameter>^ input = gcnew array<LockParameter>( InputLockedParameterCount );
202 for( int i = 0; i < input->Length; i++ )
205 p.Format = WaveFormat::FromUnmanaged( *pInputLockedParameters[i].pFormat );
206 p.MaxFrameCount = pInputLockedParameters[i].MaxFrameCount;
211 array<LockParameter>^ output = gcnew array<LockParameter>( OutputLockedParameterCount );
212 for( int i = 0; i < output->Length; i++ )
215 p.Format = WaveFormat::FromUnmanaged( *pOutputLockedParameters[i].pFormat );
216 p.MaxFrameCount = pOutputLockedParameters[i].MaxFrameCount;
221 return m_interface->LockForProcess( input, output ).Code;
223 catch( SlimDXException^ ex )
225 return ex->ResultCode.Code;
235 void WINAPI XAPOShim::Process( UINT32 InputProcessParameterCount, const XAPO_PROCESS_BUFFER_PARAMETERS *pInputProcessParameters, UINT32 OutputProcessParameterCount, XAPO_PROCESS_BUFFER_PARAMETERS *pOutputProcessParameters, BOOL IsEnabled )
239 array<BufferParameter>^ input = gcnew array<BufferParameter>( InputProcessParameterCount );
240 for( int i = 0; i < input->Length; i++ )
243 p.Buffer = IntPtr( pInputProcessParameters[i].pBuffer );
244 p.Flags = static_cast<BufferFlags>( pInputProcessParameters[i].BufferFlags );
245 p.ValidFrameCount = pInputProcessParameters[i].ValidFrameCount;
250 array<BufferParameter>^ output = gcnew array<BufferParameter>( OutputProcessParameterCount );
251 for( int i = 0; i < output->Length; i++ )
254 p.Buffer = IntPtr( pOutputProcessParameters[i].pBuffer );
255 p.Flags = static_cast<BufferFlags>( pOutputProcessParameters[i].BufferFlags );
256 p.ValidFrameCount = pOutputProcessParameters[i].ValidFrameCount;
261 m_interface->Process( input, output, IsEnabled > 0 );
268 void WINAPI XAPOShim::Reset()
272 m_interface->Reset();
279 void WINAPI XAPOShim::UnlockForProcess()
283 m_interface->UnlockForProcess();
290 void WINAPI XAPOShim::GetParameters( void *pParameters, UINT32 ParameterByteSize )
294 m_parameters->GetParameters( gcnew DataStream( pParameters, ParameterByteSize, true, true, false ) );
301 void WINAPI XAPOShim::SetParameters( const void *pParameters, UINT32 ParameterByteSize )
305 m_parameters->SetParameters( gcnew DataStream( pParameters, ParameterByteSize, true, false ) );