Wav_SD_Card_Read for RS EDP

Reading a wav file from an SD Card

This small program allows the user to input a filename for the .wav file he want to inspect. After entering the file name the software will attempt to open the named file from the SD card and if successful will display the information contained in the header.
The header of a .wav file contains information such as the data rate, the number of audio channels (stereo/mon etc) plus the length of the file. This information is critical if the user want to attempt to play the wav file. By reading the sample rate information for example the software can be adjustment to read the data at the required rate.
The full information of the header file is read into a structure of the following type and displayed on the PC virtual terminal using printf type statement:

/* Structure of a .wav file header */
struct wave_header_construction
{    sint8_t  identification_block[5];
     uint32_t length_of_file;
     sint8_t  identifier1[5];
     sint8_t  identifier2[5];
     uint32_t position_of_data;
     uint16_t format_tag;
     uint16_t number_of_channels;
     uint32_t samples_per_second;                    
     uint32_t bytes_per_second;
     uint16_t bytes_per_sample;
     uint16_t bits_per_sample;
     sint8_t  marker[5];
     uint32_t number_of_bits_in_sample;
} wave_file_info;

The complete header file is then displayed on the PC virtual terminal with the help of a few pc.printf statements, and a check made to see if this file is a valid header file or not. It is often found that some .wav files become corrupted as the information contained within the block does not make sense. A quick check is done by the software to indicate weather the .wav file is valid or not.

The complete code is available to download from here.
It comprises of several source code and header files and is based on the libraries provided by ARM.

The software is designed to run on the RS EDP platform utilising the mbed module, the mbed module adapter and the base board, but can be modified to work with pretty much any system. The mbed adpater board has the SD card socket on it

Please check out my personel profile page for other SD card examples.

All wikipages