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 "../ComObject.h"
25 #include "../DataStream.h"
26 #include "../stack_array.h"
28 const IID IID_CXAPOBase = __uuidof(IXAPO);
30 #include "BaseProcessor.h"
32 using namespace System;
33 using namespace SlimDX::Multimedia;
39 BaseProcessor::BaseProcessor( SlimDX::XAPO::RegistrationProperties properties )
41 XAPO_REGISTRATION_PROPERTIES props = properties.ToUnmanaged();
43 Construct( new XAPOBaseImpl( this, &props ) );
46 int BaseProcessor::CalculateInputFrames( int outputFrameCount )
48 return InternalPointer->CalcInputFrames( outputFrameCount );
51 int BaseProcessor::CalculateOutputFrames( int inputFrameCount )
53 return InternalPointer->CalcOutputFrames( inputFrameCount );
56 Result BaseProcessor::Initialize( DataStream^ data )
58 HRESULT hr = InternalPointer->Initialize( data->PositionPointer, static_cast<UINT32>( data->RemainingLength ) );
62 bool BaseProcessor::IsInputFormatSupported( SlimDX::Multimedia::WaveFormat^ outputFormat, SlimDX::Multimedia::WaveFormat^ requestedInputFormat, [Out] SlimDX::Multimedia::WaveFormat^% supportedInputFormat )
64 auto_array<WAVEFORMATEX> output = WaveFormat::ToUnmanaged( outputFormat );
65 auto_array<WAVEFORMATEX> input = WaveFormat::ToUnmanaged( requestedInputFormat );
66 WAVEFORMATEX *supported = NULL;
68 HRESULT hr = InternalPointer->IsInputFormatSupported( output.get(), input.get(), &supported );
69 supportedInputFormat = WaveFormat::FromUnmanaged( *supported );
73 bool BaseProcessor::IsOutputFormatSupported( SlimDX::Multimedia::WaveFormat^ inputFormat, SlimDX::Multimedia::WaveFormat^ requestedOutputFormat, [Out] SlimDX::Multimedia::WaveFormat^% supportedOutputFormat )
75 auto_array<WAVEFORMATEX> input = WaveFormat::ToUnmanaged( inputFormat );
76 auto_array<WAVEFORMATEX> output = WaveFormat::ToUnmanaged( requestedOutputFormat );
77 WAVEFORMATEX *supported = NULL;
79 HRESULT hr = InternalPointer->IsOutputFormatSupported( input.get(), output.get(), &supported );
80 supportedOutputFormat = WaveFormat::FromUnmanaged( *supported );
84 Result BaseProcessor::LockForProcess( array<LockParameter>^ inputParameters, array<LockParameter>^ outputParameters )
86 stack_array<XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS> input = stackalloc( XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS, inputParameters->Length );
87 stack_array<XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS> output = stackalloc( XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS, outputParameters->Length );
89 for( int i = 0; i < inputParameters->Length; i++ )
91 XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS p;
92 p.pFormat = WaveFormat::ToUnmanaged( inputParameters[i].Format ).release();
93 p.MaxFrameCount = inputParameters[i].MaxFrameCount;
98 for( int i = 0; i < outputParameters->Length; i++ )
100 XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS p;
101 p.pFormat = WaveFormat::ToUnmanaged( outputParameters[i].Format ).release();
102 p.MaxFrameCount = outputParameters[i].MaxFrameCount;
107 HRESULT hr = InternalPointer->LockForProcess( inputParameters->Length, &input[0], outputParameters->Length, &output[0] );
111 void BaseProcessor::Reset()
113 InternalPointer->Reset();
116 void BaseProcessor::UnlockForProcess()
118 InternalPointer->UnlockForProcess();
121 void BaseProcessor::ProcessThru( DataStream^ inputBuffer, array<float>^ outputBuffer, int frameCount, int inputChannelCount, int outputChannelCount, bool mixWithDestination )
123 pin_ptr<float> pinnedOutput = &outputBuffer[0];
124 ImplPointer->ProcessThru( inputBuffer->PositionPointer, pinnedOutput, frameCount, static_cast<WORD>( inputChannelCount ), static_cast<WORD>( outputChannelCount ), mixWithDestination );
127 Result BaseProcessor::ValidateFormatDefault( SlimDX::Multimedia::WaveFormat^ format )
129 auto_array<WAVEFORMATEX> wave = WaveFormat::ToUnmanaged( format );
130 HRESULT hr = ImplPointer->ValidateFormatDefault( wave.get(), FALSE );
135 Result BaseProcessor::ValidateFormatPair( SlimDX::Multimedia::WaveFormat^ supportedFormat, SlimDX::Multimedia::WaveFormat^ requestedFormat )
137 auto_array<WAVEFORMATEX> supported = WaveFormat::ToUnmanaged( supportedFormat );
138 auto_array<WAVEFORMATEX> requested = WaveFormat::ToUnmanaged( requestedFormat );
140 HRESULT hr = ImplPointer->ValidateFormatPair( supported.get(), requested.get(), FALSE );
144 SlimDX::XAPO::RegistrationProperties BaseProcessor::RegistrationProperties::get()
146 return SlimDX::XAPO::RegistrationProperties::FromUnmanaged( *ImplPointer->GetRegistrationPropertiesInternal() );
149 bool BaseProcessor::IsLocked::get()
151 return ImplPointer->IsLocked() > 0;
154 XAPOBaseImpl::XAPOBaseImpl( BaseProcessor^ processor, XAPO_REGISTRATION_PROPERTIES *pRegProperties )
155 : CXAPOBase( pRegProperties )
157 m_processor = processor;
160 void XAPOBaseImpl::Process( UINT32 InputProcessParameterCount, const XAPO_PROCESS_BUFFER_PARAMETERS *pInputProcessParameters, UINT32 OutputProcessParameterCount, XAPO_PROCESS_BUFFER_PARAMETERS *pOutputProcessParameters, BOOL IsEnabled )
164 array<BufferParameter>^ input = gcnew array<BufferParameter>( InputProcessParameterCount );
165 for( int i = 0; i < input->Length; i++ )
168 p.Buffer = IntPtr( pInputProcessParameters[i].pBuffer );
169 p.Flags = static_cast<BufferFlags>( pInputProcessParameters[i].BufferFlags );
170 p.ValidFrameCount = pInputProcessParameters[i].ValidFrameCount;
175 array<BufferParameter>^ output = gcnew array<BufferParameter>( OutputProcessParameterCount );
176 for( int i = 0; i < output->Length; i++ )
179 p.Buffer = IntPtr( pOutputProcessParameters[i].pBuffer );
180 p.Flags = static_cast<BufferFlags>( pOutputProcessParameters[i].BufferFlags );
181 p.ValidFrameCount = pOutputProcessParameters[i].ValidFrameCount;
186 m_processor->Process( input, output, IsEnabled > 0 );