OSDN Git Service

#32713 初コミット。SVNrev567時点での、ファイルはbranch/140707(ReBuild XGVersion)から移行したもの。
[dtxmaniaxg-verk/dtxmaniaxg-verk-git.git] / SlimDXc_Jun2010(VC++2008) / source / xapo / IAudioProcessor.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 "../DataStream.h"
25 #include "IAudioProcessor.h"
26
27 using namespace System;
28 using namespace SlimDX::Multimedia;
29
30 namespace SlimDX
31 {
32 namespace XAPO
33 {
34         XAPOShim::XAPOShim( IAudioProcessor^ wrappedInterface )
35         {
36                 m_interface = wrappedInterface;
37                 refCount = 1;
38
39                 if( IParameterProvider::typeid->IsAssignableFrom( wrappedInterface->GetType() ) )
40                         m_parameters = safe_cast<IParameterProvider^>( wrappedInterface );
41                 else
42                         m_parameters = nullptr;
43         }
44
45         HRESULT XAPOShim::QueryInterface( const IID &iid, LPVOID *ppv )
46         {
47                 if( iid == __uuidof(IXAPO) )
48                 {
49                         AddRef();
50                         *ppv = static_cast<IXAPO*>( this );
51                         return S_OK;
52                 }
53                 else if( iid == __uuidof(IUnknown) )
54                 {
55                         AddRef();
56                         *ppv = static_cast<IUnknown*>( static_cast<IXAPO*>( this ) );
57                         return S_OK;
58                 }
59                 else if( iid == __uuidof(IXAPOParameters) && safe_cast<IParameterProvider^>( m_parameters ) != nullptr )
60                 {
61                         AddRef();
62                         *ppv = static_cast<IXAPOParameters*>( this );
63                         return S_OK;
64                 }
65
66                 return E_NOTIMPL;
67         }
68
69         ULONG XAPOShim::AddRef()
70         {
71                 return InterlockedIncrement( &refCount );
72         }
73
74         ULONG XAPOShim::Release()
75         {
76                 if( InterlockedDecrement( &refCount ) == 0 )
77                         delete this;
78                 return refCount;
79         }
80
81         UINT32 WINAPI XAPOShim::CalcInputFrames( UINT32 OutputFrameCount )
82         {
83                 try
84                 {
85                         return m_interface->CalculateInputFrames( OutputFrameCount );
86                 }
87                 catch(...)
88                 {
89                 }
90
91                 return 0;
92         }
93
94         UINT32 WINAPI XAPOShim::CalcOutputFrames( UINT32 InputFrameCount )
95         {
96                 try
97                 {
98                         return m_interface->CalculateOutputFrames( InputFrameCount );
99                 }
100                 catch(...)
101                 {
102                 }
103
104                 return 0;
105         }
106
107         HRESULT WINAPI XAPOShim::GetRegistrationProperties( XAPO_REGISTRATION_PROPERTIES **ppRegistrationProperties )
108         {
109                 try
110                 {
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 ) );
114
115                         *ppRegistrationProperties = ptr;
116                 }
117                 catch( SlimDXException^ ex )
118                 {
119                         return ex->ResultCode.Code;
120                 }
121                 catch( Exception^ )
122                 {
123                         return E_FAIL;
124                 }
125
126                 return S_OK;
127         }
128
129         HRESULT WINAPI XAPOShim::Initialize( const void *pData, UINT32 DataByteSize )
130         {
131                 try
132                 {
133                         DataStream^ data = gcnew DataStream( pData, DataByteSize, true, false );
134                         
135                         return m_interface->Initialize( data ).Code;
136                 }
137                 catch( SlimDXException^ ex )
138                 {
139                         return ex->ResultCode.Code;
140                 }
141                 catch( Exception^ )
142                 {
143                         return E_FAIL;
144                 }
145
146                 return S_OK;
147         }
148
149         HRESULT WINAPI XAPOShim::IsInputFormatSupported( const WAVEFORMATEX *pOutputFormat, const WAVEFORMATEX *pRequestedInputFormat, WAVEFORMATEX **ppSupportedInputFormat )
150         {
151                 try
152                 {
153                         WaveFormat^ format;
154                         bool result = m_interface->IsInputFormatSupported( WaveFormat::FromUnmanaged( *pOutputFormat ), WaveFormat::FromUnmanaged( *pRequestedInputFormat ), format );
155
156                         auto_array<WAVEFORMATEX> native = WaveFormat::ToUnmanaged( format );
157                         *ppSupportedInputFormat = native.release();
158
159                         return result ? S_OK : XAPO_E_FORMAT_UNSUPPORTED;
160                 }
161                 catch( SlimDXException^ ex )
162                 {
163                         return ex->ResultCode.Code;
164                 }
165                 catch( Exception^ )
166                 {
167                         return E_FAIL;
168                 }
169
170                 return S_OK;
171         }
172
173         HRESULT WINAPI XAPOShim::IsOutputFormatSupported( const WAVEFORMATEX *pInputFormat, const WAVEFORMATEX *pRequestedOutputFormat, WAVEFORMATEX **ppSupportedOutputFormat )
174         {
175                 try
176                 {
177                         WaveFormat^ format;
178                         bool result = m_interface->IsOutputFormatSupported( WaveFormat::FromUnmanaged( *pInputFormat ), WaveFormat::FromUnmanaged( *pRequestedOutputFormat ), format );
179
180                         auto_array<WAVEFORMATEX> native = WaveFormat::ToUnmanaged( format );
181                         *ppSupportedOutputFormat = native.release();
182
183                         return result ? S_OK : XAPO_E_FORMAT_UNSUPPORTED;
184                 }
185                 catch( SlimDXException^ ex )
186                 {
187                         return ex->ResultCode.Code;
188                 }
189                 catch( Exception^ )
190                 {
191                         return E_FAIL;
192                 }
193
194                 return S_OK;
195         }
196
197         HRESULT WINAPI XAPOShim::LockForProcess( UINT32 InputLockedParameterCount, const XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS *pInputLockedParameters, UINT32 OutputLockedParameterCount, const XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS *pOutputLockedParameters )
198         {
199                 try
200                 {
201                         array<LockParameter>^ input = gcnew array<LockParameter>( InputLockedParameterCount );
202                         for( int i = 0; i < input->Length; i++ )
203                         {
204                                 LockParameter p;
205                                 p.Format = WaveFormat::FromUnmanaged( *pInputLockedParameters[i].pFormat );
206                                 p.MaxFrameCount = pInputLockedParameters[i].MaxFrameCount;
207
208                                 input[i] = p;
209                         }
210
211                         array<LockParameter>^ output = gcnew array<LockParameter>( OutputLockedParameterCount );
212                         for( int i = 0; i < output->Length; i++ )
213                         {
214                                 LockParameter p;
215                                 p.Format = WaveFormat::FromUnmanaged( *pOutputLockedParameters[i].pFormat );
216                                 p.MaxFrameCount = pOutputLockedParameters[i].MaxFrameCount;
217
218                                 output[i] = p;
219                         }
220
221                         return m_interface->LockForProcess( input, output ).Code;
222                 }
223                 catch( SlimDXException^ ex )
224                 {
225                         return ex->ResultCode.Code;
226                 }
227                 catch( Exception^ )
228                 {
229                         return E_FAIL;
230                 }
231
232                 return S_OK;
233         }
234
235         void WINAPI XAPOShim::Process( UINT32 InputProcessParameterCount, const XAPO_PROCESS_BUFFER_PARAMETERS *pInputProcessParameters, UINT32 OutputProcessParameterCount, XAPO_PROCESS_BUFFER_PARAMETERS *pOutputProcessParameters, BOOL IsEnabled )
236         {
237                 try
238                 {
239                         array<BufferParameter>^ input = gcnew array<BufferParameter>( InputProcessParameterCount );
240                         for( int i = 0; i < input->Length; i++ )
241                         {
242                                 BufferParameter p;
243                                 p.Buffer = IntPtr( pInputProcessParameters[i].pBuffer );
244                                 p.Flags = static_cast<BufferFlags>( pInputProcessParameters[i].BufferFlags );
245                                 p.ValidFrameCount = pInputProcessParameters[i].ValidFrameCount;
246
247                                 input[i] = p;
248                         }
249
250                         array<BufferParameter>^ output = gcnew array<BufferParameter>( OutputProcessParameterCount );
251                         for( int i = 0; i < output->Length; i++ )
252                         {
253                                 BufferParameter p;
254                                 p.Buffer = IntPtr( pOutputProcessParameters[i].pBuffer );
255                                 p.Flags = static_cast<BufferFlags>( pOutputProcessParameters[i].BufferFlags );
256                                 p.ValidFrameCount = pOutputProcessParameters[i].ValidFrameCount;
257
258                                 output[i] = p;
259                         }
260
261                         m_interface->Process( input, output, IsEnabled > 0 );
262                 }
263                 catch(...)
264                 {
265                 }
266         }
267
268         void WINAPI XAPOShim::Reset()
269         {
270                 try
271                 {
272                         m_interface->Reset();
273                 }
274                 catch(...)
275                 {
276                 }
277         }
278
279         void WINAPI XAPOShim::UnlockForProcess()
280         {
281                 try
282                 {
283                         m_interface->UnlockForProcess();
284                 }
285                 catch(...)
286                 {
287                 }
288         }
289
290         void WINAPI XAPOShim::GetParameters( void *pParameters, UINT32 ParameterByteSize )
291         {
292                 try
293                 {
294                         m_parameters->GetParameters( gcnew DataStream( pParameters, ParameterByteSize, true, true, false ) );
295                 }
296                 catch(...)
297                 {
298                 }
299         }
300
301         void WINAPI XAPOShim::SetParameters( const void *pParameters, UINT32 ParameterByteSize )
302         {
303                 try
304                 {
305                         m_parameters->SetParameters( gcnew DataStream( pParameters, ParameterByteSize, true, false ) );
306                 }
307                 catch(...)
308                 {
309                 }
310         }
311 }
312 }