This is a sample that drives a speaker with PWM.
Fork of GR-PEACH_Audio_WAV by
This is a sample that drives a speaker with PWM. This sample will play a ".wav" file of the microSD or USB memory root folder. If the USER_BUTTON0 is pressed, the next song is played.
Format | Wav file (RIFF format) ".wav" |
Channel | 1ch and 2ch |
Frequencies | 32kHz, 44.1kHz and 48kHz |
Quantization bit rate | 8bits and 16bits |
You can adjust the volume by changing the following.
main.cpp
AudioPlayer.outputVolume(0.5); // Volume control (min:0.0 max:1.0)
The default setting of serial communication (baud rate etc.) in mbed is shown the following link.
Please refer to the link and change the settings of your PC terminal software.
The default value of baud rate in mbed is 9600, and this application uses baud rate 9600.
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
Revision 16:63d0cf9e117b, committed 2018-07-24
- Comitter:
- dkato
- Date:
- Tue Jul 24 08:46:48 2018 +0000
- Parent:
- 15:570acc3d2b89
- Commit message:
- Changed to be usable with EasyPlayback
Changed in this revision
diff -r 570acc3d2b89 -r 63d0cf9e117b EasyPlayback.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EasyPlayback.lib Tue Jul 24 08:46:48 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/dkato/code/EasyPlayback/#6c46c61630b3
diff -r 570acc3d2b89 -r 63d0cf9e117b EasyPlaybackPWM.lib --- a/EasyPlaybackPWM.lib Tue Jul 24 05:45:07 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/dkato/code/EasyPlaybackPWM/#41ab76b22961
diff -r 570acc3d2b89 -r 63d0cf9e117b PwmOutSpeaker.lib --- a/PwmOutSpeaker.lib Tue Jul 24 05:45:07 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/dkato/code/PwmOutSpeaker/#436529700217
diff -r 570acc3d2b89 -r 63d0cf9e117b main.cpp --- a/main.cpp Tue Jul 24 05:45:07 2018 +0000 +++ b/main.cpp Tue Jul 24 08:46:48 2018 +0000 @@ -1,14 +1,13 @@ #include "mbed.h" -#include "EasyPlaybackPWM.h" -#include "EasyDec_WavCnv2ch.h" #include "SdUsbConnect.h" +#include "EasyPlayback.h" +#include "EasyDec_WavCnv2ch.h" -#define FILE_NAME_LEN (64) +#define FNAME_LEN (64) #define MOUNT_NAME "storage" -#define TAG_BUFF_SIZE (64 + 1) //null-terminated static InterruptIn skip_btn(USER_BUTTON0); -static EasyPlaybackPWM AudioPlayer(P4_5, P4_7); +static EasyPlayback AudioPlayer(EasyPlayback::AUDIO_TPYE_PWM, P4_5, P4_7); static void skip_btn_fall(void) { AudioPlayer.skip(); @@ -17,39 +16,25 @@ int main() { DIR * d; struct dirent * p; - char file_path[sizeof("/"MOUNT_NAME"/") + FILE_NAME_LEN]; - - // decoder setting - AudioPlayer.add_decoder<EasyDec_WavCnv2ch>(".wav"); - AudioPlayer.add_decoder<EasyDec_WavCnv2ch>(".WAV"); - - // volume control - AudioPlayer.outputVolume(0.5); // Volume control (min:0.0 max:1.0) + char file_path[sizeof("/"MOUNT_NAME"/") + FNAME_LEN]; + SdUsbConnect storage(MOUNT_NAME); - // button setting - skip_btn.fall(&skip_btn_fall); + AudioPlayer.add_decoder<EasyDec_WavCnv2ch>(".wav"); // decoder setting + AudioPlayer.add_decoder<EasyDec_WavCnv2ch>(".WAV"); // decoder setting + AudioPlayer.outputVolume(0.5); // Volume control (min:0.0 max:1.0) + skip_btn.fall(&skip_btn_fall); // button setting - // wait for the storage device to be connected - printf("Finding a storage...\r\n"); - SdUsbConnect storage(MOUNT_NAME); - storage.wait_connect(); - printf("done\r\n"); - - while(1) { - // file search - d = opendir("/"MOUNT_NAME"/"); + while (1) { + storage.wait_connect(); + d = opendir("/"MOUNT_NAME"/"); // file search while ((p = readdir(d)) != NULL) { size_t len = strlen(p->d_name); - if (len < FILE_NAME_LEN) { - // make file path - sprintf(file_path, "/%s/%s", MOUNT_NAME, p->d_name); + if (len < FNAME_LEN) { + sprintf(file_path, "/%s/%s", MOUNT_NAME, p->d_name); // make file path printf("%s\r\n", file_path); - - // playback - AudioPlayer.play(file_path); + AudioPlayer.play(file_path); // playback } } closedir(d); } } -
diff -r 570acc3d2b89 -r 63d0cf9e117b mbed-gr-libs.lib --- a/mbed-gr-libs.lib Tue Jul 24 05:45:07 2018 +0000 +++ b/mbed-gr-libs.lib Tue Jul 24 08:46:48 2018 +0000 @@ -1,1 +1,1 @@ -https://github.com/d-kato/mbed-gr-libs/#96620c101d2ba348ef418a03f77928242503a718 +https://github.com/d-kato/mbed-gr-libs/#d921d611d596ecaebaab49070ef82450c583309c