/// <summary> /// 使用采样点数据初始化 <see cref="WaveSample"/> 结构的新实例。 /// </summary> /// <param name="data">采样点数据的字节数组。</param> /// <param name="format">采样点的波形声音格式。</param> /// <param name="channels">采样点的声道数量。</param> /// <param name="bitDepth">采样点的采样位深度。</param> private WaveSample(byte[] data, WaveFormat format, WaveChannels channels, WaveBitDepth bitDepth) { this.Data = data; this.Format = format; this.Channels = channels; this.BitDepth = bitDepth; }
/// <summary> /// 以要写入的流和波形声音参数初始化 <see cref="WaveStreamWriter"/> 类的新实例。 /// </summary> /// <param name="stream">要写入波形声音的流。</param> /// <param name="format">波形声音的格式。</param> /// <param name="channels">波形声音的声道数量。</param> /// <param name="sampleRate">波形声音的采样率。</param> /// <param name="bitDepth">波形声音的采样位深度。</param> /// <exception cref="ArgumentNullException"> /// <paramref name="stream"/> 为 <see langword="null"/>。</exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="format"/> 为 <see cref="WaveFormat.IEEEFloat"/>, /// 但 <paramref name="bitDepth"/> 不为 <see cref="WaveBitDepth.Bit32"/>。</exception> public WaveStreamWriter(Stream stream, WaveFormat format = WaveFormat.PCM, WaveChannels channels = WaveChannels.Stereo, WaveSampleRate sampleRate = WaveSampleRate.Hz44100, WaveBitDepth bitDepth = WaveBitDepth.Bit16) { if (stream is null) { throw new ArgumentNullException(nameof(stream)); } if ((format == WaveFormat.IEEEFloat) && (bitDepth != WaveBitDepth.Bit32)) { throw new ArgumentOutOfRangeException(nameof(bitDepth)); } this.Stream = stream; this.Format = format; this.Channels = channels; this.SampleRate = sampleRate; this.BitDepth = bitDepth; this.InitializeStream(); }