Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }