Read the information on the Internet, the implementation is not difficult, next to study the FFT
In accordance with the online information, complement/32768
The program is divided into two parts, the definition of WAV format on-line data many
Read WAV, save audio data to TXT
Using system.io;using system;using system.text;namespace audio Processing {class Program {const int bytesample = 2; const int dataposition = 40; 0x16 2byte 0002 Dual channel//0x22 2byte 0010 16 bit//0x18 4byte 0000ac44 44100 sample rate static void Main (Strin G[] args) {byte[] length = new byte[4]; FileStream fs = new FileStream ("Test.wav", FileMode.Open, FileAccess.Read); Fs. Position = dataposition; Fs. Read (length, 0, 4); byte[] content = new Byte[gethextoint (length)]; string[] Sample = new string[content. Length/bytesample]; Fs. Read (content, 0, content. Length); Gethex (content); Sample = Getsample (content); StreamWriter SW = new StreamWriter ("Data.txt", true, Encoding.default); foreach (String i in sample) {sw. Flush (); Sw. WriteLine (i); } SW. Close (); } static int Gethextoint (byte[] x) {String retvalue = ""; for (int i = x.length-1; I >= 0; i--) {RetValue + = X[i]. ToString ("X"); } return Convert.ToInt32 (RetValue, 16); } static void Gethex (byte[] x) {byte tmp; for (int i = 0; i < x.length; i++) {tmp = Convert.tobyte (X[i]. ToString ("X"), 16); X[i] = tmp; }} static string[] Getsample (byte[] x) {string[] RetValue = new String[x.length/bytesa Mple]; for (int i = 0, i < retvalue.length; i++) {for (int j = (i + 1) * BYTESAMPLE-1; J >= I * Bytesample; j--) {Retvalue[i] + = X[j]. ToString ("X"); } Retvalue[i] = ((double) convert.toint16 (Retvalue[i], 16)/32768). ToString ("F4"); } return RetValue; } }}
Read txt, display waveform
Using system;using system.drawing;using system.text;using system.windows.forms;using System.IO;using system.collections.generic;using system.threading;namespace loaddataview{public partial class Form1:form { const BOOL Leftstatus = FALSE; Public Form1 () {InitializeComponent (); New Thread (new ThreadStart () = {this. Invoke (new MethodInvoker () = {Label1. Text = Leftstatus? "Left channel": "Right channel"; })); list<double> list = new list<double> (); StreamReader sr = new StreamReader ("Data.txt", Encoding.default); int m = 0; while (!SR. Endofstream) {if (leftstatus) {if (m% 2 = = 0) List. ADD (double. Parse (Sr. ReadLine ())); } else {if (m% 2! = 0) List. ADD (double. Parse (Sr. ReadLine ())); } m++; } Sr. Close (); Bitmap Bitmap = new Bitmap (picturebox1.width, picturebox1.height); Graphics g = graphics.fromimage (bitmap); G.smoothingmode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; G.drawline (New Pen (Color.Black, 5), New Point (+), new Point (20, 540)); G.drawline (New Pen (Color.Black, 5), New Point (A, 290), New Point (1600, 290)); int k = list. count/1550; for (int i = 0; i < list. Count; i++) {g.drawline (new Pen (Color.green, 1), New Point (+ i/k, 290), new point (+ I /k, 290 + (int) (List[i] * 250 * 2))); } this.pictureBox1.Image = bitmap; })). Start (); private void Form1_Resize (object sender, EventArgs e) {this. Width = 1650; This. Height = 600; } }}
C # Implementation of WAV waveform diagram