熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

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

2013-11-13 09:53:24  來源: .NET編程 

using System;
using SystemIO;
using SystemText;
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(argsLength>)
{ strpath=args[]Trim();
}
if(FileExists(strpath))
{   GetWavInfo(strpath);
ConsoleWriteLine(GetWavInfo Successfully!);
//ConsoleWriteLine();
}
else
{   ConsoleWrite(Please Enter the write filepath!\n);
ConsoleWrite(用法: 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_FRAM_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);
SystemIOFileStream fs=fiOpenRead();
if(fsLength>=)
{
byte[] bInfo=new byte[];
fsRead(bInfo);
SystemTextEncodingDefaultGetString(bInfo);
if(SystemTextEncodingDefaultGetString(bInfo)==RIFF&&SystemTextEncodingDefaultGetString(bInfo)==WAVE&&SystemTextEncodingDefaultGetString(bInfo)==fmt )
{
wavInfogroupid = SystemTextEncodingDefaultGetString(bInfo);
SystemBitConverterToInt(bInfo);
wavInfofilesize = SystemBitConverterToInt(bInfo);
//wavInfofilesize = ConvertToInt(SystemTextEncodingDefaultGetString(bInfo));
wavInforifftype = SystemTextEncodingDefaultGetString(bInfo);
wavInfochunkid = SystemTextEncodingDefaultGetString(bInfo);
wavInfochunksize = SystemBitConverterToInt(bInfo);
wavInfowformattag = SystemBitConverterToInt(bInfo);
wavInfowchannels = SystemBitConverterToUInt(bInfo);
wavInfodwsamplespersec = SystemBitConverterToUInt(bInfo);
wavInfodwavgbytespersec = SystemBitConverterToUInt(bInfo);
wavInfowblockalign = SystemBitConverterToUInt(bInfo);
wavInfowbitspersample = SystemBitConverterToUInt(bInfo);
wavInfodatachunkid = SystemTextEncodingDefaultGetString(bInfo);
wavInfodatasize = SystemBitConverterToInt(bInfo);
SystemConsoleWriteLine(groupid:+wavInfogroupid);
SystemConsoleWriteLine(filesize:+wavInfofilesize);
SystemConsoleWriteLine(rifftype:+wavInforifftype);
SystemConsoleWriteLine(chunkid:+wavInfochunkid);
SystemConsoleWriteLine(chunksize:+wavInfochunksize);
SystemConsoleWriteLine(wformattag:+wavInfowformattag);
SystemConsoleWriteLine(wchannels:+wavInfowchannels);
SystemConsoleWriteLine(dwsamplespersec:+wavInfodwsamplespersec);
SystemConsoleWriteLine(dwavgbytespersec:+wavInfodwavgbytespersec);
SystemConsoleWriteLine(wblockalign:+wavInfowblockalign);
SystemConsoleWriteLine(wbitspersample:+wavInfowbitspersample);
SystemConsoleWriteLine(datachunkid:+wavInfodatachunkid);
SystemConsoleWriteLine(datasize:+wavInfodatasize);
}
}
}
}
}

From:http://tw.wingwit.com/Article/program/net/201311/11870.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.