/// <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); } WaveFormat.__PcmNative _PcmNative = *(WaveFormat.__PcmNative *)((void *)pointer); WAVE_FORMAT waveFormatEncoding = _PcmNative.waveFormatTag; if (_PcmNative.channels <= 2 && (waveFormatEncoding == WAVE_FORMAT.PCM || waveFormatEncoding == WAVE_FORMAT.IEEE_FLOAT || waveFormatEncoding == WAVE_FORMAT.WMAUDIO2 || waveFormatEncoding == WAVE_FORMAT.WMAUDIO3)) { WaveFormat waveFormat = new WaveFormat(); waveFormat.__MarshalFrom(ref _PcmNative); return(waveFormat); } if (waveFormatEncoding == WAVE_FORMAT.EXTENSIBLE) { WaveFormatExtensible waveFormatExtensible = new WaveFormatExtensible(); waveFormatExtensible.__MarshalFrom(ref *(WaveFormatExtensible.__Native *)((void *)pointer)); return(waveFormatExtensible); } if (waveFormatEncoding == WAVE_FORMAT.ADPCM) { WaveFormatAdpcm waveFormatAdpcm = new WaveFormatAdpcm(); waveFormatAdpcm.__MarshalFrom(ref *(WaveFormatAdpcm.__Native *)((void *)pointer)); return(waveFormatAdpcm); } throw new InvalidOperationException(string.Format("Unsupported WaveFormat [{0}]", new object[] { waveFormatEncoding })); }
internal void __MarshalTo(ref WaveFormat.__PcmNative @ref) { @ref.waveFormatTag = this.waveFormatTag; @ref.channels = this.channels; @ref.sampleRate = this.sampleRate; @ref.averageBytesPerSecond = this.averageBytesPerSecond; @ref.blockAlign = this.blockAlign; @ref.bitsPerSample = this.bitsPerSample; }
internal void __MarshalFrom(ref WaveFormat.__PcmNative @ref) { this.waveFormatTag = @ref.waveFormatTag; this.channels = @ref.channels; this.sampleRate = @ref.sampleRate; this.averageBytesPerSecond = @ref.averageBytesPerSecond; this.blockAlign = @ref.blockAlign; this.bitsPerSample = @ref.bitsPerSample; this.extraSize = 0; }
internal void __MarshalFree(ref WaveFormat.__PcmNative @ref) { @ref.__MarshalFree(); }