@@ -81,57 +81,11 @@ If USB properties of the Mbed USB WAV Audio Player are altered, such as the samp
81
81
82
82
## main.cpp
83
83
84
- ``` c++ NOCI
85
- // Mbed WAV Audio Player
86
- #include " mbed.h"
87
- #include " USBAudio.h"
88
- #include " SDBlockDevice.h"
89
- #include " FATFileSystem.h"
90
- #include " AudioPlayer.h"
91
- #include " WaveAudioStream.h"
92
-
93
- // Connection for SD card
94
- SDBlockDevice sd (PTE3, PTE1, PTE2, PTE4);//MOSI, MISO, SCLK, CS
95
- FATFileSystem fs("sd", &sd);
96
-
97
- int main() {
98
- // Set the maximum speed so it can keep up with audio
99
- sd.frequency(25000000);
100
- // Load WAV file from SD card
101
- // WAV file must be PCM signed 16-bit little endian
102
- File file;
103
- if (file.open(&fs, "songs/Bach-minuet-in-g.wav") != 0) {
104
- error("Could not open 'songs/Bach-minuet-in-g.wav'\r\n");
105
- }
106
- WaveAudioStream song(&file);//"song" is the audio data object
107
- // Check to see if file is a valid WAV file
108
- if(song.get_valid() == 0){
109
- error("ERROR: not valid WAV file\r\n");
110
- }
111
- // WAV file must be 16-bit
112
- if(song.get_bytes_per_sample() != 2){
113
- error("ERROR: WAV file not 2 bytes per sample (16-bit)\r\n");
114
- }
115
- USBAudio audio(true, 8000, song.get_channels(), song.get_sample_rate(), song.get_channels());
116
- uint8_t buffer[ 1500] ;
117
- int num_bytes_read;
118
- printf("Playing Audio\r\n");
119
- // Reads and plays data from WAV file over USB until song is over
120
- while(1){
121
- num_bytes_read = song.read(buffer, 1500);
122
- if(num_bytes_read == -1){
123
- printf("Song Over\r\n");
124
- break;
125
- }
126
- audio.write(buffer, num_bytes_read);
127
- }
128
- song.close();//Close the WAV file
129
- }
130
- ```
84
+ [ ![ View code] ( https://www.mbed.com/embed/?url=https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_USB/USBAudio_wav_audio_player )] ( https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_USB/USBAudio_wav_audio_player/main.cpp )
131
85
132
86
## Example WAV file
133
87
134
- [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)
88
+ [ Bach-minuet-in-g.wav] ( https://github.com/ARMmbed /mbed-os-examples-docs_only/blob/master/APIs_USB/USBAudio_wav_audio_player /Bach-minuet-in-g.wav )
135
89
136
90
## Troubleshooting
137
91
0 commit comments