/// <summary>Returns all data needed to copy the stream</summary> /// <remarks>Do not forget to call Marshal.FreeHGlobal and release the raw data pointer</remarks> /// <param name="streamInfo">Receives the header information</param> /// <param name="format">Receives the format</param> /// <param name="streamLength">Receives the length of the stream</param> /// <returns>Pointer to the wave data</returns> public IntPtr GetStreamData(ref Avi.AVISTREAMINFO streamInfo, ref Avi.PCMWAVEFORMAT format, ref int streamLength) { streamInfo = this.GetStreamInfo(); format = this.GetFormat(); //length in bytes = length in samples * length of a sample streamLength = Avi.AVIStreamLength(this.aviStream.ToInt32()) * streamInfo.dwSampleSize; IntPtr waveData = Marshal.AllocHGlobal(streamLength); int result = Avi.AVIStreamRead(this.aviStream, 0, streamLength, waveData, streamLength, 0, 0); if (result != 0) { throw new Exception("Exception in AVIStreamRead: " + result.ToString()); } return(waveData); }