Exemplo 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));
        }
Exemplo 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);
            }
        }
Exemplo n.º 3
0
 internal unsafe void __MarshalFrom(ref WaveFormatAdpcm.__Native @ref)
 {
     base.__MarshalFrom(ref @ref.waveFormat);
       this.SamplesPerBlock = @ref.samplesPerBlock;
       this.Coefficients1 = new short[(int) @ref.numberOfCoefficients];
       this.Coefficients2 = new short[(int) @ref.numberOfCoefficients];
       if ((int) @ref.numberOfCoefficients > 7)
     throw new InvalidOperationException("Unable to read Adpcm format. Too may coefficients (max 7)");
       fixed (short* numPtr = &@ref.coefficients)
       {
     for (int index = 0; index < (int) @ref.numberOfCoefficients; ++index)
     {
       this.Coefficients1[index] = numPtr[index * 2];
       this.Coefficients2[index] = numPtr[index * 2 + 1];
     }
       }
       this.extraSize = (short) (4 + 4 * (int) @ref.numberOfCoefficients);
 }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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;
       }
 }
Exemplo n.º 6
0
 private unsafe void __MarshalTo(ref WaveFormatAdpcm.__Native @ref)
 {
     if (this.Coefficients1.Length > 7)
     throw new InvalidOperationException("Unable to encode Adpcm format. Too may coefficients (max 7)");
       this.extraSize = (short) (4 + 4 * this.Coefficients1.Length);
       base.__MarshalTo(ref @ref.waveFormat);
       @ref.samplesPerBlock = this.SamplesPerBlock;
       @ref.numberOfCoefficients = (ushort) this.Coefficients1.Length;
       fixed (short* numPtr = &@ref.coefficients)
       {
     for (int index = 0; index < (int) @ref.numberOfCoefficients; ++index)
     {
       numPtr[index * 2] = this.Coefficients1[index];
       numPtr[index * 2 + 1] = this.Coefficients2[index];
     }
       }
 }