Esempio 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);
        }
Esempio 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>
        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);
        }