I try to extract information from a wav-file, and it works for most info.
Here is some of my code:
Qt Code:
  1. QFile audioFil(fileName);
  2. if (audioFil.open(QIODevice::ReadOnly)){
  3. audioFil.seek(0);
  4. tst = audioFil.read(4);
  5. qDebug() << "RIFF..? : " << tst;
  6. .....
  7. audioFil.seek(20);
  8. tst = audioFil.read(2);
  9. audioFormat = GetLittleEndianInteger(tst,0);
  10. qDebug() << "audioformat (1 = PCM): " << audioFormat;
  11.  
  12. audioFil.seek(22);
  13. tst = audioFil.read(2);
  14. channels = GetLittleEndianInteger(tst,0);
  15. qDebug() << "Channels: " << channels;
  16.  
  17. audioFil.seek(24);
  18. tst = audioFil.read(4);
  19. sampleRate = GetLittleEndianInteger(tst,0);
  20. qDebug() << "sampleRate: " << sampleRate;
  21.  
  22. audioFil.seek(28);
  23. tst = audioFil.read(4);
  24. byteRate = GetLittleEndianInteger(tst,0);
  25. qDebug() << "ByteRate: " << byteRate;
  26.  
  27. audioFil.seek(32);
  28. tst = audioFil.read(2);
  29. blockAlign = GetLittleEndianInteger(tst,0);
  30. qDebug() << "BlockAlign: " << blockAlign;
To copy to clipboard, switch view to plain text mode 
The GetLittleEndianInteger function is here
Qt Code:
  1. int MainWindow::GetLittleEndianInteger(QByteArray data, int startIndex)
  2. {
  3. return (data[startIndex + 3] << 24)
  4. | (data[startIndex + 2] << 16)
  5. | (data[startIndex + 1] << 8)
  6. | data[startIndex];
  7. }
To copy to clipboard, switch view to plain text mode 

debugMsg.jpgheader.jpg
As you can see from the two images, it extracts the correct values, except when it comes to SampleRate and ByteRate.
SampleRate should be 44100 (44 ac 00 00). How does it become -21436?
ByteRate should be 176400 (10 b1 02 00). How does it become -20208?

This has driven me crazy the last hours Any ideas?