Lab4: Play a WAV Audio File from an SD Card with Harmony v2

Purpose

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!

Overview

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 Multimedia Expansion Board (MEB) II, and streams it over the PIC32 I²S interface through the audio CODEC. Here we implement the functionality of an audio player (for 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.


The application sub-tasks for this lab are shown in this figure.

Fig_3_1_3.png
Figure 4.1: APP_Tasks()

The initial states in the APP_SDCARD_AUDIO_Tasks() are the same as those found in the previous lab:

  1. Open the CODEC to obtain a handle to the CODEC buffer.
  2. Register a CODEC buffer event handler function (called when the buffer transfer had completed).
  3. Mount the file system for the SD card.
  4. 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.

Fig_3_2.png
Figure 4.2: APP_SDCARD_AUDIO_Tasks()


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.

Fig_3_3.png
Figure 4.3: Audio Player State Machine

Lab Source Files and Solutions:

If you haven't already, download all lab source files and solutions for the SD card audio player labs.

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 the Archived Downloads tab)
MPLAB X IDE and XC32 Compiler (See the Downloads Archive tab)
Note that multiple versions of all these tools can co-exist on the same computer.

 Procedure

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.

Lab Index

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

 Results

You should be able to hear audio tracks on your headphones connected to the MEB 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 distorted audio.

 Analysis

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 MHC. The decoder parsed the WAV files and extracted information including the 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.

 Conclusions

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.


© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.