Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 From theory to practice
#11
A .wav file (as well as most other audio and images actually) consists of two main parts, a header and the actual data.  For a .wav file  the 'header' is 44 bytes (0 - 43) and the data is the remainder of the file (bytes 44 - end).  The 'header' is further divided into 'file' and 'format' bytes (chunks). The following is something I wrote to 'read' that information.  It's some what long as I included a lot of comments. It only requires the built-in struct module.  This is based on the information provided here: .WAV format.  Hope this help you in understanding what's going on 'under the hood'

the output:
Output:
C:\Python36\python.exe C:/Python/Sound/read_wave.py .WAV File information for  SineWave_440Hz.wav ===============================================================================  File ID: RIFF  File Size: 264644  File Type: WAVE  File Format: fmt   Length of Format Data: 16 Type of Format: PCM (Uncompressed)  Number of Channels: 1  Sample Rate: 44100  Byte Rate: 88200  Block Align: 2 Bits Per Sample: 16  Data Header: data  Size of Data Section: 264600 Process finished with exit code 0
I did not include the actual data, but concept remains the same.  Just 'seek(44), read the appropriate bits per sample (i.e . 8, 16, 24, 32) then unpack it.  Writing the file is pretty much just the reverse, except you 'pack' instead of 'unpack'.
zivoni likes this post
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Quote
#12
It's very nice to see how to parse informations from a binary file!

I opened my testing .waw file to see it and its exactly as you found. Only between a fmt chunk and a data chunk there is a chunk with id tags, probably some later (and now common) extension to .wav specification. The data chunk still starts with "data", so seek to that would work for chunk size/block.

top of wav
Quote
#13
Looking at your output, it appears they added what, 184 bytes to the header? From what I've read (actually glanced over) was that over time the Windows/IBM wave format has evolved to include a number of enhancements, including what is shown in your output.  That said, since it buggers up the start of the 'data' section, I suppose one would first have to determine where "data" actually appears in newer files in order to know the size of the header and in turn the size of the actual data.  For instance, as of 2007, MS has allowed for 18 different speakers (channels)...say whaaa?

I wonder if the additional bytes are the new 'standard' size for optional information and if so, what sort of info can be put in it?

I suppose I'll get some more recent wave files and see what I can see.

btw, the MS article is located here: https://msdn.microsoft.com/en-us/library...s.85).aspx

Seems I answered my own questions. I came across this document that explains (at least as of 1994) the newer format.  You have to scroll down a bit to the .WAV section.

http://www-mmsp.ece.mcgill.ca/Documents/...IFFNEW.pdf
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)