During my spare time I was able to develop a WAVE file parser that I was using during one of my project.

The initial idea popped up while I was facing an issue while trying to debug a WAVE file that was fed into Fast Fourier Transform and the FFT output in python and Android was not giving me the similar output. And then it became a interest for me to know more about the WAVE specification. And in few days I was more interested to write my own C/C++ code to parse the WAVE file to deal with the header section.

The Parser

The code for the wave parser can be found in this github link.

The wave parser in C/C++ can be used to display the header information for WAVE file. It currently supports parsing a basic WAVE file and headers with LIST type with Info chunks.

How to build and run the code

Follow the steps below to build and run the wave parser in C/C++.

$ git clone https://github.com/srimantap/wave_parser
$ meson setup builddir
$ cd builddir
$ meson compile
$ meson install

To get the help text for the wave parser “–help” or “-h” option can be passed.

Usage: wave_parser [OPTIONS]
Parse a WAVE file
FILE is the input file to parse

Options:
    -f, --file=INFIL         input to read from INFILE
    -h, --help               This help string
    -o, --outfile=OUTFILE    write output to OUTFILE
                             default is set to standard output
    -v, --verbose            set the log level for debugging
                             values:
                                 ERROR   = 1, default
                                 WARNING = 2
                                 DEBUG   = 3
                                 INFO    = 4

A wave file can be provided with the command line argument to display the header information

$ wave_parser -f test.wav
 
2021-10-04 20:52:02       MESSAGE    Start parsing of wave file test.wav                    
2021-10-04 20:52:02       MESSAGE                                                                                    
2021-10-04 20:52:02       MESSAGE    Header Information                                                              
2021-10-04 20:52:02       MESSAGE    ==================                                                              
2021-10-04 20:52:02       MESSAGE                                                                                    
2021-10-04 20:52:02       MESSAGE      ChunkID        :  RIFF                                                        
2021-10-04 20:52:02       MESSAGE      ChunkSize      :  32036                                                       
2021-10-04 20:52:02       MESSAGE      Format         :  WAVE                                                        
2021-10-04 20:52:02       MESSAGE      Subchunk1ID    :  fmt                                                         
2021-10-04 20:52:02       MESSAGE      Subchunk1Size  :  16                                                          
2021-10-04 20:52:02       MESSAGE      AudioFormat    :  1                                                           
2021-10-04 20:52:02       MESSAGE      NumChannels    :  1                                                           
2021-10-04 20:52:02       MESSAGE      SampleRate     :  16000                                                       
2021-10-04 20:52:02       MESSAGE      ByteRate       :  32000                                                       
2021-10-04 20:52:02       MESSAGE      BlockAlign     :  2                                                           
2021-10-04 20:52:02       MESSAGE      BitsPerSample  :  16                                                          
2021-10-04 20:52:02       MESSAGE      Subchunk2ID    :  data                                                        
2021-10-04 20:52:02       MESSAGE      Subchunk2Size  :  32000                                                       
2021-10-04 20:52:02       MESSAGE                                

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *