用户操作
[即时聊天] [发私信] [加为好友]
吴晓东ID:shooper
1146次访问,排名2万外好友0人,关注者0
shooper的文章
原创 1 篇
翻译 0 篇
转载 0 篇
评论 1 篇
最近评论
hellobaobao:不错的文章,到现在才发现呵呵!
文章分类
收藏
    相册
    Oracle专家
    biti_rainy
    eygle's Oracle Blog
    Fenng 的 BLOG
    Kamus' Oracle World(RSS)
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 C#获取WAVE文件文件头信息收藏

     | 

    C#获取WAVE文件文件头信息

     

    前些日子在论坛里问了,没人回答,今天有空自己写了一下

    文件格式依据网站

    http://www.moon-soft.com/program/FORMAT/

     

    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");

                    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_PCMWAVE_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();

                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);

                        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);

                        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);

     

                    }

                }

            }

        }

    }

     

    发表于 @ 2005年01月17日 18:35:00|评论(loading...)|编辑

     | 

    评论

    #hellobaobao 发表于2007-09-28 09:38:40  IP: 218.5.2.*
    不错的文章,到现在才发现呵呵!
    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © shooper