Exemplo 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="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);
        }
Exemplo 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="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);
        }
Exemplo n.º 3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="XAudio2" /> class.
 /// </summary>
 /// <param name="ptr">Native pointer of the <see cref="XAudio2Voice" /> object.</param>
 /// <param name="version">The XAudio2 subversion to use.</param>
 protected XAudio2(IntPtr ptr, XAudio2Version version)
     : base(ptr)
 {
     _version = version;
 }
Exemplo n.º 4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="XAudio2SubmixVoice" /> class.
 /// </summary>
 /// <param name="ptr">Native pointer of the <see cref="XAudio2SubmixVoice" /> object.</param>
 /// <param name="version">The <see cref="XAudio2Version"/> to use.</param>
 public XAudio2SubmixVoice(IntPtr ptr, XAudio2Version version)
     : base(ptr, version)
 {
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XAudio2"/> class.
 /// </summary>
 public XAudio2(XAudio2Version version)
     : this(XAudio2Flags.None, ProcessorSpecifier.DefaultProcessor, version)
 {
 }
Exemplo n.º 6
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="XAudio2" /> class.
 /// </summary>
 /// <param name="ptr">Native pointer of the <see cref="XAudio2Voice" /> object.</param>
 /// <param name="version">The XAudio2 subversion to use.</param>
 protected XAudio2(IntPtr ptr, XAudio2Version version)
     : base(ptr)
 {
     _version = version;
 }
Exemplo n.º 7
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="XAudio2SourceVoice" /> class.
 /// </summary>
 /// <param name="ptr">Native pointer of the <see cref="XAudio2SourceVoice" /> object.</param>
 /// <param name="version">The <see cref="XAudio2Version"/> to use.</param>
 public XAudio2SourceVoice(IntPtr ptr, XAudio2Version version)
     : base(ptr, version)
 {
 }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XAudio2" /> class.
 /// </summary>
 /// <param name="requestedVersion">The requested version.</param>
 public XAudio2(XAudio2Version requestedVersion)
     : this(XAudio2Flags.None, ProcessorSpecifier.DefaultProcessor, requestedVersion)
 {
 }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
 public IXAudio2(XAudio2Version requestedVersion)
     : this(XAudio2Flags.None, ProcessorSpecifier.Processor1, requestedVersion)
 {
 }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XAudio2" /> class.
 /// </summary>
 /// <param name="requestedVersion">The requested version.</param>
 public XAudio2(XAudio2Version requestedVersion)
     : this(XAudio2Flags.None, ProcessorSpecifier.DefaultProcessor, requestedVersion)
 {
 }
Exemplo n.º 13
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="XAudio2MasteringVoice" /> class.
 /// </summary>
 /// <param name="ptr">Native pointer of the <see cref="XAudio2MasteringVoice" /> object.</param>
 /// <param name="version">The <see cref="XAudio2Version"/> to use.</param>
 public XAudio2MasteringVoice(IntPtr ptr, XAudio2Version version)
     : base(ptr, version)
 {
 }
Exemplo n.º 14
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="XAudio2MasteringVoice" /> class.
 /// </summary>
 /// <param name="ptr">Native pointer of the <see cref="XAudio2MasteringVoice" /> object.</param>
 /// <param name="version">The <see cref="XAudio2Version"/> to use.</param>        
 public XAudio2MasteringVoice(IntPtr ptr, XAudio2Version version)
     : base(ptr, version)
 {
 }
Exemplo n.º 15
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="XAudio2" /> class.
 /// </summary>
 /// <param name="ptr">Native pointer of the <see cref="XAudio2Voice" /> object.</param>
 /// <param name="version">The XAudio2 subversion to use.</param>
 protected XAudio2(IntPtr ptr, XAudio2Version version)
     : base(ptr)
 {
     _version = version;
     InitializeEngineCallback();
 }
Exemplo n.º 16
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="XAudio2SubmixVoice" /> class.
 /// </summary>
 /// <param name="ptr">Native pointer of the <see cref="XAudio2SubmixVoice" /> object.</param>
 /// <param name="version">The <see cref="XAudio2Version"/> to use.</param>
 public XAudio2SubmixVoice(IntPtr ptr, XAudio2Version version)
     : base(ptr, version)
 {
 }
Exemplo n.º 17
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="XAudio2SourceVoice" /> class.
 /// </summary>
 /// <param name="ptr">Native pointer of the <see cref="XAudio2SourceVoice" /> object.</param>
 /// <param name="version">The <see cref="XAudio2Version"/> to use.</param>        
 public XAudio2SourceVoice(IntPtr ptr, XAudio2Version version)
     : base(ptr, version)
 {
 }
Exemplo n.º 18
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="XAudio2Voice" /> class.
 /// </summary>
 /// <param name="ptr">Native pointer of the <see cref="XAudio2Voice" /> object.</param>
 /// <param name="version">The <see cref="XAudio2Version"/> to use.</param>
 public XAudio2Voice(IntPtr ptr, XAudio2Version version)
     : base(ptr)
 {
     _version = version;
 }
Exemplo n.º 19
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="XAudio2" /> class.
 /// </summary>
 /// <param name="ptr">Native pointer of the <see cref="XAudio2Voice" /> object.</param>
 /// <param name="version">The XAudio2 subversion to use.</param>
 protected XAudio2(IntPtr ptr, XAudio2Version version)
     : base(ptr)
 {
     _version = version;
     InitializeEngineCallback();
 }