Artificial Intelligence TechC++C++11C++14C++17Language FeatureLearn C++

Learn How To Read The WAV Waveform Audio File Format In C++

Learn How To Read The WAV Waveform Audio File Format In C++

Sound is one of the important parts of computer science and programming. The correct use of sound can add excitement to recreational apps such as games or it can act to alert the user to an important event or state change in a utility or business-focused program. We have many different sound formats to play sound files in our applications or mostly in our games, or sometimes we need to edit them to analyze or to apply some filters. Games, MIDI Apps, Sound Editors, Music Studio Apps, Engineering Apps, AI Applications (such as voice recognition from sound or movie files), etc. Waveform Audio File Format (shortly *.WAVE or *.WAV files) are the oldest and they are still useful to play them from memory and it is easy to edit them. In this post, we explain how we can read the WAV Waveform Audio File Format in C++.

What is the WAV waveform audio file format in C++?

Audio files have different audio formats – ways of storing the analog sound in a variety of digital representations. The most used formats are MP3, OG, and FLAC files and these audio formats have compression techniques to make audio files smaller. The most known raw version is a WAV file. Wave format (*.wav or *wave) is a recorded digital form of sound whose volume changes data across a timeline. In C++ Builder it is easy to use recording wav files on Windows. To record a sound in Multi-Device applications we must use FMX.Media.hpp header.

How can we record a WAV waveform audio file format in C++?

Recording WAV sound is well explained in our Learn How To Easily Record Sound In Powerful Modern C++ On Windows post.

How can we read the WAV waveform audio file format in C++?

If you are reading a binary file, first you should know its structure type and so on. Waveform Audio File Format (WAVE or WAV) is an audio file format standard to record audio bitstream on a memory or on a drive as a file. Here are two images that show the header of the WAVE format.

Wave File format Ref <a href=httpsoundfilesapporgdocWaveFormat target= blank rel=noopener nofollow title=>httpsoundfilesapporgdocWaveFormat<a>
Wave File format Ref <a href=httpsoundfilesapporgdocWaveFormat target= blank rel=noopener nofollow title=>httpsoundfilesapporgdocWavFormat<a>


How can we read the WAV waveform audio file format in C++?

WAW header can be defined as a structure as shown below:

Now let’s create a read_wav_file() function to read this struct. We can read this WAV header as shown below.

finally, we can read and display like so:


Is there a full C++ example to read the WAV waveform audio file format in C++?

Here is the full C++ example to read a file which uses the WAV waveform audio file format.

The output will be as below.

Note that this struct can be used in C applications too. As you see, in modern C++, we can easily read WAV wave files, now you can display or edit wave files.

Learn How To Read The WAV Waveform Audio File Format In C++ C++ Builder logo

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise version.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?

C++C++17Code SnippetLearn C++

How To Convert Char Array String To Unicode String Correctly In C++?

Artificial Intelligence TechC++Language FeatureLearn C++

How To Develop A Simple Hopfield Network In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++Syntax

Learn Default Constructors Of Classes In Modern C++