We have completed our first step towards building a music player by developing a way to store the music files locally on the sd card. Now we will shift our focus towards understanding the way in which music is stored. The first audio was stored as analogue signal transcribe mechanically on a paper or glass but since then we have rapidly developed various other more efficient ways to store an audio signal. The digital formats revolutionized the whole industry as it was easier to store, process as well as replicate. Currently, we deal with various digital formats such as AIFF, AAC, MPEG standard etc. The MP3 is the MPEG-1 Audio layer 3 and is one of the most recognized audio file formats as it uses lossy data compression which drastically decreases the file sizes and is one of the reasons which caused the boom in the music industry in the 1990's. The format itself is quite complex as it uses advanced compression techniques such as the Huffman coding and so we will begin our discussion with the WAV format which will make our work easier along with providing the right amount of knowledge regarding file formats.
Consider a signal with different values at different intervals. If we know the maximum amplitude of the signal then we can divide the range of different amplitudes into discrete values. For eg, Consider a signal lying between 0 volts to 5 volts. If we divide the range(5-0) volts into 100 levels and store the value at any given moment as one of the numbers in between 1-100, then we can successfully store an analogue signal as binary numbers. This technique is known as Analog to Digital Conversion and sampling of the signal is done as to get the values at different times.
So if provide an analogue audio file as an input to the ADC we will be able to get the corresponding digital values at a particular frequency i.e if we have a sampling frequency of 'n' Hz then we will get 'n' different values of the audio in one second. This is known as a RAW file as we have the discrete values of an analogue signal at a particular frequency but it is uncompressed or unaltered. We can use this to play the music using our MCU as this is a digital audio format but we won't be able to do this without knowing the sampling frequency and the sampling resolution. For these pieces of information, we use the WAV file format which contains the RAW data along with some metadata about the music file such as its name, frequency, bit resolution, number of channels etc.
This time we will be storing our music file as a WAV file in the sd card as they are easy to manipulate. These files have one major disadvantage, they are very huge in size and so in the upcoming posts we will shift to MP3 and develop a complete music player.
WAVE stands for Waveform Audio File Format and is commonly written as WAV due to its file extension. It is a Microsoft and IBM audio file format standard for storing audio bitstreams on PC.
A typical WAVE file contains a 44 bytes Header followed by the data segment.
The data segment contains the bytes which are sampled at the frequency provided in the header. 44.1 kHz is a common sampling rate. For testing purpose, we can download any .wav file and open it using notepad and we will be able to see the above data very clearly. The information which is very much needed is the file size, Number of channels, Sample rate and the Bits per sample. We need to write a software to parse the header and extract the above info along with marking the start of the data segment by using the "data" chunk header.

Comments
Post a Comment