Ejemplo n.º 1
0
        /// <summary>
        /// Helper function to retrieve a WaveFormat structure from a pointer
        /// </summary>
        /// <param name="pointer">Pointer to the WaveFormat rawdata</param>
        /// <returns>WaveFormat structure</returns>
        public unsafe static WaveFormat MarshalFrom(IntPtr pointer)
        {
            if (pointer == IntPtr.Zero)
            {
                return(null);
            }

            var pcmWaveFormat = *(__PcmNative *)pointer;
            var encoding      = pcmWaveFormat.waveFormatTag;

            // Load simple PcmWaveFormat if channels <= 2 and encoding is Pcm, IeeFloat, Wmaudio2, Wmaudio3
            // See http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.xaudio2.waveformatex%28v=vs.85%29.aspx
            if (pcmWaveFormat.channels <= 2 && (encoding == WaveFormatEncoding.Pcm || encoding == WaveFormatEncoding.IeeeFloat || encoding == WaveFormatEncoding.Wmaudio2 || encoding == WaveFormatEncoding.Wmaudio3))
            {
                var waveFormat = new WaveFormat();
                waveFormat.__MarshalFrom(ref pcmWaveFormat);
                return(waveFormat);
            }

            if (encoding == WaveFormatEncoding.Extensible)
            {
                var waveFormat = new WaveFormatExtensible();
                waveFormat.__MarshalFrom(ref *(WaveFormatExtensible.__Native *)pointer);
                return(waveFormat);
            }

            if (encoding == WaveFormatEncoding.Adpcm)
            {
                var waveFormat = new WaveFormatAdpcm();
                waveFormat.__MarshalFrom(ref *(WaveFormatAdpcm.__Native *)pointer);
                return(waveFormat);
            }

            throw new InvalidOperationException(string.Format("Unsupported WaveFormat [{0}]", encoding));
        }
Ejemplo n.º 2
0
        public static unsafe WaveFormat MarshalFrom(IntPtr pointer)
        {
            if (pointer == IntPtr.Zero)
            {
                return((WaveFormat)null);
            }
            WaveFormat.__PcmNative @ref = *(WaveFormat.__PcmNative *)(void *) pointer;
            WaveFormatEncoding     waveFormatEncoding = @ref.waveFormatTag;

            if ((int)@ref.channels <= 2 && (waveFormatEncoding == WaveFormatEncoding.Pcm || waveFormatEncoding == WaveFormatEncoding.IeeeFloat || (waveFormatEncoding == WaveFormatEncoding.Wmaudio2 || waveFormatEncoding == WaveFormatEncoding.Wmaudio3)))
            {
                WaveFormat waveFormat = new WaveFormat();
                waveFormat.__MarshalFrom(ref @ref);
                return(waveFormat);
            }
            else if (waveFormatEncoding == WaveFormatEncoding.Extensible)
            {
                WaveFormatExtensible formatExtensible = new WaveFormatExtensible();
                formatExtensible.__MarshalFrom(ref *(WaveFormatExtensible.__Native *)(void *) pointer);
                return((WaveFormat)formatExtensible);
            }
            else
            {
                if (waveFormatEncoding != WaveFormatEncoding.Adpcm)
                {
                    throw new InvalidOperationException(string.Format("Unsupported WaveFormat [{0}]", (object)waveFormatEncoding));
                }
                WaveFormatAdpcm waveFormatAdpcm = new WaveFormatAdpcm();
                waveFormatAdpcm.__MarshalFrom(ref *(WaveFormatAdpcm.__Native *)(void *) pointer);
                return((WaveFormat)waveFormatAdpcm);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Helper function to retrieve a WaveFormat structure from a pointer
        /// </summary>
        /// <param name="pointer">Pointer to the WaveFormat rawdata</param>
        /// <returns>WaveFormat structure</returns>
        public static unsafe WaveFormat MarshalFrom(IntPtr pointer)
        {
            if (pointer == IntPtr.Zero) return null;

            var pcmWaveFormat = *(__PcmNative*)pointer;
            var encoding = pcmWaveFormat.waveFormatTag;

            // Load simple PcmWaveFormat if channels <= 2 and encoding is Pcm, IeeFloat, Wmaudio2, Wmaudio3
            // See http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.xaudio2.waveformatex%28v=vs.85%29.aspx
            if (pcmWaveFormat.channels <= 2 && (encoding == WaveFormatEncoding.Pcm || encoding == WaveFormatEncoding.IeeeFloat || encoding == WaveFormatEncoding.Wmaudio2 || encoding == WaveFormatEncoding.Wmaudio3))
            {
                var waveFormat = new WaveFormat();
                waveFormat.__MarshalFrom(ref pcmWaveFormat);
                return waveFormat;
            }

            if (encoding == WaveFormatEncoding.Extensible)
            {
                var waveFormat = new WaveFormatExtensible();
                waveFormat.__MarshalFrom(ref *(WaveFormatExtensible.__Native*)pointer);
                return waveFormat;
            }

            if (encoding == WaveFormatEncoding.Adpcm)
            {
                var waveFormat = new WaveFormatAdpcm();
                waveFormat.__MarshalFrom(ref *(WaveFormatAdpcm.__Native*)pointer);
                return waveFormat;
            }

            throw new InvalidOperationException(string.Format("Unsupported WaveFormat [{0}]", encoding));
        }
Ejemplo n.º 4
0
 public static unsafe WaveFormat MarshalFrom(IntPtr pointer)
 {
     if (pointer == IntPtr.Zero)
     return (WaveFormat) null;
       WaveFormat.__PcmNative @ref = *(WaveFormat.__PcmNative*) (void*) pointer;
       WaveFormatEncoding waveFormatEncoding = @ref.waveFormatTag;
       if ((int) @ref.channels <= 2 && (waveFormatEncoding == WaveFormatEncoding.Pcm || waveFormatEncoding == WaveFormatEncoding.IeeeFloat || (waveFormatEncoding == WaveFormatEncoding.Wmaudio2 || waveFormatEncoding == WaveFormatEncoding.Wmaudio3)))
       {
     WaveFormat waveFormat = new WaveFormat();
     waveFormat.__MarshalFrom(ref @ref);
     return waveFormat;
       }
       else if (waveFormatEncoding == WaveFormatEncoding.Extensible)
       {
     WaveFormatExtensible formatExtensible = new WaveFormatExtensible();
     formatExtensible.__MarshalFrom(ref *(WaveFormatExtensible.__Native*) (void*) pointer);
     return (WaveFormat) formatExtensible;
       }
       else
       {
     if (waveFormatEncoding != WaveFormatEncoding.Adpcm)
       throw new InvalidOperationException(string.Format("Unsupported WaveFormat [{0}]", (object) waveFormatEncoding));
     WaveFormatAdpcm waveFormatAdpcm = new WaveFormatAdpcm();
     waveFormatAdpcm.__MarshalFrom(ref *(WaveFormatAdpcm.__Native*) (void*) pointer);
     return (WaveFormat) waveFormatAdpcm;
       }
 }