OSDN Git Service

#32713 初コミット。SVNrev567時点での、ファイルはbranch/140707(ReBuild XGVersion)から移行したもの。
[dtxmaniaxg-verk/dtxmaniaxg-verk-git.git] / SlimDXc_Jun2010(VC++2008) / source / xapo / BaseProcessor.cpp
1 /*
2 * Copyright (c) 2007-2010 SlimDX Group
3
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:
10
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13
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
20 * THE SOFTWARE.
21 */
22 #include "stdafx.h"
23
24 #include "../ComObject.h"
25 #include "../DataStream.h"
26 #include "../stack_array.h"
27
28 const IID IID_CXAPOBase = __uuidof(IXAPO);
29
30 #include "BaseProcessor.h"
31
32 using namespace System;
33 using namespace SlimDX::Multimedia;
34
35 namespace SlimDX
36 {
37 namespace XAPO
38 {
39         BaseProcessor::BaseProcessor( SlimDX::XAPO::RegistrationProperties properties )
40         {
41                 XAPO_REGISTRATION_PROPERTIES props = properties.ToUnmanaged();
42
43                 Construct( new XAPOBaseImpl( this, &props ) );
44         }
45
46         int BaseProcessor::CalculateInputFrames( int outputFrameCount )
47         {
48                 return InternalPointer->CalcInputFrames( outputFrameCount );
49         }
50
51         int BaseProcessor::CalculateOutputFrames( int inputFrameCount )
52         {
53                 return InternalPointer->CalcOutputFrames( inputFrameCount );
54         }
55
56         Result BaseProcessor::Initialize( DataStream^ data )
57         {
58                 HRESULT hr = InternalPointer->Initialize( data->PositionPointer, static_cast<UINT32>( data->RemainingLength ) );
59                 return Result( hr );
60         }
61
62         bool BaseProcessor::IsInputFormatSupported( SlimDX::Multimedia::WaveFormat^ outputFormat, SlimDX::Multimedia::WaveFormat^ requestedInputFormat, [Out] SlimDX::Multimedia::WaveFormat^% supportedInputFormat )
63         {
64                 auto_array<WAVEFORMATEX> output = WaveFormat::ToUnmanaged( outputFormat );
65                 auto_array<WAVEFORMATEX> input = WaveFormat::ToUnmanaged( requestedInputFormat );
66                 WAVEFORMATEX *supported = NULL;
67
68                 HRESULT hr = InternalPointer->IsInputFormatSupported( output.get(), input.get(), &supported );
69                 supportedInputFormat = WaveFormat::FromUnmanaged( *supported );
70                 return hr == S_OK;
71         }
72
73         bool BaseProcessor::IsOutputFormatSupported( SlimDX::Multimedia::WaveFormat^ inputFormat, SlimDX::Multimedia::WaveFormat^ requestedOutputFormat, [Out] SlimDX::Multimedia::WaveFormat^% supportedOutputFormat )
74         {
75                 auto_array<WAVEFORMATEX> input = WaveFormat::ToUnmanaged( inputFormat );
76                 auto_array<WAVEFORMATEX> output = WaveFormat::ToUnmanaged( requestedOutputFormat );
77                 WAVEFORMATEX *supported = NULL;
78
79                 HRESULT hr = InternalPointer->IsOutputFormatSupported( input.get(), output.get(), &supported );
80                 supportedOutputFormat = WaveFormat::FromUnmanaged( *supported );
81                 return hr == S_OK;
82         }
83
84         Result BaseProcessor::LockForProcess( array<LockParameter>^ inputParameters, array<LockParameter>^ outputParameters )
85         {
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 );
88
89                 for( int i = 0; i < inputParameters->Length; i++ )
90                 {
91                         XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS p;
92                         p.pFormat = WaveFormat::ToUnmanaged( inputParameters[i].Format ).release();
93                         p.MaxFrameCount = inputParameters[i].MaxFrameCount;
94
95                         input[i] = p;
96                 }
97
98                 for( int i = 0; i < outputParameters->Length; i++ )
99                 {
100                         XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS p;
101                         p.pFormat = WaveFormat::ToUnmanaged( outputParameters[i].Format ).release();
102                         p.MaxFrameCount = outputParameters[i].MaxFrameCount;
103
104                         output[i] = p;
105                 }
106
107                 HRESULT hr = InternalPointer->LockForProcess( inputParameters->Length, &input[0], outputParameters->Length, &output[0] );
108                 return Result( hr );
109         }
110
111         void BaseProcessor::Reset()
112         {
113                 InternalPointer->Reset();
114         }
115
116         void BaseProcessor::UnlockForProcess()
117         {
118                 InternalPointer->UnlockForProcess();
119         }
120
121         void BaseProcessor::ProcessThru( DataStream^ inputBuffer, array<float>^ outputBuffer, int frameCount, int inputChannelCount, int outputChannelCount, bool mixWithDestination )
122         {
123                 pin_ptr<float> pinnedOutput = &outputBuffer[0];
124                 ImplPointer->ProcessThru( inputBuffer->PositionPointer, pinnedOutput, frameCount, static_cast<WORD>( inputChannelCount ), static_cast<WORD>( outputChannelCount ), mixWithDestination );
125         }
126
127         Result BaseProcessor::ValidateFormatDefault( SlimDX::Multimedia::WaveFormat^ format )
128         {
129                 auto_array<WAVEFORMATEX> wave = WaveFormat::ToUnmanaged( format );
130                 HRESULT hr = ImplPointer->ValidateFormatDefault( wave.get(), FALSE );
131
132                 return Result( hr );
133         }
134
135         Result BaseProcessor::ValidateFormatPair( SlimDX::Multimedia::WaveFormat^ supportedFormat, SlimDX::Multimedia::WaveFormat^ requestedFormat )
136         {
137                 auto_array<WAVEFORMATEX> supported = WaveFormat::ToUnmanaged( supportedFormat );
138                 auto_array<WAVEFORMATEX> requested = WaveFormat::ToUnmanaged( requestedFormat );
139
140                 HRESULT hr = ImplPointer->ValidateFormatPair( supported.get(), requested.get(), FALSE );
141                 return Result( hr );
142         }
143
144         SlimDX::XAPO::RegistrationProperties BaseProcessor::RegistrationProperties::get()
145         {
146                 return SlimDX::XAPO::RegistrationProperties::FromUnmanaged( *ImplPointer->GetRegistrationPropertiesInternal() );
147         }
148
149         bool BaseProcessor::IsLocked::get()
150         {
151                 return ImplPointer->IsLocked() > 0;
152         }
153
154         XAPOBaseImpl::XAPOBaseImpl( BaseProcessor^ processor, XAPO_REGISTRATION_PROPERTIES *pRegProperties )
155                 : CXAPOBase( pRegProperties )
156         {
157                 m_processor = processor;
158         }
159
160         void XAPOBaseImpl::Process( UINT32 InputProcessParameterCount, const XAPO_PROCESS_BUFFER_PARAMETERS *pInputProcessParameters, UINT32 OutputProcessParameterCount, XAPO_PROCESS_BUFFER_PARAMETERS *pOutputProcessParameters, BOOL IsEnabled )
161         {
162                 try
163                 {
164                         array<BufferParameter>^ input = gcnew array<BufferParameter>( InputProcessParameterCount );
165                         for( int i = 0; i < input->Length; i++ )
166                         {
167                                 BufferParameter p;
168                                 p.Buffer = IntPtr( pInputProcessParameters[i].pBuffer );
169                                 p.Flags = static_cast<BufferFlags>( pInputProcessParameters[i].BufferFlags );
170                                 p.ValidFrameCount = pInputProcessParameters[i].ValidFrameCount;
171
172                                 input[i] = p;
173                         }
174
175                         array<BufferParameter>^ output = gcnew array<BufferParameter>( OutputProcessParameterCount );
176                         for( int i = 0; i < output->Length; i++ )
177                         {
178                                 BufferParameter p;
179                                 p.Buffer = IntPtr( pOutputProcessParameters[i].pBuffer );
180                                 p.Flags = static_cast<BufferFlags>( pOutputProcessParameters[i].BufferFlags );
181                                 p.ValidFrameCount = pOutputProcessParameters[i].ValidFrameCount;
182
183                                 output[i] = p;
184                         }
185
186                         m_processor->Process( input, output, IsEnabled > 0 );
187                 }
188                 catch(...)
189                 {
190                 }
191         }
192 }
193 }