public object Read(ContentStream stream, object existingObject) { if (existingObject == null) { BinaryReader binaryReader = new BinaryReader(stream); bool flag = binaryReader.ReadBoolean(); int channelsCount = binaryReader.ReadInt32(); int samplingFrequency = binaryReader.ReadInt32(); int bytesCount = binaryReader.ReadInt32(); if (flag) { MemoryStream memoryStream = new MemoryStream(); using (StreamingSource streamingSource = Ogg.Stream(stream)) { streamingSource.CopyTo(memoryStream); if (memoryStream.Length > int.MaxValue) { throw new InvalidOperationException("Audio data too long."); } memoryStream.Position = 0L; return(new SoundBuffer(memoryStream, (int)memoryStream.Length, channelsCount, samplingFrequency)); } } return(new SoundBuffer(stream, bytesCount, channelsCount, samplingFrequency)); } throw new NotSupportedException(); }
public void Write(string projectDirectory, Stream stream) { using (Stream stream2 = Storage.OpenFile(Storage.CombinePaths(projectDirectory, Sound), OpenFileMode.Read)) { if (Ogg.IsOggStream(stream2)) { StreamingSource streamingSource = Ogg.Stream(stream2); if (OggCompressed) { if (stream2.Length > int.MaxValue) { throw new InvalidOperationException("Audio data too long."); } BinaryWriter binaryWriter = new BinaryWriter(stream); binaryWriter.Write(OggCompressed); binaryWriter.Write(streamingSource.ChannelsCount); binaryWriter.Write(streamingSource.SamplingFrequency); binaryWriter.Write((int)stream2.Length); stream2.Position = 0L; stream2.CopyTo(stream); } else { WritePcm(stream, streamingSource); } } else { if (!Wav.IsWavStream(stream2)) { throw new InvalidOperationException("Unrecognized sound format."); } if (OggCompressed) { throw new InvalidOperationException("Ogg compression not available for WAV format sound files."); } WritePcm(stream, Wav.Stream(stream2)); } } }