C#讀取wav文件


 1  private void showWAVForm(string filepath) //此函數只能用於讀取16bit量化單聲道的WAV文件  2          {
 3               FileStream  fs = new FileStream(filepath,FileMode.Open);
 4               fs.Read(new byte[42],0,42);
 5               byte[] datasize = new byte[4]; 
 6               fs.Read(datasize,0,4);
 7               int dtsize = byteArray2Int(datasize); //數據塊部分數據的字節數
 8               for (int i = 0; i < dtsize/2; i++)
 9                   {
10                     byte[] byt = new byte[2];
11                     fs.Read(byt, 0, 2);
12                     short dt = (short)(byt[0] | (((int)byt[1]) << 8)); 13                     Console.WriteLine(dt);
14                 }
15               fs.Close();
16          }
17  
18      private int byteArray2Int(byte[] hex)
19         {
20            return hex[0] | (hex[1] << 8) | (hex[2] << 16) | (hex[3] << 24);
21         }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM