Voice Recorder Tutorial: Step 9

Step 9: Debug Your Application

Congratulations! You’re done: you are ready to debug your application!

Don't forget to insert a micro SD card into the micro SD card slot (J8) on the MEB II board.


Loopback Mode

1

Put a breakpoint in the APP_VOICE_RECORD_LOOP_STATES_CODEC_ADD_FIRST_BUFFER_READ state in app_voice_record_loop.c. Hitting this breakpoint will indicate that the first write-read request has been submitted successfully.

Step14_1.PNG

2

Debug your application! Click the Debug Main Project Main_Debug_Project.png icon.

3

The breakpoint you added above will not be hit until you start the Loopback application. On the MEB II's display, select the Loopback mode and press the Start button. Once the Start button is pressed, the breakpoint will be hit. Single-step (by clicking F7) and observe the flow of control in the application state machine.

4

Put a breakpoint in the buffer event handler. Hitting the breakpoint in the event handler indicates that the last submitted buffer is transferred/received at the CODEC.

Step14_2.PNG

5

Remove all break points and click F5 to allow the application to run.

6

Connect a headset with the speaker jack connected to the HP Out connector and microphone jack connected to the MIC IN connector on the Multimedia Expansion Board II. Speak into the microphone to hear your voice in the headset speaker.


Record Mode

1

Suspend debugging by pressing the Pause button Debug_Pause.png. Press the Reset button Debug_Reset.gif to reinitialize the application.

2

Put a breakpoint in the APP_VOICE_RECORD_STORE_STATES_CREATE_WAVE_HEADER state in app_voice_record_store.c. This will indicate:

  • The CODEC is opened.
  • A WAV audio file is created on the SD card.
  • The header of the file is being written.
Step14_3.PNG

3

Debug your application! Click the Debug Main Project Main_Debug_Project.png icon.

4

The breakpoint you added above will not be hit until you start the Record application. On the MEB II's display, select the Record mode and press the Start button. Once the Start button is pressed, the breakpoint will be hit. Single-step (by clicking F7) and observe the flow of control in the application state machine.

5

Put a breakpoint in the buffer event handler. Hitting the breakpoint in the event handler indicates that the queued read request is completed and that the write operations to the SD card can be started.

Step14_4.PNG

6

Put another breakpoint in the state APP_VOICE_RECORD_STORE_STATES_WRITE_WAVE_AUDIO_DATA indicating that the audio data writing to the WAV file is in progress.

Step14_5.PNG

7

Remove all break points and click F5 to allow the application to run.

8

Change the mode to Playback and observe that a new WAV file is listed in the list box. This new WAV file is the one just created.


Playback Mode

1

Suspend debugging by pressing the Pause button Debug_Pause.png. Press the Reset button Debug_Reset.gif to reinitialize the application.

2

Put a breakpoint in the APP_SDCARD_AUDIO_PLAYER_STATE_TRACK_CHANGE state which will indicate that an audio track is complete and the next track will be selected for playing.

Step14_6.PNG

3

Debug your application! Click the Debug Main Project Main_Debug_Project.png icon.

4

The breakpoint you added above will not be hit until you start the Playback application. On the MEB II's display, select the Playback mode and press the Start button. Once the Start button is pressed, the breakpoint will be hit. Single-step (by clicking F7) and observe the flow of control in the application state machine.

5

Put a breakpoint in the buffer event handler. Hitting this breakpoint indicates that the last submitted buffer is transferred to the CODEC.

Step14_7.PNG

6

Remove all break points and click F5 to allow the application to run.

7

Connect a headphone to the HP Out connector on the Multimedia Expansion Board II and you should hear the audio track being played.

 Results

Loopback mode:

You should be able to hear (through the headphone) yourself speaking on the microphone connected to the Multimedia Expansion Board II. This may not work when the CODEC is not configured appropriately or when the sampling rate is not set to 16000 Hz.

Record mode:

Thirty seconds of your voice will be recorded and stored in a WAV file. The recording may fail if the SD card was not mounted or if the CODEC was not initialized as expected.

Playback mode:

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 you may not hear any audio at all or may hear distorted audio.

 Analysis

You have successfully streamed your voice from a microphone to a speaker. You have also recorded your voice and stored it in a WAV file on an SD card and played it back on a speaker. The application was designed around four cooperating tasks. One task each for initializing and managing the Loopback, Record, and Playback mode. An additional task was created to handle the display interface.

You used the MPLAB® Harmony Configurator (MHC) to configure the PIC32 and the MPLAB Harmony Framework. You used the clock configurator to set up the oscillator to generate the necessary system and peripheral clock. You configured the CODEC, I²C, I²S, SD Card, and Serial Peripheral Interface (SPI) drivers. You also initialized the Direct Memory Access (DMA) and Files systems service and you added the audio decoder functionality.

You used the MPLAB Harmony Graphics Composer (MHGC) to create a touch-controlled display to control this application.

 Conclusions

This tutorial provides you with the major components needed to build an audio application (recording and playback). As a next step, you may want to add support for other audio formats (e.g., MP3 or WMA) and add options for higher sampling rates (48000 Hz) or data widths (24- and 32-bit).

© 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.