public void Open() { if (this.opened) { throw new InvalidOperationException(); } if (this.inputFormat == null) { throw new InvalidOperationException("Input format is not specified."); } if (this.outputFormat == null) { throw new InvalidOperationException("Output format is not specified."); } this.pwfxSource = this.inputFormat.ToPtr(); this.pwfxDest = this.outputFormat.ToPtr(); this.outputFormat = new SoundFormat(this.pwfxDest); int mmr = AcmInterop.acmStreamOpen(out this.pStream, IntPtr.Zero, this.pwfxSource, this.pwfxDest, IntPtr.Zero, IntPtr.Zero, UIntPtr.Zero, 0); if (mmr != 0) { throw new SoundException("acmStreamOpen", mmr); } int cbSrcLength = (int)((this.bufferLength / 1000.0) * this.inputFormat.AverageBytesPerSecond); this.header = new AcmInterop.ACMSTREAMHEADER(); this.header.cbStruct = Marshal.SizeOf(this.header); this.header.cbSrcLength = cbSrcLength; int suggestedDstLength; mmr = AcmInterop.acmStreamSize(this.pStream, cbSrcLength, out suggestedDstLength, AcmInterop.ACM_STREAMSIZEF_SOURCE); try { this.header.cbDstLength = suggestedDstLength; this.header.pbDst = Marshal.AllocHGlobal(suggestedDstLength); this.header.pbSrc = Marshal.AllocHGlobal(cbSrcLength); this.headerGCHandle = GCHandle.Alloc(this.header, GCHandleType.Pinned); mmr = AcmInterop.acmStreamPrepareHeader(this.pStream, ref this.header, 0); if (mmr != 0) { throw new SoundException("acmStreamPrepareHeader", mmr); } this.isStart = true; this.opened = true; } finally { if (!this.opened) { this.Close(); } } }