2016-11-03 6 views
0

* .wavファイルの想定内容を読んだ後、なぜゼロになっているのか分かりません。出力の画像にバイナリリーダーが* .wavの内容を読み取らない理由

リンク:助けを事前にhttp://imgur.com/a/rZWes

using (BinaryReader reader = new BinaryReader(File.Open("test.wav", FileMode.Open))) { 

      // Read the wave file header from the buffer. 

      int chunkID = reader.ReadInt32();   print (chunkID); 
      int fileSize = reader.ReadInt32();   print (fileSize); 
      int riffType = reader.ReadInt32();   print (riffType); 
      int fmtID = reader.ReadInt32();    print (fmtID); 
      int fmtSize = reader.ReadInt32();   print (fmtSize); 
      int fmtCode = reader.ReadInt16();   print (fmtCode); 
      int channels = reader.ReadInt16();   print (channels); 
      int sampleRate = reader.ReadInt32();  print (sampleRate); 
      int fmtAvgBPS = reader.ReadInt32();   print (fmtAvgBPS); 
      int fmtBlockAlign = reader.ReadInt16();  print (fmtBlockAlign); 
      int bitDepth = reader.ReadInt16();   print (bitDepth); 

      int dataID = reader.ReadInt32();   print (dataID); 
      int dataSize = reader.ReadInt32();   print (dataSize); 

      byteArray = reader.ReadBytes(dataSize); 

      // After this you have to split that byte array for each channel (Left,Right) 
      // Wav supports many channels, so you have to read channel from header 
     } 

ありがとう!

+0

あなたの 'print'関数とは何ですか? –

+0

エンディアンの問題? https://en.wikipedia.org/wiki/Endianness –

+0

画像をリンクするのではなく、質問の出力を投稿する必要があります。また、結果を確認するために16進エディタでwavファイルを調べてみましたか? – juharr

答えて

0

はWAVヘッダのこの定義を参照してください:

http://soundfile.sapp.org/doc/WaveFormat/

あなたが「データ」ヘッダ&データサイズを取得する前には、bitsPerSample(ビット深度)の後に、オプションの値があることがわかります。

PCM形式でない場合は、これらも読むか、bitDepthの後に "data"を検索する必要があります。

私がちょうどチェックしたファイル - 最初の値は、この特定のケース12のint16の数を指定するint16です。したがって、さらに24バイトを読み取ると、「データ」ヘッダーに移動します。

// Read the wave file header from the buffer. 
    int chunkID = reader.ReadInt32(); // ASCII string = "RIFF" 
    print(chunkID); 
    int fileSize = reader.ReadInt32(); 
    print(fileSize); 
    int riffType = reader.ReadInt32(); // ASCII string "WAVE" 
    print(riffType); 
    int fmtID = reader.ReadInt32();  // ASCII string "fmt " 
    print(fmtID); 
    int fmtSize = reader.ReadInt32(); // 16 = PCM (actually specifies size of data of this section) 
    print(fmtSize); 
    short fmtCode = reader.ReadInt16(); 
    print(fmtCode); 
    short channels = reader.ReadInt16(); 
    print(channels); 
    int sampleRate = reader.ReadInt32(); 
    print(sampleRate); 
    int fmtAvgBPS = reader.ReadInt32(); 
    print(fmtAvgBPS); 
    short fmtBlockAlign = reader.ReadInt16(); 
    print(fmtBlockAlign); 
    short bitDepth = reader.ReadInt16(); 
    print(bitDepth); 

    short[] extraPars = null; 
    if (fmtSize != 16) 
    { 
     short NoOfEPs = reader.ReadInt16(); 
     extraPars = new short[NoOfEPs]; 
     for (int i=0;i<NoOfEPs;i++) 
     extraPars[i] = reader.ReadInt16();; 
    } 

    int dataID = reader.ReadInt32(); // ASCII string = "data" 
    print(dataID); 
    int dataSize = reader.ReadInt32(); 
    print(dataSize); 

    byte [] byteArray = new byte[dataSize]; 
    byteArray = reader.ReadBytes(dataSize); 
関連する問題