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>
)
{ strpath=args[
]
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_F
RAM_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>=
)
{
byte[] bInfo=new byte[
];
fs
Read(bInfo
);
System
Text
Encoding
Default
GetString(bInfo
);
if(System
Text
Encoding
Default
GetString(bInfo
)==
RIFF
&&System
Text
Encoding
Default
GetString(bInfo
)==
WAVE
&&System
Text
Encoding
Default
GetString(bInfo
)==
fmt
)
{
wavInfo
groupid = System
Text
Encoding
Default
GetString(bInfo
);
System
BitConverter
ToInt
(bInfo
);
wavInfo
filesize = System
BitConverter
ToInt
(bInfo
);
//wavInfo
filesize = Convert
ToInt
(System
Text
Encoding
Default
GetString(bInfo
));
wavInfo
rifftype = System
Text
Encoding
Default
GetString(bInfo
);
wavInfo
chunkid = System
Text
Encoding
Default
GetString(bInfo
);
wavInfo
chunksize = System
BitConverter
ToInt
(bInfo
);
wavInfo
wformattag = System
BitConverter
ToInt
(bInfo
);
wavInfo
wchannels = System
BitConverter
ToUInt
(bInfo
);
wavInfo
dwsamplespersec = System
BitConverter
ToUInt
(bInfo
);
wavInfo
dwavgbytespersec = System
BitConverter
ToUInt
(bInfo
);
wavInfo
wblockalign = System
BitConverter
ToUInt
(bInfo
);
wavInfo
wbitspersample = System
BitConverter
ToUInt
(bInfo
);
wavInfo
datachunkid = System
Text
Encoding
Default
GetString(bInfo
);
wavInfo
datasize = System
BitConverter
ToInt
(bInfo
);
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);
}
}
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/11870.html