Beispiel #1
0
        /// <summary>Creates a new in-memory wave loaded from an existing wave audio stream.</summary>
        /// <param name="source">Stream of WAV formatted audio data to load.</param>
        /// <returns>In-memory representation of wave file.</returns>
        public static WaveFile Load(Stream source)
        {
            RiffChunk riffChunk;
            RiffHeaderChunk waveHeader = null;
            WaveFormatChunk waveFormat = null;
            WaveDataChunk waveData = null;

            while (waveData == null)
            {
                riffChunk = RiffChunk.ReadNext(source);

                switch (riffChunk.TypeID)
                {
                    case RiffHeaderChunk.RiffTypeID:
                        waveHeader = new RiffHeaderChunk(riffChunk, source, "WAVE");
                        break;
                    case WaveFormatChunk.RiffTypeID:
                        if (waveHeader == null)
                            throw new InvalidDataException("WAVE format section encountered before RIFF header, wave file corrupted.");

                        waveFormat = new WaveFormatChunk(riffChunk, source);
                        break;
                    case WaveDataChunk.RiffTypeID:
                        if (waveFormat == null)
                            throw new InvalidDataException("WAVE data section encountered before format section, wave file corrupted.");

                        waveData = new WaveDataChunk(riffChunk, source, waveFormat);
                        break;
                    default:
                        // Skip unidentified section
                        source.Seek(riffChunk.ChunkSize, SeekOrigin.Current);
                        break;
                }
            }

            return new WaveFile(waveHeader, waveFormat, waveData);
        }
Beispiel #2
0
 public WaveFile(int sampleRate, short bitsPerSample, short channels, ushort audioFormat)
 {
     m_waveHeader = new RiffHeaderChunk("WAVE");
     m_waveFormat = new WaveFormatChunk(sampleRate, bitsPerSample, channels, audioFormat);
     m_waveData = new WaveDataChunk(m_waveFormat);
 }
Beispiel #3
0
 public WaveFile(RiffHeaderChunk waveHeader, WaveFormatChunk waveFormat, WaveDataChunk waveData)
 {
     m_waveHeader = waveHeader;
     m_waveFormat = waveFormat;
     m_waveData = waveData;
 }
Beispiel #4
0
 /// <summary>Creates a new empty in-memory wave file using standard CD quality settings</summary>
 public WaveFile()
 {
     m_waveHeader = new RiffHeaderChunk("WAVE");
     m_waveFormat = new WaveFormatChunk(44100, 16, 2, 0x1);
     m_waveData = new WaveDataChunk(m_waveFormat);
 }