public FMT_CHUNK(WaveAudioFormat audioFormat) { byte[] numChannelsEncoded = BitConverter.IsLittleEndian ? new byte[2] { (byte)audioFormat.ChannelCount, 0x00 } : new byte[2] { 0x00, (byte)audioFormat.ChannelCount }; this.lNumChannels = Endian(numChannelsEncoded, Endianness.LITTLE); this.lSampleRate = Endian(BitConverter.GetBytes(audioFormat.SampleRate), Endianness.LITTLE); this.lBitsPerSample = BitConverter.IsLittleEndian ? new byte[2] { (byte)audioFormat.BitsPerSample, 0x00 } : new byte[2] { 0x00, (byte)audioFormat.BitsPerSample }; int byteRate = audioFormat.SampleRate * audioFormat.ChannelCount * (audioFormat.BitsPerSample / 8); this.lByteRate = Endian(BitConverter.GetBytes(byteRate), Endianness.LITTLE); short blockAlign = (short)(audioFormat.ChannelCount * (audioFormat.BitsPerSample / 8)); this.lBlockAlign = new byte[] { (byte)blockAlign, (byte)(blockAlign >> 8) }; }
public WaveStream(List <WaveSample> fullAudioStream) { WaveAudioFormat audioFormat = fullAudioStream?[0]?.SampleFormat; byte[] audioData = WaveGenerator.ToByteArray(fullAudioStream.ToArray()); this.riff = new WaveFileFormat.RIFF_CHUNK(); this.fmt = new WaveFileFormat.FMT_CHUNK(audioFormat); this.data = new WaveFileFormat.DATA_CHUNK(audioData); this.riff.SetChunkSize(4 + (8 + this.fmt.GetChunkSize()) + (8 + this.data.GetChunkSize())); }