示例#1
0
 public static bool Equals(WAVEFORMATEX x, WAVEFORMATEX y)
 {
     return
     x.wFormatTag == y.wFormatTag &&
     x.nChannels == y.nChannels &&
     x.nSamplesPerSec == y.nSamplesPerSec &&
     x.nAvgBytesPerSec == y.nAvgBytesPerSec &&
     x.nBlockAlign == y.nBlockAlign &&
     x.wBitsPerSample == y.wBitsPerSample;
 }
示例#2
0
        public static WAVEFORMATEX ReadFrom(Stream stream)
        {
            var fmt = new WAVEFORMATEX();
              var reader = new BinaryReader(stream);

              fmt.wFormatTag = (WAVE_FORMAT_TAG)reader.ReadUInt16();
              fmt.nChannels = reader.ReadUInt16();
              fmt.nSamplesPerSec = reader.ReadUInt32();
              fmt.nAvgBytesPerSec = reader.ReadUInt32();
              fmt.nBlockAlign = reader.ReadUInt16();
              fmt.wBitsPerSample = reader.ReadUInt16();

              if (18 <= stream.Length)
            fmt.cbSize = reader.ReadUInt16();

              return fmt;
        }
示例#3
0
        public static WAVEFORMATEX CreateLinearPcmFormat(long samplesPerSec, int bitsPerSample, int channles)
        {
            if (samplesPerSec <= 0)
            throw new ArgumentOutOfRangeException("samplesPerSec", samplesPerSec, "must be non-zero positive number");
              if (bitsPerSample <= 0)
            throw new ArgumentOutOfRangeException("bitsPerSample", bitsPerSample, "must be non-zero positive number");
              if ((bitsPerSample & 0x7) != 0x0)
            throw new ArgumentOutOfRangeException("bitsPerSample", bitsPerSample, "must be number of n * 8");
              if (channles <= 0)
            throw new ArgumentOutOfRangeException("channles", channles, "must be non-zero positive number");

              var format = new WAVEFORMATEX();

              format.wFormatTag = WAVE_FORMAT_TAG.WAVE_FORMAT_PCM;
              format.nChannels = (ushort)channles;
              format.nSamplesPerSec = (uint)samplesPerSec;
              format.wBitsPerSample = (ushort)bitsPerSample;
              format.nBlockAlign = (ushort)((bitsPerSample * channles) >> 3);
              format.nAvgBytesPerSec = format.nBlockAlign * format.nSamplesPerSec;
              format.cbSize = 0;

              return format;
        }