Esempio n. 1
0
 public AudioFormatEx(WAVEFORMATEX wavFormat)
     : this(
         (WaveFormatType) wavFormat.FormatTag, wavFormat.Channels, wavFormat.BitsPerSample,
         wavFormat.SamplesPerSec)
 {
     //note: WAVEFORMATEX.FormatPCM = 1 and also WaveFormatType.Pcm = 1 that's why the cast is OK  
 }
Esempio n. 2
0
        public static void WriteSilence(Stream outputStream, WAVEFORMATEX audioFormat, double msec)
        {
            if (msec <= 0) return;

            long bytes = audioFormat.BufferSizeFromAudioDuration((long) (msec*10000));
            //expects duration in 100-nanosecond units (hns)

            var b = new BinaryWriter(outputStream);
            for (uint i = 0; i < bytes; i++)
                b.Write((byte) 0);
        }
Esempio n. 3
0
        /// <summary>
        ///     Read the format block from the file and construct the WAVEFORMATEX
        ///     structure
        /// </summary>
        private void ReadFormatBlock()
        {
            try
            {
                Debug.Assert(Chunk.FCC == FourCC.WavFmt, "This is not a WavFmt chunk");
                Debug.Assert(this.waveFormat == null, "The waveformat structure should have been set before");

                // Some .wav files do not include the cbSize field of the WAVEFORMATEX 
                // structure. For uncompressed PCM audio, field is always zero. 
                uint formatSize = 0;
                if (Chunk.Size < MinFormatSize)
                {
                    throw new InvalidOperationException("File is not a WAV file");
                }

                // Allocate a buffer for the WAVEFORMAT structure.
                formatSize = Chunk.Size;

                this.waveFormat = new WAVEFORMATEX();

                // Read the format from the current chunk in the file
                byte[] data = ReadDataFromChunk(formatSize);

                // Copy the read data into our WAVFORMATEX
                this.waveFormat.SetFromByteArray(data);
            }
            catch (Exception)
            {
                this.waveFormat = null;
                throw;
            }
        }