After completing this exercise, you will understand how to configure and add the Audio Decoder Library (for decoding audio files in WAV format) to the project developed in the previous lab (Lab3: SD card reader support to load audio files) with the MPLAB® Harmony Configurator (MHC). You will also learn how to integrate these modules into an MPLAB Harmony project. This section will really start to show you the power of Harmony!
In this exercise we extend the previous lab, Lab3: SD card reader support to load audio files, and add new functionality to it. This application reads a WAV audio file from the SD card on the PIC32 MEB II board, and streams it over the PIC32 I2S interface through the audio CODEC. Here we implement the functionality of an audio player (for waveform audio format (WAV) files only). The application switches to the next track when the current track playing is completed (assuming that there is more than one track on the SD card). This application also demonstrates the configuration and integration of the additional modules using MHC, thereby extending its functionality.
The naming of functions and variables used in this exercise have been changed from APP_TONE_TEXTFILE_SDCARD_ to APP_SDCARD_AUDIO_. Otherwise the basic application flow remains the same.
|Figure 4.1: APP_Tasks()|
The application sub-tasks for this lab are shown in this figure.
|Figure 4.2: APP_SDCARD_AUDIO_Tasks()|
The initial states in the the APP_SDCARD_AUDIO_Tasks() are the same as those found in the previous lab:
- Open the CODEC to obtain a handle to the CODEC buffer
- Register a CODEC buffer event handler function (called when the buffer transfer had completed)
- Mount the file system for the SD card
- Set the current drive path for the SD card
You will add a new state for this lab: STATE RUNNING. This state searches all directories on the SD card, and saves a list of WAV audio files into a table.
|Figure 4.3: Audio Player State Machine|
The audio player state machine then starts to run. The audio player states perform the task of reading the audio data from the opened WAV audio file, decoding the WAV raw data through the decoder, and then passing the decoded buffer to the audio CODEC for playing. The audio player states also handle track change events, and waiting for the current audio buffer completion event from the audio CODEC. You will see these states described in more detail in Step 4.
Lab Source Files and Solutions:
If you haven't already downloaded all source files for the SD card Audio Player labs:
Download the lab source files and solutions >
This project has been verified to work with the following versions of software tools:
MPLAB X IDE v3.26, MPLAB XC32 Compiler v1.40, MPLAB Harmony v1.08
Because we regularly update our tools, occasionally you may discover an issue while using newer versions. If you suspect that to be the case, we recommend that you double check using the same versions that the project was tested with.
Archived versions of our tools can be found on the following Microchip websites:
MPLAB Harmony (see "Archived Downloads" tab)
MPLAB X IDE and XC32 Compiler (see "Downloads Archive" tab)
Note that multiple versions of all these tools can co-exist on the same computer.
This lab builds off the work you performed in the previous lab. If you did not perform SD card Audio Player Lab3, please start Lab4 using the Lab3 solution project (found under the firmware folder). Verify it works as expected before continuing with this lab.
All steps must be completed before you will be ready to build, download, and run the application.
- Step 1 – Copy source files and rename project for Lab4.
- Step 2 – Add WAV decoder functionality.
- Step 3 – Generate Harmony code.
- Step 4 – Include application specific source files, add required code and build the project.
- Step 5 – Review the application code.
- Step 6 – Debug your application.
Step 1: Copy source files and rename project for Lab4
Step 2: Add WAV decoder functionality
Step 3: Generate Harmony code
Step 4: Include application specific source files, add required code and build the project
Step 5: Review the Application code
Step 6: Debug your Application
You should be able to hear audio tracks on your headphones connected to the Multimedia Expansion Board II. If you did not configure the decoder correctly or copied audio files with a file format other than WAV, you may not hear any audio at all or may hear a distorted audio.
In this exercise we successfully played an audio track stored in the form of a WAV file on an SD card. We extended the previous lab, SD Card Audio Player Lab3, by adding audio decoder functionality using the MHC. The decoder parsed the WAV files and extracted information including audio sampling rate, bits per sample and ultimately provided the application with the raw audio data samples. We also extended the application by adding a separate state machine that traversed through the SD card folder structure and saved the WAV audio files in a table. The application configured a CODEC driver based on the sampling rate information provided by the decoder and passed the audio samples read from the decoder to the CODEC for playing.
With this exercise we have all the major pieces of a basic audio player glued together. We have the SD card driver and a file system to hold the audio files, decoder functionality to decode audio files of the WAV file format, and a CODEC driver for digital to analog conversion of audio. In effect, we have a full fledged audio player. As a next step, you may extend the application by adding decoder support for other audio file formats like MP3 or WMA using MHC.
Table of Contents