How to make a simple wav player by using Arduino
Talking about using Arduino to play music, is it the Arduino MP3 shield not the first thing you come up with? Or maybe some geeks will consider about tone() function? They are not the things our topic is about today. We don’t need any MP3 shield, tone(), or SD card. Only Arduino can perfectly play the music you like.
It’s cool. Do-it-yourself a home-brew MP3 player for dear daddy or little daughter is fascinating. If you got a small Freaduino Nano or Freaduino Pro to put this into fact, then I’m sure ipod won’t be your consideration.
But specifically how do you make it? Let us take a look.
PS: For the demo we’re gonna show you, since the RAM for the Arduino is very small, hence we can only keep a 2-3 second music. Use a SD card, there’ll be no time limitation. See Arduino Simple Wav Player 2 using SD card.
Integrated with the homemade low-pass filter, this Arduino-based simple WAV player is to send out PWM signal generated by UNO, then through the low-pass filter and make the PCM data stored in the flash of UNO into sounds. Basically, the player cannot be regarded as a pure WAV playback, because by extracting the data from the WAV file and storing it in an array format in UNO, this tutorial is for reference. You can make SD card based WAV player by referring to this idea.
The WAV player is easy to make on different platforms and applicable for various scenarios like voice broadcast system, electronic keyboard, as long as you understand the principle of sound.
II. The Principle
2.1 Digital Audio
2.1.1 Digital Audio Basics
The basic principles and methods of digital audio processing technology is to use ADC, the analog digital converter, to take sample, quantize, encode and convert the analog audio signal into digital data and files to be saved. Of course, during the playback, the digital data goes through the DAC digital analog converter to restore the analogy signal form to be played out by the sound device.
Depending on the application range of the audio signal, the sampling frequency and the quantization accuracy of the analog audio digital 0ADC varies. The following table shows the common standard:
As you can see from the above table, according to the sampling theorem, for audio signal with different qualities, the digital audio ADC sampling frequency is twice the highest frequency analog signal. Additionally, the higher sound quality you require, the higher ADC quantization bits. In fact, the human ear cannot tell 1/256 level (8) precision changes, but for the CD sound quality, we use 16 quantization bits, precision 1/65536. Apparently, the better sound quality a digital audio has, the greater the amount of data it has to deal with. As for a second audio signal, when it’s a telephone-level quality digital audio, the amount of data is 8k bytes with each byte stored the level value of one sampling point. To obtain a CD-level quality digital audio, the data amount for every second is 88.2k; that amount is 176.4k for a two-channel stereo.
The most typical digital audio data file is WAV, which is mostly by using the original PCM encoding to store the raw data for each sampling point. Without any compression, now we got a sound card(either integrated or stand-alone) with build-in microphone port, under the support of WINDOWS platform, we can record, that is, turn the sound into digital audio and save it in the computer. And this file we saved, is WAV format file. Therefore, when we follow the sampling frequency speed to read the audio data one by one, the file is converted to analog signal by DAC, thus, the sound can be represented.
2.1.2 WAVE Format Introduction
WAVE format (extension: wav) is one of the basic audio formats used in multimedia digital audio, which is based on RIFF format as a standard. RIFF is short for Resource Interchange File Format. The first four bytes of each WAVE file is “RIFF”.
WAVE files are composed of several chunks (blocks). According to their positions in the file, they are: RIFF WAVE chunk, format chunk, fact chunk (optional), data chunk, LIST chunk (optional), etc. Of all listed above, except for RIFF WAVE chunk, format chunk, data chunk, the others are optional.
2.1.3 Get PCM Audio Data from WAV Files
There are many WAV format files in PC. In fact, all prompt tone WINDOWS uses WAV format files. We can certainly create whatever audio file we need with the software on the PC. In the materials we provide a WAV file “talking microcontroller.wav” for readers. You can use the software WINHEX to view the specific content of the file in binary format (displayed as hexadecimal). The picture below tells how to display the content of the file by using INHEX.
According to the previous introduction of the WAV format audio file, you can find out the audio data part. The chunks have been marked in the following picture, and the parameters have been listed.
For more detail: How to make a simple wav player by using Arduino
This Post / Project can also be found using search terms:
- bang boros gloery hoile tube