Wave ファイルのフォーマットヘッダ。
Ejemplo n.º 1
0
        /// <summary>
        /// Wave ファイルを開く。
        /// </summary>
        /// <param name="reader">Wave ファイルを格納したストリーム</param>
        public void Open(BinaryReader reader)
        {
            if (this.reader != null)
            {
                this.reader.Close();
            }

            this.reader = reader;
            byte[] buf;

            buf = this.reader.ReadBytes(4);
            if (buf[0] != 'R' || buf[1] != 'I' || buf[2] != 'F' || buf[3] != 'F')
            {
                throw new WaveException("このファイルはRIFF形式ではありません。");
            }

            this.reader.ReadBytes(4);             //ファイルサイズ読み飛ばし。

            buf = this.reader.ReadBytes(4);
            if (buf[0] != 'W' || buf[1] != 'A' || buf[2] != 'V' || buf[3] != 'E')
            {
                throw new WaveException("このファイルはwave形式ではありません。");
            }

            buf = this.reader.ReadBytes(4);
            if (buf[0] != 'f' || buf[1] != 'm' || buf[2] != 't' || buf[3] != ' ')
            {
                throw new WaveException("fmtタグが見つかりませんでした。");
            }

            int headerLength = this.reader.ReadInt32();

            if (headerLength < 16)
            {
                throw new WaveException("ヘッダ長が短すぎます。");
            }

            this.header = new FormatHeader(this.reader);
            if (header.id != 0x0001)
            {
                throw new WaveException("対応していないフォーマットです。");
            }

            if (headerLength != 16)
            {
                this.reader.ReadBytes(headerLength - 16);                 // ヘッダーの残りの部分読み飛ばし。
            }

            buf = this.reader.ReadBytes(4);
            if (buf[0] != 'd' || buf[1] != 'a' || buf[2] != 't' || buf[3] != 'a')
            {
                throw new WaveException("dataタグが見つかりませんでした。");
            }

            this.dataLength = (uint)(this.reader.ReadUInt32() / this.header.blockSize);
        }        //Open
Ejemplo n.º 2
0
 /// <summary>
 /// Wave ファイルを開く。
 /// </summary>
 /// <param name="filename">Wave ファイル名</param>
 public void Open(string filename, FormatHeader header)
 {
     Open(new BinaryWriter(File.OpenWrite(filename)), header);
 }
Ejemplo n.º 3
0
 public WaveWriter(BinaryWriter writer, FormatHeader header)
 {
     this.Open(writer, header);
 }
Ejemplo n.º 4
0
 public WaveWriter(string filename, FormatHeader header)
 {
     this.Open(filename, header);
 }
Ejemplo n.º 5
0
		/// <summary>
		/// Wave ファイルを開く。
		/// </summary>
		/// <param name="reader">Wave ファイルを格納したストリーム</param>
		public void Open(BinaryWriter writer, FormatHeader header)
		{
			if(this.writer != null)
			{
				this.writer.Close();
			}

			this.writer = writer;
			this.header = header;
			byte[] buf;

			buf = System.Text.Encoding.ASCII.GetBytes("RIFF");
			this.writer.Write(buf);

			this.writer.Write((uint)0); //データ長(仮の値を入れておく)

			buf = System.Text.Encoding.ASCII.GetBytes("WAVE");
			this.writer.Write(buf);

			buf = System.Text.Encoding.ASCII.GetBytes("fmt ");
			this.writer.Write(buf);

			this.writer.Write((uint)16);
			this.header.WriteToStream(writer);

			buf = System.Text.Encoding.ASCII.GetBytes("data");
			this.writer.Write(buf);

			this.writer.Write((uint)0); //データ長(仮の値を入れておく)
		}//Open
Ejemplo n.º 6
0
		public WaveWriter(BinaryWriter writer, FormatHeader header)
		{
			this.Open(writer, header);
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Wave ファイルを開く。
		/// </summary>
		/// <param name="filename">Wave ファイル名</param>
		public void Open(string filename, FormatHeader header)
		{
			Open(new BinaryWriter(File.OpenWrite(filename)), header);
		}
Ejemplo n.º 8
0
		public WaveWriter(string filename, FormatHeader header)
		{
			this.Open(filename, header);
		}
Ejemplo n.º 9
0
		/// <summary>
		/// Wave ファイルを開く。
		/// </summary>
		/// <param name="reader">Wave ファイルを格納したストリーム</param>
		public void Open(BinaryReader reader)
		{
			if(this.reader != null)
			{
				this.reader.Close();
			}

			this.reader = reader;
			byte[] buf;

			buf= this.reader.ReadBytes(4);
			if(buf[0] != 'R' || buf[1] != 'I' || buf[2] != 'F' || buf[3] != 'F')
			{
				throw new WaveException("このファイルはRIFF形式ではありません。");
			}

			this.reader.ReadBytes(4); //ファイルサイズ読み飛ばし。

			buf= this.reader.ReadBytes(4);
			if(buf[0] != 'W' || buf[1] != 'A' || buf[2] != 'V' || buf[3] != 'E')
			{
				throw new WaveException("このファイルはwave形式ではありません。");
			}

			buf= this.reader.ReadBytes(4);
			if(buf[0] != 'f' || buf[1] != 'm' || buf[2] != 't' || buf[3] != ' ')
			{
				throw new WaveException("fmtタグが見つかりませんでした。");
			}

			int headerLength = this.reader.ReadInt32();
			if(headerLength < 16)
			{
				throw new WaveException("ヘッダ長が短すぎます。");
			}

			this.header = new FormatHeader(this.reader);
			if(header.id != 0x0001)
			{
				throw new WaveException("対応していないフォーマットです。");
			}

			if(headerLength != 16)
			{
				this.reader.ReadBytes(headerLength - 16); // ヘッダーの残りの部分読み飛ばし。
			}

			buf= this.reader.ReadBytes(4);
			if(buf[0] != 'd' || buf[1] != 'a' || buf[2] != 't' || buf[3] != 'a')
			{
				throw new WaveException("dataタグが見つかりませんでした。");
			}

			this.dataLength = (uint)(this.reader.ReadUInt32() / this.header.blockSize);
		}//Open
Ejemplo n.º 10
0
		public WaveTime(FormatHeader header, double[] l, double[] r) : base(header)
		{
			this.l = l;
			this.r = r;
		}
Ejemplo n.º 11
0
		public WaveData(FormatHeader header)
		{
			this.header = header;
		}
Ejemplo n.º 12
0
		public WaveFrequency(FormatHeader header, Spectrum l, Spectrum r) : base(header)
		{
			this.l = l;
			this.r = r;
		}