// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; using SharpDX.Multimedia; namespace SharpDX.XAPO { /// /// Base AudioProcessor class that implements methods from . This class is /// also providing its parameter through a generic. /// /// type of the parameter for this AudioProcessor public abstract partial class AudioProcessorBase : CallbackBase, AudioProcessor, ParameterProvider where T : struct { private RegistrationProperties _registrationProperies; private T _parameters; private WaveFormat _inputFormatLocked; private WaveFormat _outputFormatLocked; private int _maxFrameCountLocked; /// /// Return parameters /// public virtual T Parameters { get { return _parameters; } set { _parameters = value; } } /// /// Gets the input format locked. /// /// The input format locked. protected WaveFormat InputFormatLocked { get { return _inputFormatLocked; } } /// /// Gets the output format locked. /// /// The output format locked. protected WaveFormat OutputFormatLocked { get { return _outputFormatLocked; } } /// /// Gets the max frame count locked. /// /// The max frame count locked. protected int MaxFrameCountLocked { get { return _maxFrameCountLocked; } } /// /// Returns the registration properties of an XAPO. /// /// a structure containing the registration properties the XAPO was created with; use XAPOFree to free the structure. /// HRESULT IXAPO::GetRegistrationProperties([Out] XAPO_REGISTRATION_PROPERTIES** ppRegistrationProperties) public RegistrationProperties RegistrationProperties { get { return _registrationProperies; } protected set { _registrationProperies = value; } } /// /// Queries if a specific input format is supported for a given output format. /// /// Output format. /// Input format to check for being supported. /// If not NULL, and the input format is not supported for the given output format, ppSupportedInputFormat returns a pointer to the closest input format that is supported. Use {{XAPOFree}} to free the returned structure. /// No documentation. /// HRESULT IXAPO::IsInputFormatSupported([None] const WAVEFORMATEX* pOutputFormat,[None] const WAVEFORMATEX* pRequestedInputFormat,[Out, Optional] WAVEFORMATEX** ppSupportedInputFormat) public bool IsInputFormatSupported(WaveFormat outputFormat, WaveFormat requestedInputFormat, out WaveFormat supportedInputFormat) { supportedInputFormat = requestedInputFormat; return true; } /// /// Queries if a specific output format is supported for a given input format. /// /// [in] Input format. /// [in] Output format to check for being supported. /// [out] If not NULL and the output format is not supported for the given input format, ppSupportedOutputFormat returns a pointer to the closest output format that is supported. Use {{XAPOFree}} to free the returned structure. /// No documentation. /// HRESULT IXAPO::IsOutputFormatSupported([None] const WAVEFORMATEX* pInputFormat,[None] const WAVEFORMATEX* pRequestedOutputFormat,[Out, Optional] WAVEFORMATEX** ppSupportedOutputFormat) public bool IsOutputFormatSupported(WaveFormat inputFormat, WaveFormat requestedOutputFormat, out WaveFormat supportedOutputFormat) { supportedOutputFormat = requestedOutputFormat; return true; } /// /// Performs any effect-specific initialization. /// /// Effect-specific initialization parameters, may be NULL if DataByteSize is 0. /// No documentation. /// HRESULT IXAPO::Initialize([In, Buffer, Optional] const void* pData,[None] UINT32 DataByteSize) public void Initialize(DataStream stream) { } /// /// Resets variables dependent on frame history. /// /// void IXAPO::Reset() public void Reset() { } /// /// Called by XAudio2 to lock the input and output configurations of an XAPO allowing it to /// do any final initialization before {{Process}} is called on the realtime thread. /// /// Array of input structures.pInputLockedParameters may be NULL if InputLockedParameterCount is 0, otherwise it must have InputLockedParameterCount elements. /// Array of output structures.pOutputLockedParameters may be NULL if OutputLockedParameterCount is 0, otherwise it must have OutputLockedParameterCount elements. /// No documentation. /// HRESULT IXAPO::LockForProcess([None] UINT32 InputLockedParameterCount,[In, Buffer, Optional] const XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS* pInputLockedParameters,[None] UINT32 OutputLockedParameterCount,[In, Buffer, Optional] const XAPO_LOCKFORPROCESS_BUFFER_PARAMETERS* pOutputLockedParameters) public void LockForProcess(LockParameters[] inputLockedParameters, LockParameters[] outputLockedParameters) { _inputFormatLocked = inputLockedParameters[0].Format; _outputFormatLocked = outputLockedParameters[0].Format; _maxFrameCountLocked = inputLockedParameters[0].MaxFrameCount; } /// /// Deallocates variables that were allocated with the {{LockForProcess}} method. /// /// void IXAPO::UnlockForProcess() public void UnlockForProcess() { } /// /// Runs the XAPO's digital signal processing (DSP) code on the given input and output buffers. /// /// [in] Input array of structures. /// [in, out] Output array of structures. On input, the value of .ValidFrameCount indicates the number of frames that the XAPO should write to the output buffer. On output, the value of .ValidFrameCount indicates the actual number of frames written. /// TRUE to process normally; FALSE to process thru. See Remarks for additional information. /// void IXAPO::Process([None] UINT32 InputProcessParameterCount,[In, Buffer, Optional] const XAPO_PROCESS_BUFFER_PARAMETERS* pInputProcessParameters,[None] UINT32 OutputProcessParameterCount,[InOut, Buffer, Optional] XAPO_PROCESS_BUFFER_PARAMETERS* pOutputProcessParameters,[None] BOOL IsEnabled) public abstract void Process(BufferParameters[] inputProcessParameters, BufferParameters[] outputProcessParameters, bool isEnabled); /// /// Returns the number of input frames required to generate the given number of output frames. /// /// The number of output frames desired. /// No documentation. /// UINT32 IXAPO::CalcInputFrames([None] UINT32 OutputFrameCount) public int CalcInputFrames(int outputFrameCount) { return outputFrameCount; } /// /// Returns the number of output frames that will be generated from a given number of input frames. /// /// The number of input frames. /// No documentation. /// UINT32 IXAPO::CalcOutputFrames([None] UINT32 InputFrameCount) public int CalcOutputFrames(int inputFrameCount) { return inputFrameCount; } /// /// Sets effect-specific parameters. /// /// Effect-specific parameter block. /// void IXAPOParameters::SetParameters([In, Buffer] const void* pParameters,[None] UINT32 ParameterByteSize) /* public void SetParameters(IntPtr arametersRef, int parameterByteSize) */ void ParameterProvider.SetParameters(DataStream parameters) { Utilities.Read(parameters.PositionPointer, ref _parameters); } /// /// Gets the current values for any effect-specific parameters. /// /// [in, out] Receives an effect-specific parameter block. /// void IXAPOParameters::GetParameters([Out, Buffer] void* pParameters,[None] UINT32 ParameterByteSize) void ParameterProvider.GetParameters(DataStream parameters) { Utilities.Write(parameters.PositionPointer, ref _parameters); } } }