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

首頁 > 編程 > C# > 正文

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

2023-05-14 16:26:30
字體:
來源:轉載
供稿:網友

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=@"D:/music/jintian.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_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();

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

}

}

}

}

}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大同市| 武城县| 南溪县| 米泉市| 碌曲县| 乌拉特后旗| 仁布县| 织金县| 南溪县| 陇西县| 旺苍县| 卫辉市| 蒲江县| 元江| 通许县| 宜君县| 巴彦县| 绵阳市| 筠连县| 新巴尔虎右旗| 普兰店市| 潮安县| 桑植县| 瑞金市| 盐边县| 淮南市| 鹿泉市| 冷水江市| 云浮市| 荔波县| 眉山市| 娄底市| 剑川县| 沽源县| 南昌市| 苍南县| 通州区| 道真| 宝丰县| 安仁县| 衡阳市|