コード例 #1
0
ファイル: WaveFile.cs プロジェクト: rmc00/gsf
 public WaveFile(RiffHeaderChunk waveHeader, WaveFormatChunk waveFormat, WaveDataChunk waveData, ListInfoChunk listInfo = null)
 {
     m_waveHeader = waveHeader;
     m_waveFormat = waveFormat;
     m_waveData = waveData;
     m_listInfo = listInfo;
 }
コード例 #2
0
ファイル: WaveFile.cs プロジェクト: rmc00/gsf
        /// <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>
        /// <param name="loadData">Determines if wave data should be loaded into memory.</param>
        /// <returns>In-memory representation of wave file.</returns>
        public static WaveFile Load(Stream source, bool loadData = true)
        {
            RiffChunk riffChunk;
            RiffHeaderChunk waveHeader = null;
            WaveFormatChunk waveFormat = null;
            WaveDataChunk waveData = null;
            ListInfoChunk listInfo = null;

            while (source.Position < source.Length)
            {
                riffChunk = RiffChunk.ReadNext(source);

                switch (riffChunk.TypeID)
                {
                    case RiffHeaderChunk.RiffTypeID:
                        waveHeader = new RiffHeaderChunk(riffChunk, source, "WAVE");
                        break;
                    case WaveFormatChunk.RiffTypeID:
                        if ((object)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 ((object)waveFormat == null)
                            throw new InvalidDataException("WAVE data section encountered before format section, wave file corrupted");

                        if (loadData)
                        {
                            waveData = new WaveDataChunk(riffChunk, source, waveFormat);
                        }
                        else
                        {
                            source.Seek(riffChunk.ChunkSize, SeekOrigin.Current);
                            waveData = new WaveDataChunk(waveFormat);
                            waveData.ChunkSize = riffChunk.ChunkSize;
                        }
                        break;
                    case ListInfoChunk.RiffTypeID:
                        listInfo = new ListInfoChunk(riffChunk, source);
                        break;
                    default:
                        // Skip unidentified section
                        source.Seek(riffChunk.ChunkSize, SeekOrigin.Current);
                        break;
                }
            }

            return new WaveFile(waveHeader, waveFormat, waveData, listInfo);
        }