Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XAudio2" /> class.
        /// </summary>
        /// <param name="flags">Specify a Debug or Normal XAudio2 instance.</param>
        /// <param name="processorSpecifier">The processor specifier.</param>
        /// <param name="version">The version to use (auto, 2.7 or 2.8).</param>
        /// <exception cref="System.InvalidOperationException">XAudio2 version [ + version + ] is not installed</exception>
        public XAudio2(XAudio2Flags flags, ProcessorSpecifier processorSpecifier, XAudio2Version version = XAudio2Version.Default)
            : base(IntPtr.Zero)
        {
#if DESKTOP_APP
            Guid clsid = ((int)flags == 1) ? CLSID_XAudio27_Debug : CLSID_XAudio27;
            if ((version == XAudio2Version.Default || version == XAudio2Version.Version27) && Utilities.TryCreateComInstance(clsid, Utilities.CLSCTX.ClsctxInprocServer, IID_IXAudio2, this))
            {
                SetupVtblFor27();
                // Initialize XAudio2
                Initialize(0, processorSpecifier);
                Version = XAudio2Version.Version27;
            }
            else
#endif
            if (version == XAudio2Version.Default || version == XAudio2Version.Version28)
            {
                XAudio2Functions.XAudio2Create(this, 0, (int)processorSpecifier);
                Version = XAudio2Version.Version28;
            }
            else
            {
                throw new InvalidOperationException("XAudio2 version [" + version + "] is not installed");
            }

            // Register engine callback

            engineCallbackImpl = new EngineCallbackImpl(this);
            engineShadowPtr    = EngineShadow.ToIntPtr(engineCallbackImpl);
            RegisterForCallbacks_(engineShadowPtr);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XAudio2" /> class.
        /// </summary>
        /// <param name="flags">Specify a Debug or Normal XAudio2 instance.</param>
        /// <param name="processorSpecifier">The processor specifier.</param>
        /// <param name="requestedVersion">The requestedVersion to use (auto, 2.7 or 2.8).</param>
        /// <exception cref="System.InvalidOperationException">XAudio2 requestedVersion [ + requestedVersion + ] is not installed</exception>
        public XAudio2(XAudio2Flags flags, ProcessorSpecifier processorSpecifier, XAudio2Version requestedVersion = XAudio2Version.Default)
            : base(IntPtr.Zero)
        {
            var tryVersions = requestedVersion == XAudio2Version.Default
                ? new[] { XAudio2Version.Version29, XAudio2Version.Version28, XAudio2Version.Version27 }
                : new[] { requestedVersion };

            foreach (var tryVersion in tryVersions)
            {
                switch (tryVersion)
                {
#if !WINDOWS_UWP
                case XAudio2Version.Version27:
                    Guid clsid = ((int)flags == 1) ? CLSID_XAudio27_Debug : CLSID_XAudio27;
                    if ((requestedVersion == XAudio2Version.Default || requestedVersion == XAudio2Version.Version27) && Utilities.TryCreateComInstance(clsid, Utilities.CLSCTX.ClsctxInprocServer, IID_IXAudio2, this))
                    {
                        SetupVtblFor27();
                        // Initialize XAudio2
                        Initialize(0, processorSpecifier);
                        Version = XAudio2Version.Version27;
                    }
                    break;
#endif
                case XAudio2Version.Version28:
                    try
                    {
                        XAudio28Functions.XAudio2Create(this, 0, (int)processorSpecifier);
                        Version = XAudio2Version.Version28;
                    }
                    catch (DllNotFoundException) { }
                    break;

                case XAudio2Version.Version29:
                    try
                    {
                        XAudio29Functions.XAudio2Create(this, 0, (int)processorSpecifier);
                        Version = XAudio2Version.Version29;
                    }
                    catch (DllNotFoundException) { }
                    break;
                }

                // Early exit if we found a requestedVersion
                if (Version != XAudio2Version.Default)
                {
                    break;
                }
            }

            if (Version == XAudio2Version.Default)
            {
                throw new DllNotFoundException(string.Format("Unable to find XAudio2 dlls for requested versions [{0}], not installed on this machine", requestedVersion == XAudio2Version.Default ? "2.7, 2.8 or 2.9" : requestedVersion.ToString()));
            }

            // Register engine callback

            engineCallbackImpl = new EngineCallbackImpl(this);
            engineShadowPtr    = EngineShadow.ToIntPtr(engineCallbackImpl);
            RegisterForCallbacks(engineCallbackImpl);
        }
Ejemplo n.º 3
0
 internal IXAudio2(ProcessorSpecifier processorSpecifier, bool registerCallback)
     : base(XAudio2Native.XAudio2Create(0, processorSpecifier))
 {
     // Register engine callback
     if (registerCallback)
     {
         _engineCallback = new EngineCallbackImpl(this);
         RegisterForCallbacks(_engineCallback);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Create new instance of <see cref="IXAudio2"/> class.
        /// </summary>
        /// <param name="processorSpecifier"></param>
        /// <param name="registerCallback">Whether to register for callback, uses native RegisterForCallbacks.</param>
        public IXAudio2(
            ProcessorSpecifier processorSpecifier = ProcessorSpecifier.UseDefaultProcessor,
            bool registerCallback = true)
            : base(IntPtr.Zero)
        {
            NativePointer = XAudio2Native.XAudio2Create(0, processorSpecifier);

            // Register engine callback
            if (registerCallback)
            {
                _engineCallback = new EngineCallbackImpl(this);
                RegisterForCallbacks(_engineCallback);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XAudio2"/> class.
        /// </summary>
        /// <param name="flags">Specify a Debug or Normal XAudio2 instance.</param>
        /// <param name="processorSpecifier">The processor specifier.</param>
        public XAudio2(XAudio2Flags flags, ProcessorSpecifier processorSpecifier)
            : base(IntPtr.Zero)
        {
#if !DIRECTX11_1
            Guid clsid = (flags == XAudio2Flags.DebugEngine) ? CLSID_XAudio2_Debug : CLSID_XAudio2;

            // Initialize for multithreaded
            //var result = Utilities.CoInitializeEx(IntPtr.Zero, Utilities.CoInit.MultiThreaded);
            //result.CheckError();

            Utilities.CreateComInstance(clsid, Utilities.CLSCTX.ClsctxInprocServer, Utilities.GetGuidFromType(typeof(XAudio2)), this);

            // Initialize XAudio2
            Initialize(0, processorSpecifier);
#else
            XAudio2Functions.XAudio2Create(this, 0, (int)processorSpecifier);
#endif
            // Register engine callback

            engineCallbackImpl = new EngineCallbackImpl(this);
            engineShadowPtr    = EngineShadow.ToIntPtr(engineCallbackImpl);
            RegisterForCallbacks_(engineShadowPtr);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XAudio2"/> class.
        /// </summary>
        /// <param name="flags">Specify a Debug or Normal XAudio2 instance.</param>
        /// <param name="processorSpecifier">The processor specifier.</param>
        public XAudio2(XAudio2Flags flags, ProcessorSpecifier processorSpecifier)
            : base(IntPtr.Zero)
        {
#if !DIRECTX11_1
            Guid clsid = (flags == XAudio2Flags.DebugEngine) ? CLSID_XAudio2_Debug : CLSID_XAudio2;

            // Initialize for multithreaded
            //var result = Utilities.CoInitializeEx(IntPtr.Zero, Utilities.CoInit.MultiThreaded);
            //result.CheckError();

            Utilities.CreateComInstance(clsid, Utilities.CLSCTX.ClsctxInprocServer, Utilities.GetGuidFromType(typeof(XAudio2)), this);

            // Initialize XAudio2
            Initialize(0, processorSpecifier);
#else

            XAudio2Functions.XAudio2Create(this, 0, (int)processorSpecifier);

#endif
            // Register engine callback

            engineCallbackImpl = new EngineCallbackImpl(this);
            engineShadowPtr = EngineShadow.ToIntPtr(engineCallbackImpl);
            RegisterForCallbacks_(engineShadowPtr);
        }
Ejemplo n.º 7
0
        public IXAudio2(XAudio2Flags flags, ProcessorSpecifier processorSpecifier, XAudio2Version requestedVersion = XAudio2Version.Default)
            : base(IntPtr.Zero)
        {
            var tryVersions = requestedVersion == XAudio2Version.Default
                ? new[] { XAudio2Version.Version29, XAudio2Version.Version28, XAudio2Version.Version27 }
                : new[] { requestedVersion };

            foreach (var tryVersion in tryVersions)
            {
                switch (tryVersion)
                {
                case XAudio2Version.Version27:
                    if (PlatformDetection.IsUAP)
                    {
                        throw new NotSupportedException("XAudio 2.7 is not supported on UAP platform");
                    }

                    Guid clsid = ((int)flags == 1) ? CLSID_XAudio27_Debug : CLSID_XAudio27;
                    if ((requestedVersion == XAudio2Version.Default || requestedVersion == XAudio2Version.Version27) &&
                        ComUtilities.TryCreateComInstance(clsid, ComContext.InprocServer, IID_IXAudio27, this))
                    {
                        SetupVtblFor27();
                        // Initialize XAudio2
                        Initialize(0, processorSpecifier);
                        Version = XAudio2Version.Version27;
                    }
                    break;

                case XAudio2Version.Version28:
                    try
                    {
                        NativePointer = XAudio28.XAudio2Create(0, processorSpecifier);
                        Version       = XAudio2Version.Version28;
                    }
                    catch (DllNotFoundException) { }
                    break;

                case XAudio2Version.Version29:
                    try
                    {
                        NativePointer = XAudio29.XAudio2Create(0, processorSpecifier);
                        Version       = XAudio2Version.Version29;
                    }
                    catch (DllNotFoundException) { }
                    break;
                }

                // Early exit if we found a requestedVersion
                if (Version != XAudio2Version.Default)
                {
                    break;
                }
            }

            if (Version == XAudio2Version.Default)
            {
                var versionStr = requestedVersion == XAudio2Version.Default ? "2.7, 2.8 or 2.9" : requestedVersion.ToString();
                throw new DllNotFoundException($"Unable to find XAudio2 dlls for requested versions [{versionStr}], not installed on this machine");
            }

            IXAudio2Voice.Version = Version;

            // Register engine callback
            _engineCallbackImpl = new EngineCallbackImpl(this);
            RegisterForCallbacks(_engineCallbackImpl);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XAudio2" /> class.
        /// </summary>
        /// <param name="flags">Specify a Debug or Normal XAudio2 instance.</param>
        /// <param name="processorSpecifier">The processor specifier.</param>
        /// <param name="requestedVersion">The requestedVersion to use (auto, 2.7 or 2.8).</param>
        /// <exception cref="System.InvalidOperationException">XAudio2 requestedVersion [ + requestedVersion + ] is not installed</exception>
        public XAudio2(XAudio2Flags flags, ProcessorSpecifier processorSpecifier, XAudio2Version requestedVersion = XAudio2Version.Default)
            : base(IntPtr.Zero)
        {
            var tryVersions = requestedVersion == XAudio2Version.Default
                ? new[] { XAudio2Version.Version29, XAudio2Version.Version28, XAudio2Version.Version27 }
                : new[] { requestedVersion };

            foreach (var tryVersion in tryVersions)
            {
                switch (tryVersion)
                {
#if DESKTOP_APP
                    case XAudio2Version.Version27:
                        Guid clsid = ((int)flags == 1) ? CLSID_XAudio27_Debug : CLSID_XAudio27;
                        if ((requestedVersion == XAudio2Version.Default || requestedVersion == XAudio2Version.Version27) && Utilities.TryCreateComInstance(clsid, Utilities.CLSCTX.ClsctxInprocServer, IID_IXAudio2, this))
                        {
                            SetupVtblFor27();
                            // Initialize XAudio2
                            Initialize(0, processorSpecifier);
                            Version = XAudio2Version.Version27;
                        }
                        break;
#endif
                    case XAudio2Version.Version28:
                        try
                        {
                            XAudio28Functions.XAudio2Create(this, 0, (int)processorSpecifier);
                            Version = XAudio2Version.Version28;
                        }
                        catch (DllNotFoundException) { }
                        break;
#if STORE_APP_10
                    case XAudio2Version.Version29:
                        try
                        {
                            XAudio29Functions.XAudio2Create(this, 0, (int)processorSpecifier);
                            Version = XAudio2Version.Version29;
                        }
                        catch (DllNotFoundException) { }
                        break;
#endif
                }

                // Early exit if we found a requestedVersion
                if (Version != XAudio2Version.Default)
                {
                    break;
                }
            }

            if (Version == XAudio2Version.Default)
            {
                throw new DllNotFoundException(string.Format("Unable to find XAudio2 dlls for requested versions [{0}], not installed on this machine", requestedVersion == XAudio2Version.Default ? "2.7, 2.8 or 2.9" : requestedVersion.ToString()));
            }

            // Register engine callback

            engineCallbackImpl = new EngineCallbackImpl(this);
            engineShadowPtr = EngineShadow.ToIntPtr(engineCallbackImpl);
            RegisterForCallbacks_(engineShadowPtr);
        }