protected virtual bool InitializeForWriting(Stream underlyingStream, WaveFormat2 wfIn, WaveFormat2 wfOut, bool fAppend) { if (fAppend) { long position = underlyingStream.Position; underlyingStream.Seek(0, SeekOrigin.Begin); LoadHeader(); _ckData.BeginWrite(); _ckData.Seek(position - _ckData.DataStart, SeekOrigin.Begin); } else { _baseStream.Position = 0; _mmc = new RiffChunk(underlyingStream); (_mmc as RiffChunk).BeginWrite(); _ckFmt = new FmtChunk(underlyingStream, wfOut); _mmc.AppendChunk(_ckFmt); _ckFmt.BeginWrite(); _ckFmt.Write(_ckFmt.WaveFormat.GetBytes()); _fmt = wfOut; _ckData = new DataChunk(underlyingStream); _mmc.AppendChunk(_ckData); _ckData.BeginWrite(); } return(true); }
public override MMChunk CreateSubChunk(FourCC fourCC, Stream st) { MMChunk ck = base.CreateSubChunk(fourCC, st); long size = 0; foreach (MMChunk cck in m_chunkList) { if (cck != ck) { size += cck.Size; } } ck.Start = m_posStart + 4 + size; return(ck); }
protected virtual void LoadHeader() { _mmc = MMChunk.FromStream(_baseStream); _ckFmt = _mmc.FindChunk(FourCC.Fmt) as FmtChunk; if (_ckFmt != null) { _fmt = _ckFmt.WaveFormat; } _ckData = _mmc.FindChunk(FourCC.Data) as DataChunk; if (_ckData != null) { _posData = _ckData.DataStart; } _baseStream.Seek(_posData, SeekOrigin.Begin); }
public override void LoadFromStream(Stream st) { byte[] data = new byte[4]; m_posStart = st.Position - 4; st.Read(data, 0, 4); m_nSize = BitConverter.ToInt32(data, 0); st.Read(data, 0, 4); if (Encoding.ASCII.GetString(data, 0, 4) != "WAVE") { throw new InvalidOperationException("Must have WAVE format"); } while (st.Position - m_posStart != m_nSize + 8) { MMChunk ck = MMChunk.FromStream(st); if (ck == null) { break; } m_chunkList.Add(ck); } }
public virtual void AppendChunk(MMChunk ck) { ck.m_fourCC.Write(_stm); m_chunkList.Add(ck); }