public IntPtr ToPtr(int totalBytes) { IntPtr pwfx = Marshal.AllocHGlobal(totalBytes); KernelInterop.ZeroMemory(pwfx, new IntPtr(totalBytes)); MMInterop.WAVEFORMATEX wfx = new MMInterop.WAVEFORMATEX(); wfx.cbSize = this.cbSize; wfx.nAvgBytesPerSec = (uint)this.avgBytesPerSecond; wfx.nBlockAlign = (ushort)this.blockAlign; wfx.nChannels = (ushort)this.channels; wfx.nSamplesPerSec = (uint)this.samplesPerSecond; wfx.wBitsPerSample = (ushort)this.bitsPerSample; wfx.wFormatTag = (ushort)this.tag; Marshal.StructureToPtr(wfx, pwfx, false); return(pwfx); }
public SoundFormat(IntPtr ptr, int totalBytes) { MMInterop.WAVEFORMATEX wfx = (MMInterop.WAVEFORMATEX)Marshal.PtrToStructure(ptr, typeof(MMInterop.WAVEFORMATEX)); this.avgBytesPerSecond = (int)wfx.nAvgBytesPerSec; this.blockAlign = wfx.nBlockAlign; this.channels = wfx.nChannels; this.samplesPerSecond = (int)wfx.nSamplesPerSec; this.bitsPerSample = wfx.wBitsPerSample; this.tag = (SoundFormatTag)wfx.wFormatTag; this.cbSize = wfx.cbSize; int extraBytes = Math.Max(wfx.cbSize, totalBytes - fixedSize); if (extraBytes > 0) { this.extra = new byte[extraBytes]; Marshal.Copy(new IntPtr(ptr.ToInt64() + fixedSize), this.extra, 0, extraBytes); } }
public IntPtr ToPtr() { int extraBytes = this.extra != null ? this.extra.Length : 0; int totalBytes = fixedSize + extraBytes; IntPtr pwfx = Marshal.AllocHGlobal(totalBytes); KernelInterop.ZeroMemory(pwfx, new IntPtr(totalBytes)); MMInterop.WAVEFORMATEX wfx = new MMInterop.WAVEFORMATEX(); wfx.cbSize = this.cbSize; wfx.nAvgBytesPerSec = (uint)this.avgBytesPerSecond; wfx.nBlockAlign = (ushort)this.blockAlign; wfx.nChannels = (ushort)this.channels; wfx.nSamplesPerSec = (uint)this.samplesPerSecond; wfx.wBitsPerSample = (ushort)this.bitsPerSample; wfx.wFormatTag = (ushort)this.tag; Marshal.StructureToPtr(wfx, pwfx, false); if (extraBytes > 0) { Marshal.Copy(this.extra, 0, new IntPtr(pwfx.ToInt64() + fixedSize), extraBytes); } return(pwfx); }
public IntPtr ToPtr(int totalBytes) { IntPtr pwfx = Marshal.AllocHGlobal(totalBytes); KernelInterop.ZeroMemory(pwfx, new IntPtr(totalBytes)); MMInterop.WAVEFORMATEX wfx = new MMInterop.WAVEFORMATEX(); wfx.cbSize = this.cbSize; wfx.nAvgBytesPerSec = (uint)this.avgBytesPerSecond; wfx.nBlockAlign = (ushort)this.blockAlign; wfx.nChannels = (ushort)this.channels; wfx.nSamplesPerSec = (uint)this.samplesPerSecond; wfx.wBitsPerSample = (ushort)this.bitsPerSample; wfx.wFormatTag = (ushort)this.tag; Marshal.StructureToPtr(wfx, pwfx, false); return pwfx; }
public IntPtr ToPtr() { int extraBytes = this.extra != null ? this.extra.Length : 0; int totalBytes = fixedSize + extraBytes; IntPtr pwfx = Marshal.AllocHGlobal(totalBytes); KernelInterop.ZeroMemory(pwfx, new IntPtr(totalBytes)); MMInterop.WAVEFORMATEX wfx = new MMInterop.WAVEFORMATEX(); wfx.cbSize = this.cbSize; wfx.nAvgBytesPerSec = (uint)this.avgBytesPerSecond; wfx.nBlockAlign = (ushort)this.blockAlign; wfx.nChannels = (ushort)this.channels; wfx.nSamplesPerSec = (uint)this.samplesPerSecond; wfx.wBitsPerSample = (ushort)this.bitsPerSample; wfx.wFormatTag = (ushort)this.tag; Marshal.StructureToPtr(wfx, pwfx, false); if (extraBytes > 0) { Marshal.Copy(this.extra, 0, new IntPtr(pwfx.ToInt64() + fixedSize), extraBytes); } return pwfx; }