国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

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

2024-07-21 02:17:59
字體:
供稿:網(wǎng)友

c#獲取wave文件文件頭信息



前些日子在論壇里問了,沒人回答,今天有空自己寫了一下

文件格式依據(jù)網(wǎng)站

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 [email protected]"c:/documents and settings/administrator/桌面/trojan/懷念戰(zhàn)友.wav";//[email protected]"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_pcm,wave_f0ram_adpcm等等。

public ushort wchannels; //記錄聲音的頻道數(shù)。

public ulong dwsamplespersec;//記錄每秒取樣數(shù)。

public ulong dwavgbytespersec;//記錄每秒的數(shù)據(jù)量。

public ushort wblockalign;//記錄區(qū)塊的對齊單位。

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



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



}

}

}

}

}



發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 建始县| 格尔木市| 东丽区| 澄江县| 西安市| 鞍山市| 敖汉旗| 垦利县| 芦山县| 宽城| 淅川县| 昭平县| 邵阳市| 江陵县| 郎溪县| 积石山| 盖州市| 张掖市| 富蕴县| 嵊州市| 麦盖提县| 鹤峰县| 镇安县| 长治县| 永安市| 商南县| 清徐县| 卫辉市| 德庆县| 红原县| 中山市| 沂水县| 博兴县| 龙井市| 封开县| 河津市| 双江| 防城港市| 仁布县| 鲁甸县| 申扎县|