我愛我的家園!

          成功在于你是否努力,希望在于你是否相信自己!

           

          C#獲取WAVE文件文件頭信息

          using System;

          using System.IO;

          using System.Text;

          namespace WAV

          {

          /// <summary>

          /// Summary description for Wav.

          /// </summary>

          public class Wav

          {public Wav()

          { //

          // TODO: Add constructor logic here

          //

          }

          [STAThread]

          static void Main(string[] args)

          {

          //

          // TODO: Add code to start application here

          //

          string strpath=@"C:\Documents and Settings\Administrator\桌面\trojan\懷念戰友.wav";//=@"F:\Music";

          if(args.Length>0)

          { strpath=args[0].Trim();

          }

          if(File.Exists(strpath))

          { GetWavInfo(strpath);

          Console.WriteLine("GetWavInfo Successfully!");

          //Console.WriteLine("");

          }

          else

          { Console.Write("Please Enter the write filepath!\n");

          專業的3S站 3s8.cn



          Console.Write("用法: WAV [Full Path Of Your WAV filepath]");

          }

          }

          public struct WavInfo

          { public string groupid;

          public string rifftype;

          public long filesize;

          public string chunkid;

          public long chunksize;

          public short wformattag; //記錄著此聲音的格式代號,例如WAVE_FORMAT_PCM,WAVE_F0RAM_ADPCM等等。

          public ushort wchannels; //記錄聲音的頻道數。

          public ulong dwsamplespersec;//記錄每秒取樣數。

          public ulong dwavgbytespersec;//記錄每秒的數據量。

          public ushort wblockalign;//記錄區塊的對齊單位。

          public ushort wbitspersample;//記錄每個取樣所需的位元數。

          public string datachunkid;

          public long datasize;

          }

          public static void GetWavInfo(string strpath)

          {

          WavInfo wavInfo = new WavInfo();

          FileInfo fi = new FileInfo(strpath);

          System.IO.FileStream fs=fi.OpenRead(); 中國3S吧 3s8.cn

          if(fs.Length>=44)

          {

          byte[] bInfo=new byte[44];

          fs.Read(bInfo,0,44);

          System.Text.Encoding.Default.GetString(bInfo,0,4);

          if(System.Text.Encoding.Default.GetString(bInfo,0,4)=="RIFF"&&System.Text.Encoding.Default.GetString(bInfo,8,4)=="WAVE"&&System.Text.Encoding.Default.GetString(bInfo,12,4)=="fmt ")

          {

          wavInfo.groupid = System.Text.Encoding.Default.GetString(bInfo,0,4);

          System.BitConverter.ToInt32(bInfo,4);

          wavInfo.filesize = System.BitConverter.ToInt32(bInfo,4);

          //wavInfo.filesize = Convert.ToInt64(System.Text.Encoding.Default.GetString(bInfo,4,4));

          wavInfo.rifftype = System.Text.Encoding.Default.GetString(bInfo,8,4);

          wavInfo.chunkid = System.Text.Encoding.Default.GetString(bInfo,12,4);

          wavInfo.chunksize = System.BitConverter.ToInt32(bInfo,16);

          wavInfo.wformattag = System.BitConverter.ToInt16(bInfo,20);

          專業的3S站 3s8.cn



          wavInfo.wchannels = System.BitConverter.ToUInt16(bInfo,22);

          wavInfo.dwsamplespersec = System.BitConverter.ToUInt32(bInfo,24);

          wavInfo.dwavgbytespersec = System.BitConverter.ToUInt32(bInfo,28);

          wavInfo.wblockalign = System.BitConverter.ToUInt16(bInfo,32);

          wavInfo.wbitspersample = System.BitConverter.ToUInt16(bInfo,34);

          wavInfo.datachunkid = System.Text.Encoding.Default.GetString(bInfo,36,4);

          wavInfo.datasize = System.BitConverter.ToInt32(bInfo,40);

          System.Console.WriteLine("groupid:"+wavInfo.groupid);

          System.Console.WriteLine("filesize:"+wavInfo.filesize);

          System.Console.WriteLine("rifftype:"+wavInfo.rifftype);

          System.Console.WriteLine("chunkid:"+wavInfo.chunkid);

          System.Console.WriteLine("chunksize:"+wavInfo.chunksize);

          System.Console.WriteLine("wformattag:"+wavInfo.wformattag);

          System.Console.WriteLine("wchannels:"+wavInfo.wchannels);
          中國3S吧 3s8.cn


          System.Console.WriteLine("dwsamplespersec:"+wavInfo.dwsamplespersec);

          System.Console.WriteLine("dwavgbytespersec:"+wavInfo.dwavgbytespersec);

          System.Console.WriteLine("wblockalign:"+wavInfo.wblockalign);

          System.Console.WriteLine("wbitspersample:"+wavInfo.wbitspersample);

          System.Console.WriteLine("datachunkid:"+wavInfo.datachunkid);

          System.Console.WriteLine("datasize:"+wavInfo.datasize);

          }

          }

          }

          }

          }

          posted on 2008-09-04 15:00 死神 閱讀(345) 評論(0)  編輯  收藏 所屬分類: 音頻開發


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          統計

          公告

          歡迎大家來到我的個人世界!

          常用鏈接

          留言簿(3)

          隨筆分類(5)

          隨筆檔案(9)

          文章分類(37)

          文章檔案(41)

          相冊

          語音技術

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 田东县| 开化县| 莆田市| 嘉兴市| 会宁县| 大田县| 南京市| 吉林市| 辽源市| 小金县| 海丰县| 五大连池市| 武冈市| 阜阳市| 定襄县| 保靖县| 拉孜县| 沭阳县| 中江县| 望江县| 新平| 景德镇市| 吉林省| 罗山县| 黄冈市| 改则县| 毕节市| 蓬安县| 攀枝花市| 张掖市| 墨脱县| 黔江区| 文山县| 中方县| 上蔡县| 武安市| 石棉县| 上犹县| 忻州市| 隆昌县| 松江区|