Skip to content

Commit 7c224f1

Browse files
author
Amanda Butler
authored
Re-edit Mbed_USB_WAV_Audio_Player.md
Re-edit file because edits were lost.
1 parent d965596 commit 7c224f1

File tree

1 file changed

+47
-31
lines changed

1 file changed

+47
-31
lines changed

docs/tutorials/using_apis/Mbed_USB_WAV_Audio_Player/Mbed_USB_WAV_Audio_Player.md

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,54 @@
1-
# Mbed USB WAV Audio Player
2-
This is a tutorial on how to put together a USB WAV audio player with Mbed. In general, the user will load a WAV file onto an SD card that will be connected to an Mbed board. The user can then play the WAV file from the board on a host computer over USB. Once connected, the Mbed board will act as a USB microphone. The sound that the microphone is "recording" is actually sound data read from the SD card and sent to the host computer. This allows the sound to be played on speakers, headphones, or recorded with a program like Audacity.
1+
## Mbed USB WAV audio player
2+
3+
This tutorial explains how to put together a USB WAV audio player with Mbed. You will load a WAV file onto an SD card connected to an Mbed board. You can then play the WAV file from the board on a host computer over USB. Once connected, the Mbed board acts as a USB microphone. The sound that the microphone is "recording" is actually sound data read from the SD card and sent to the host computer. This allows the sound to be played on speakers or headphones or recorded with a program, such as Audacity.
34

45
### Libraries
6+
57
This tutorial uses several Mbed libraries:
6-
- USB (part of Mbed-OS)
7-
- [sd-driver](https://github.com/ARMmbed/sd-driver) (external library)
8-
- [AudioPlayer](https://github.com/c1728p9/AudioPlayer) (external library)
98

10-
The USBAudio class of USB library is used to send audio data from the Mbed board to the host PC. The SDBlockDevice and FATFileSystem classes of sd-driver library are used so that WAV files can be stored on an SD card and accessed by the Mbed board. Lastly, the AudioPlayer and WaveAudioStream classes of the AudioPlayer library are used to access the audio data from the WAV file on the SD card.
9+
- USB (part of Mbed OS).
10+
- [sd-driver](https://github.com/ARMmbed/sd-driver) (external library).
11+
- [AudioPlayer](https://github.com/c1728p9/AudioPlayer) (external library).
12+
13+
This tutorial uses the USBAudio class of the USB library to send audio data from the Mbed board to the host PC. It uses the SDBlockDevice and FATFileSystem classes of the `sd-driver` library, so you can store the WAV files on an SD card and the Mbed board can access them. Lastly, it uses the AudioPlayer and WaveAudioStream classes of the AudioPlayer library to access the audio data from the WAV file on the SD card.
1114

12-
### What You Need
13-
- Mbed Enabled board
14-
- SD card
15-
- SD card shield (if board does not already have an SD card port)
16-
- USB cable
15+
### What you need
16+
17+
- Mbed Enabled board.
18+
- SD card.
19+
- SD card shield (if board does not already have an SD card port).
20+
- USB cable.
1721

1822
### Setup
19-
The following steps demonstrate the setup and use of the Mbed WAV Audio Player:
20-
1. Create a new Mbed project.
21-
`mbed new <project name>`
22-
2. Add the [sd-driver](https://github.com/ARMmbed/sd-driver) and [AudioPlayer](https://github.com/c1728p9/AudioPlayer) libraries into the new Mbed project directory.
23-
`mbed add https://github.com/ARMmbed/sd-driver`
24-
`mbed add https://github.com/c1728p9/AudioPlayer`
25-
3. Copy and paste the below example code into *main.cpp*.
26-
4. Make sure that the SPI pins for the SDBlockDevice object are updated and correct for your board. For example, in the example below, line 10 sets up SPI for the SDBlockDevice for the NXP K64F Mbed board.
27-
5. Load WAV file(s) onto SD card. The example below uses a public domain WAV file called "Bach-minuet-in-g.wav" (attached below for download) that is inside of a "songs" directory on the SD card. It is important that the WAV file be PCM signed 16-bit little endian, or else it will not play, in that USBAudio does not support any other WAV formats. The WAV file can have any sampling rate and can have any number of channels. [Online-convert](https://audio.online-convert.com/convert-to-wav) can be used to achieve WAV files with different formats from any source audio file. The file "Bach-minuet-in-g.wav" is already in the correct format.
28-
![N](https://github.com/mrcoulter45/mbed-os-5-docs/blob/Mbed_USB_WAV_Audio_Player_Tutorial/docs/images/Mbed_USB_WAV_Audio_Player_img1.png)
29-
6. Compile the program and flash the binary.
30-
7. Ensuring that the target's USB is connected to the host computer, select "Mbed Audio" as the host PC's default audio input device. On Windows, in Control Panel, set "View by" to Category in the top right hand corner. Then, navigate to Hardware and Sound > Sound, and in the recording tab, right click on "Microphone Mbed Audio" > Properties > Listen. Check the "Listen to this Device" box and click Apply. The audio from the WAV file should now be audible through whichever output device is selected for the host PC's audio output. If "View by" is not set to Category, then audio will be under Sound in Control Panel.
31-
![N](https://github.com/mrcoulter45/mbed-os-5-docs/blob/Mbed_USB_WAV_Audio_Player_Tutorial/docs/images/Mbed_USB_WAV_Audio_Player_img2.PNG)
32-
![N](https://github.com/mrcoulter45/mbed-os-5-docs/blob/Mbed_USB_WAV_Audio_Player_Tutorial/docs/images/Mbed_USB_WAV_Audio_Player_img3.PNG)
33-
8. See "Troubleshooting" if issues persist.
23+
24+
The following steps demonstrate the setup and use of the Mbed WAV audio player:
25+
26+
1. Create a new Mbed project:
27+
28+
`mbed new <project name>`
29+
30+
1. Add the [sd-driver](https://github.com/ARMmbed/sd-driver) and [AudioPlayer](https://github.com/c1728p9/AudioPlayer) libraries into the new Mbed project directory:
31+
32+
`mbed add https://github.com/ARMmbed/sd-driver`
33+
`mbed add https://github.com/c1728p9/AudioPlayer`
34+
35+
1. Copy and paste the below example code into `main.cpp`.
36+
1. Make sure the SPI pins for the SDBlockDevice object are updated and correct for your board. For example, in the example below, line 10 sets up SPI for the SDBlockDevice for the NXP K64F Mbed board.
37+
1. Load WAV file(s) onto SD card. The example below uses a public domain WAV file called "Bach-minuet-in-g.wav" (attached below for download) that is inside a "songs" directory on the SD card. It is important that the WAV file be PCM signed 16-bit little endian, or else it will not play becaues USBAudio does not support any other WAV formats. The WAV file can have any sampling rate and can have any number of channels. You can use [Online-convert](https://audio.online-convert.com/convert-to-wav) to achieve WAV files with different formats from any source audio file. The file "Bach-minuet-in-g.wav" is already in the correct format.
38+
39+
![N](https://github.com/mrcoulter45/mbed-os-5-docs/blob/Mbed_USB_WAV_Audio_Player_Tutorial/docs/images/Mbed_USB_WAV_Audio_Player_img1.png)
40+
41+
1. Compile the program and flash the binary.
42+
1. Ensuring that the target's USB is connected to the host computer, select `Mbed Audio` as the host PC's default audio input device. On Windows, in Control Panel, set `View by` to `Category` in the top right corner. Then, navigate to `Hardware` and `Sound` > `Sound`, and in the recording tab, right click on `Microphone Mbed Audio` > `Properties` > `Listen`. Check the `Listen to this Device` box, and click `Apply`. The audio from the WAV file is now audible through whichever output device is selected for the host PC's audio output. If `View by` is not set to `Category`, audio will be under Sound in Control Panel:
43+
44+
![N](https://github.com/mrcoulter45/mbed-os-5-docs/blob/Mbed_USB_WAV_Audio_Player_Tutorial/docs/images/Mbed_USB_WAV_Audio_Player_img2.PNG)
45+
46+
![N](https://github.com/mrcoulter45/mbed-os-5-docs/blob/Mbed_USB_WAV_Audio_Player_Tutorial/docs/images/Mbed_USB_WAV_Audio_Player_img3.PNG)
47+
48+
1. See [Troubleshooting](#troubleshooting) if issues persist.
3449

3550
### main.cpp
51+
3652
```c++ NOCI
3753
// Mbed WAV Audio Player
3854
#include "mbed.h"
@@ -80,13 +96,13 @@ int main() {
8096
song.close();//Close the WAV file
8197
}
8298
```
83-
### Example WAV File
84-
##### [Bach-minuet-in-g.wav](https://github.com/mrcoulter45/mbed-os-5-docs/raw/Mbed_USB_WAV_Audio_Player_Tutorial/docs/tutorials/using_apis/Mbed_USB_WAV_Audio_Player/Bach-minuet-in-g.wav)
99+
100+
### Example WAV file
101+
102+
[Bach-minuet-in-g.wav](https://github.com/mrcoulter45/mbed-os-5-docs/raw/Mbed_USB_WAV_Audio_Player_Tutorial/docs/tutorials/using_apis/Mbed_USB_WAV_Audio_Player/Bach-minuet-in-g.wav)
85103
86104
### Troubleshooting
87105
88106
If USB properties of the Mbed USB WAV Audio Player are altered, such as the sample rate or number of channels, the Mbed board will need to be deleted and re-installed in the host PC's installed device list. In Device Manager, click View > Devices by Connection. Find "Mbed Audio" and uninstall the device. Reset the board and repeat Setup step 6. If problems still persist, be sure to format the WAV file correctly, as is denoted in Setup step 4.
89107
90-
![N](https://github.com/mrcoulter45/mbed-os-5-docs/blob/Mbed_USB_WAV_Audio_Player_Tutorial/docs/images/Mbed_USB_WAV_Audio_Player_img4.png)
91-
---
92-
108+
![N](https://github.com/mrcoulter45/mbed-os-5-docs/blob/Mbed_USB_WAV_Audio_Player_Tutorial/docs/images/Mbed_USB_WAV_Audio_Player_img4.png)

0 commit comments

Comments
 (0)