C # Get WAVE file file information

xiaoxiao2021-03-06  14

C # Get WAVE file file information

I have asked in the forum, no one answered, today I have time I wrote it.

File format basis

http://www.moon-soft.com/program/format/

Using system;

Using system.io;

Using system.text;

Namespace WAV

{

///

/// Summary Description for WAV.

///

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 / desktop / Trojan / missing comrades. Wav"; // = @ "f: / music";

IF (args.length> 0)

{

StrPath = args [0] .trim ();

}

File.exists (StrPath))

{

GetWavinfo (STRPATH);

Console.writeline ("GetWavinfo SuccessFully!");

//Console.writeline ("");

}

Else

{

Console.write ("please enter the writepath! / N");

Console.Write ("Usage: WAV [Full Path of Your Wav Filepath]);

}

}

Public Struct WAVINFO

{

Public String GroupId;

Public String RiffType;

Public long filesis;

Public string chunkid;

Public long chunksize;

Public short wformattag; // record the format code of this sound, such as Wave_Format_PCM, Wave_F0RAM_ADPCM, and more.

Public ushort wchannels; // Record the number of channels.

Public Ulong dwsamplespeSpec; // Records samples per second.

Public ulong dwavgbytespersec; // Record the amount of data per second.

Public ushort wblockalign; // Record the alignment unit of the block.

Public ushort wbitsPersample; // Record the number of bits required for each sampling.

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.lendhe> = 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.bitconvert32 (Binfo, 4);

//wavinfo.filesize = convert.toint64 (system.text.encoding.default.getstring (binfo, 4, 4));

WAVINFO.RIFFTYPE = System.Text.Encoding.default.getstring (Binfau, 8, 4);

Wavinfo.chunkid = system.text.Encoding.default.getstring (Binfo, 12, 4);

WAVINFO.CHUNKSIZE = System.bitconverter.Toint32 (Binfo, 16);

WAVINFO.WFORMATTAG = System.bitconvert16 (Binfo, 20);

WAVINFO.WCHANNELS = System.bitconvert16 (Binfo, 22);

Wavinfo.dwsamplespersec = system.bitconverter.touint32 (Binfo, 24);

WAVINFO.DWAVGBYTESPERSEC = System.bitconverter.touint32 (Binfo, 28);

Wavinfo.wblockalign = system.bitconvert16 (binfo, 32);

WAVINFO.WBITSPERSAMPLE = system.bitconverter.touint16 (binfo, 34);

WAVINFO.DATACHUNKID = system.text.encoding.default.getstring (binfo, 36, 4);

Wavinfo.datasize = system.bitconvert32 (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);

}

}

}

}

}

转载请注明原文地址:https://www.9cbs.com/read-67822.html

New Post(0)