国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 晋宁县| 万源市| 平武县| 衡水市| 登封市| 夏津县| 漳州市| 宁南县| 札达县| 唐海县| 荥阳市| 辽阳市| 宿松县| 巴中市| 磴口县| 沽源县| 米脂县| 武冈市| 嵊泗县| 繁昌县| 南皮县| 肇庆市| 慈利县| 丹棱县| 瓦房店市| 宁蒗| 霍林郭勒市| 铜川市| 依安县| 永泰县| 繁昌县| 台湾省| 昌都县| 红原县| 青阳县| 缙云县| 普陀区| 长乐市| 徐州市| 东城区| 碌曲县|