VHDLwhiz WAV Audio File Reader Writer Packages User Manual
- June 12, 2024
- VHDLwhiz
Table of Contents
VHDLwhiz WAV Audio File Reader Writer Packages
Product Information
- Product Name: WAV audio file reader/writer packages
- Version: 1.0.0
- Date: July 1, 2022
- Product URL: https://vhdlwhiz.com/product/vhdl-package-wav-audio-file-reader-writer/
- Contact Email: jonas@vhdlwhiz.com
Description
- This VHDL package provides functionality for reading and writing uncompressed WAV audio format files. It contains two packages, wav_reader and wav_writer, which allow users to handle audio data in simulation.
- WAV is a widely used audio file format on Windows-based systems and is also compatible with audio recording devices and editing software like the Adobe suite. Despite the availability of more efficient audio codecs, WAV remains popular for storing uncompressed, lossless audio due to its simplicity and cross-platform support.
- The VHDLwhiz’s wav_reader package skips non-mandatory parts of a WAV file and focuses on the data subchunk that contains the audio samples. The wav_writer package can reproduce or create a new WAV file with a mandatory RIFF header.
- The VHDL packages support mono or stereo WAV files with any sampling rate and sample bit length, as long as it is a multiple of 8 bits. WAV files can have various types of encoding on individual audio samples, but the most common ones are pulse-code modulation (PCM) or 32-bit IEEE floating-point.
- Note that the wav_reader package reads the audio samples as-is without performing any conversion. It is the responsibility of the user to interpret the data. The wav_writer package allows specifying the format code to indicate the encoding of the samples.
License
The MIT license covers the source code’s copyright requirements and terms of
use. Refer to the LICENSE.txt file in the Zip file for details.
Changelog
These changes refer to the project files, and this document is updated
accordingly.
-
Version: 1.0.0
-
Remarks: Initial release
Description
- This project contains two VHDL packages for reading from or writing audio data to WAV files in simulation.
- WAV is a file format for storing audio data that’s widely used on Windows-based systems and by audio recording devices or editing software like the Adobe suite. Despite the emergence of more efficient audio codec algorithms, WAV remains a popular format for storing uncompressed, lossless audio data because of its simplicity and cross-platform support.
- Every WAV file begins with a Resource Interchange File Format (RIFF) header containing information about the audio data’s encoding. After this mandatory part, there may be multiple subchunks with meta info that’s not crucial for knowing how to interpret the audio data.
- Therefore, VHDLwhiz’s wav_reader package ignores non-mandatory parts and skips to the “data” subchunk containing the audio samples. Similarly, the wav_writer package can reproduce or create a new WAV file with a mandatory RIFF header.
- The VHDL packages support WAV files that are mono or stereo, have any sampling rate, and any sample bit length, as long as it’s a multiple of 8 bits.
- WAV files support any type of encoding on the individual audio samples, but the most common ones are pulse-code modulation (PCM) or 32-bit IEEE floating-point.
- The wav_reader package allows you to extract the format code from the file header, but it will not do any conversion. It reads the audio samples as-is, and it’s up to the Copyright VHDLwhiz.com
user of the package to interpret the data. Likewise, you may specify the
format code when using the wav_writer package to indicate the encoding of the
samples.
Example use cases
The comments above the method prototype code in the VHDL files describe how
the procedures and functions in the protected types work.
Study the VHDL testbench to see a working example that reads and writes mono
and stereo WAV files with PCM and IEEE float encoding.
DUT audio passthrough
- When testing audio processing modules, a typical use case is to read from one WAV file, stream the data through the device under test (DUT), and write back the results to a new WAV file.
- That’s easy to accomplish with VHDLwhiz’s WAV file reader/writer packages.
- The example code below shows how you can set up such a testbench.
First, we open the input WAV file for reading. Then, we create an output WAV
file based on the input file’s header. After that, we enter a loop that reads
each sample and sends it to the DUT.
Because audio data is slow compared to the FPGA’s high clock speed, the DUT
will have plenty of time to process the samples before we write its output to
the second WAV file.
Finally, we close both WAV files so that we can listen to them or analyze them
using third-party software.
Method prototypes
wav_reader_pkg.vhd
The code listing below shows the declarative region of the WAV file reader
package.
wav_writer_pkg.vhd
The code listing below shows the declarative region of the WAV file writer
package.
Zip file content
- WAV file RW package – User Manual.pdf This document
- wav_reader_pkg.vhd The VHDL package for reading WAV files
- wav_writer_pkg.vhd The VHDL package for writing WAV files
- testbench.vhd VHDL testbench for the package
- How to run.gif Screencast guide for running the testbench
- LICENSE.txt License agreement
- project.mpf ModelSim/Questa project file
- run.do ModelSim/Questa script for running the testbench
- wave.do Wave format file for ModelSim/Questa
- Audio_in_mono_48kHz_32b_float.wav Audio sample
- Audio_in_stereo_48kHz_24b_PCM.wav Audio sample
Simulating the design
There is a demo testbench in the Zip file (testbench.vhd).
The VHDL testbench should work in any capable VHDL simulator supporting the
full 2008 VHDL revision, but the provided run.do script only works in
ModelSim/Questa.
To run the testbench, open ModelSim/Questa and type in the simulator console:
do
- The testbench reads two WAV files using the wav_reader and writes them back to disk using the wav_writer package. The two input files are
- Audio_in_mono_48kHz_32b_float.wav and
- Audio_in_stereo_48kHz_24b_PCM.wav. The output files will be
- Audio_out_mono.wav and Audio_out_stereo.wav.
- The WAV header information should appear in the simulator’s transcript window, and a waveform showing the audio as an analog signal should appear, as shown below.
Known issues
The package is unsynthesizable and only meant for use in
testbenches/simulation.
Copyright VHDLwhiz.com
References
- VHDLwhiz - The best resource for VHDL engineers
- VHDLwhiz - The best resource for VHDL engineers
- VHDL package: WAV audio file reader/writer - VHDLwhiz
- VHDL package: WAV audio file reader/writer - VHDLwhiz
Read User Manual Online (PDF format)
Read User Manual Online (PDF format) >>