コード例 #1
0
        /// <summary>
        ///     Retrieves the stream format that the audio engine uses for its
        ///     internal processing of shared-mode streams.
        /// </summary>
        /// <param name="deviceFormat">
        ///     Retrieves the mix format that the audio engine uses for its internal processing of
        ///     shared-mode streams.
        /// </param>
        /// <remarks>
        ///     For more information, see
        ///     <see href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd370872(v=vs.85).aspx" />.
        /// </remarks>
        /// <returns>HRESULT</returns>
        public unsafe int GetMixFormatNative(out WaveFormat deviceFormat)
        {
            IntPtr pdeviceFormat = IntPtr.Zero;
            int    result;

            if ((result = InteropCalls.CallI(UnsafeBasePtr, &pdeviceFormat, ((void **)(*(void **)UnsafeBasePtr))[8])) ==
                0 && pdeviceFormat != IntPtr.Zero)
            {
                try
                {
                    //deviceFormat = Marshal.PtrToStructure(pdeviceFormat, typeof (WaveFormat)) as WaveFormat;
                    //if (deviceFormat != null && deviceFormat.WaveFormatTag == AudioEncoding.Extensible)
                    //{
                    //    deviceFormat =
                    //        Marshal.PtrToStructure(pdeviceFormat, typeof (WaveFormatExtensible)) as WaveFormatExtensible;
                    //}
                    deviceFormat = WaveFormatMarshaler.PointerToWaveFormat(pdeviceFormat);
                }
                finally
                {
                    Marshal.FreeCoTaskMem(pdeviceFormat);
                }
                return(result);
            }
            deviceFormat = null;
            return(result);
        }
コード例 #2
0
ファイル: MFMediaType.cs プロジェクト: Minep/LunalipseMP_v2
        /// <summary>
        /// Converts the <see cref="MFMediaType"/> to a <see cref="WaveFormat"/>.
        /// </summary>
        /// <param name="flags">Contains a flag from the <see cref="MFWaveFormatExConvertFlags"/> enumeration.</param>
        /// <returns>The <see cref="WaveFormat"/> which got created based on the <see cref="MFMediaType"/>.</returns>
        public unsafe WaveFormat ToWaveFormat(MFWaveFormatExConvertFlags flags)
        {
            IntPtr pointer = IntPtr.Zero;

            try
            {
                int cbSize;
                MediaFoundationException.Try(
                    NativeMethods.MFCreateWaveFormatExFromMFMediaType(BasePtr.ToPointer(), &pointer, &cbSize,
                                                                      (int)flags), "Interop", "MFCreateWaveFormatExFromMFMediaType");
            }
            finally
            {
                Marshal.FreeCoTaskMem(pointer);
            }
            //var waveformat = (WaveFormat)Marshal.PtrToStructure(pointer, typeof(WaveFormat));
            //if (waveformat.WaveFormatTag == AudioEncoding.Extensible)
            //    waveformat = (WaveFormatExtensible)Marshal.PtrToStructure(pointer, typeof(WaveFormatExtensible));
            //return waveformat;
            return(WaveFormatMarshaler.PointerToWaveFormat(pointer));
        }
コード例 #3
0
        /// <summary>
        /// Returns a description of the format of the sound data in the buffer.
        /// </summary>
        /// <returns>A description of the format of the sound data in the buffer. The returned description is either of the type <see cref="WaveFormat"/> or of the type <see cref="WaveFormatExtensible"/>.</returns>
        public WaveFormat GetWaveFormat()
        {
            int      size;
            DSResult result = GetFormatNative(IntPtr.Zero, 0, out size);

            DirectSoundException.Try(result, InterfaceName, "GetWaveFormat");

            IntPtr ptr = Marshal.AllocCoTaskMem(size);

            try
            {
                int n;
                result = GetFormatNative(ptr, size, out n);
                DirectSoundException.Try(result, InterfaceName, "GetWaveFormat");
                return(WaveFormatMarshaler.PointerToWaveFormat(ptr));
            }
            finally
            {
                Marshal.FreeCoTaskMem(ptr);
            }
        }