示例#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);
        }
示例#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);
        }
示例#3
0
文件: XAudio2.cs 项目: oeoen/SharpDX
        /// <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);
        }