public AudioData Deserialize(Stream stream) { if (stream is null) { throw new ArgumentNullException(nameof(stream)); } if (!stream.CanSeek) { var mem = new MemoryStream(); stream.CopyTo(mem); stream = mem; } var waveStream = MakeDecodingStream(stream); var format = waveStream.WaveFormat; var sampleRate = format.SampleRate; var bitsPerSample = format.BitsPerSample; var bytesPerSample = (int)Units.Bits.Bytes(bitsPerSample); var channels = format.Channels; var samples = waveStream.Length / bytesPerSample; ValidateFormat(sampleRate, bitsPerSample, channels); var audioFormat = MakeAudioFormat(sampleRate, bitsPerSample, channels); var pcmStream = new PcmBytesToFloatsStream(waveStream, bytesPerSample); return(new AudioData(audioFormat, pcmStream, samples, stream)); }
public AudioData Deserialize(Stream stream) { var waveStream = MakeDecodingStream(stream); var format = waveStream.WaveFormat; var sampleRate = format.SampleRate; var bitsPerSample = format.BitsPerSample; var bytesPerSample = (int)Units.Bits.Bytes(bitsPerSample); var channels = format.Channels; var samples = waveStream.Length / bytesPerSample; ValidateFormat(sampleRate, bitsPerSample, channels); var audioFormat = MakeAudioFormat(sampleRate, bitsPerSample, channels); var pcmStream = new PcmBytesToFloatsStream(waveStream, bytesPerSample); return(new AudioData(audioFormat, pcmStream, samples, stream)); }