示例#1
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="path">ファイルのパス</param>
        public RiffReader(string path)
        {
            waveFormat   = new WaveFormatEx();
            streamOffset = streamLength = 0;
            chunks       = new List <Chunk>();

            if (!File.Exists(path))
            {
                throw new IOException("no file");
            }

            try {
                streamFs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                streamBr = new BinaryReader(streamFs);
            } catch (Exception) {               // 乱暴だがこれで問題になる状況はよほどの状況
                Close();
                throw;
            }

            InitializeDisposeFinalizePattern();
        }
示例#2
0
        /// <summary>
        /// RIFF-WAVヘッダーを書き込みます。
        /// </summary>
        /// <param name="waveFormat">出力するWAVEFORMATヘッダー</param>
        /// <returns>書き出しに成功すれば真</returns>
        public bool WriteHeader(WaveFormatEx waveFormat)
        {
            ThrowExceptionIfDisposed();

            try {
                streamBw.Write(new byte[] { (byte)'R', (byte)'I', (byte)'F', (byte)'F' });
                streamBw.Write((uint)0);
                streamBw.Write(new byte[] { (byte)'W', (byte)'A', (byte)'V', (byte)'E', (byte)'f', (byte)'m', (byte)'t', (byte)' ' });
                streamBw.Write((uint)0x10);
                streamBw.Write((ushort)waveFormat.FormatTag);
                streamBw.Write(waveFormat.Channels);
                streamBw.Write((uint)waveFormat.SamplesPerSecond);
                streamBw.Write((uint)waveFormat.AverageBytesPerSecond);
                streamBw.Write((ushort)waveFormat.BlockAlign);
                streamBw.Write((ushort)waveFormat.BitsPerSample);
                streamBw.Write(new byte[] { (byte)'d', (byte)'a', (byte)'t', (byte)'a' });
                streamBw.Write((uint)0);
            } catch (IOException) {
                return(false);
            }
            return(true);
        }