Daiki Kato / Mbed OS GR-PEACH_Audio_WAV_PwmOut Featured

Dependencies:   EasyPlayback

Fork of GR-PEACH_Audio_WAV by Renesas

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.

/media/uploads/dkato/pwm_speaker_img.png

FormatWav file (RIFF format) ".wav"
Channel1ch and 2ch
Frequencies32kHz, 44.1kHz and 48kHz
Quantization bit rate8bits 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

Committer:
dkato
Date:
Tue Dec 20 07:28:04 2016 +0000
Revision:
10:e8f52c4aa394
Parent:
9:c7c0a97fdb7f
Change volume setting.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 9:c7c0a97fdb7f 1 /* mbed Microcontroller Library
dkato 9:c7c0a97fdb7f 2 * Copyright (c) 2006-2012 ARM Limited
dkato 9:c7c0a97fdb7f 3 *
dkato 9:c7c0a97fdb7f 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
dkato 9:c7c0a97fdb7f 5 * of this software and associated documentation files (the "Software"), to deal
dkato 9:c7c0a97fdb7f 6 * in the Software without restriction, including without limitation the rights
dkato 9:c7c0a97fdb7f 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
dkato 9:c7c0a97fdb7f 8 * copies of the Software, and to permit persons to whom the Software is
dkato 9:c7c0a97fdb7f 9 * furnished to do so, subject to the following conditions:
dkato 9:c7c0a97fdb7f 10 *
dkato 9:c7c0a97fdb7f 11 * The above copyright notice and this permission notice shall be included in
dkato 9:c7c0a97fdb7f 12 * all copies or substantial portions of the Software.
dkato 9:c7c0a97fdb7f 13 *
dkato 9:c7c0a97fdb7f 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
dkato 9:c7c0a97fdb7f 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
dkato 9:c7c0a97fdb7f 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
dkato 9:c7c0a97fdb7f 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
dkato 9:c7c0a97fdb7f 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
dkato 9:c7c0a97fdb7f 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
dkato 9:c7c0a97fdb7f 20 * SOFTWARE.
dkato 9:c7c0a97fdb7f 21 */
dkato 9:c7c0a97fdb7f 22 #ifndef MBED_SDFILESYSTEM_H
dkato 9:c7c0a97fdb7f 23 #define MBED_SDFILESYSTEM_H
dkato 9:c7c0a97fdb7f 24
dkato 9:c7c0a97fdb7f 25 #include "mbed.h"
dkato 9:c7c0a97fdb7f 26 #include "FATFileSystem.h"
dkato 9:c7c0a97fdb7f 27 #include <stdint.h>
dkato 9:c7c0a97fdb7f 28
dkato 9:c7c0a97fdb7f 29 /** Access the filesystem on an SD Card using SPI
dkato 9:c7c0a97fdb7f 30 *
dkato 9:c7c0a97fdb7f 31 * @code
dkato 9:c7c0a97fdb7f 32 * #include "mbed.h"
dkato 9:c7c0a97fdb7f 33 * #include "SDFileSystem.h"
dkato 9:c7c0a97fdb7f 34 *
dkato 9:c7c0a97fdb7f 35 * SDFileSystem sd(p5, p6, p7, p12, "sd"); // mosi, miso, sclk, cs
dkato 9:c7c0a97fdb7f 36 *
dkato 9:c7c0a97fdb7f 37 * int main() {
dkato 9:c7c0a97fdb7f 38 * FILE *fp = fopen("/sd/myfile.txt", "w");
dkato 9:c7c0a97fdb7f 39 * fprintf(fp, "Hello World!\n");
dkato 9:c7c0a97fdb7f 40 * fclose(fp);
dkato 9:c7c0a97fdb7f 41 * }
dkato 9:c7c0a97fdb7f 42 */
dkato 9:c7c0a97fdb7f 43 class SDFileSystem : public FATFileSystem {
dkato 9:c7c0a97fdb7f 44 public:
dkato 9:c7c0a97fdb7f 45
dkato 9:c7c0a97fdb7f 46 /** Create the File System for accessing an SD Card using SPI
dkato 9:c7c0a97fdb7f 47 *
dkato 9:c7c0a97fdb7f 48 * @param mosi SPI mosi pin connected to SD Card
dkato 9:c7c0a97fdb7f 49 * @param miso SPI miso pin conencted to SD Card
dkato 9:c7c0a97fdb7f 50 * @param sclk SPI sclk pin connected to SD Card
dkato 9:c7c0a97fdb7f 51 * @param cs DigitalOut pin used as SD Card chip select
dkato 9:c7c0a97fdb7f 52 * @param name The name used to access the virtual filesystem
dkato 9:c7c0a97fdb7f 53 */
dkato 9:c7c0a97fdb7f 54 SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name);
dkato 9:c7c0a97fdb7f 55 virtual int disk_initialize();
dkato 9:c7c0a97fdb7f 56 virtual int disk_status();
dkato 9:c7c0a97fdb7f 57 virtual int disk_read(uint8_t* buffer, uint32_t block_number, uint32_t count);
dkato 9:c7c0a97fdb7f 58 virtual int disk_write(const uint8_t* buffer, uint32_t block_number, uint32_t count);
dkato 9:c7c0a97fdb7f 59 virtual int disk_sync();
dkato 9:c7c0a97fdb7f 60 virtual uint32_t disk_sectors();
dkato 9:c7c0a97fdb7f 61
dkato 9:c7c0a97fdb7f 62 protected:
dkato 9:c7c0a97fdb7f 63
dkato 9:c7c0a97fdb7f 64 int _cmd(int cmd, int arg);
dkato 9:c7c0a97fdb7f 65 int _cmdx(int cmd, int arg);
dkato 9:c7c0a97fdb7f 66 int _cmd8();
dkato 9:c7c0a97fdb7f 67 int _cmd58();
dkato 9:c7c0a97fdb7f 68 int initialise_card();
dkato 9:c7c0a97fdb7f 69 int initialise_card_v1();
dkato 9:c7c0a97fdb7f 70 int initialise_card_v2();
dkato 9:c7c0a97fdb7f 71
dkato 9:c7c0a97fdb7f 72 int _read(uint8_t * buffer, uint32_t length);
dkato 9:c7c0a97fdb7f 73 int _write(const uint8_t *buffer, uint32_t length);
dkato 9:c7c0a97fdb7f 74 uint32_t _sd_sectors();
dkato 9:c7c0a97fdb7f 75 uint32_t _sectors;
dkato 9:c7c0a97fdb7f 76
dkato 9:c7c0a97fdb7f 77 void set_init_sck(uint32_t sck) { _init_sck = sck; }
dkato 9:c7c0a97fdb7f 78 // Note: The highest SPI clock rate is 20 MHz for MMC and 25 MHz for SD
dkato 9:c7c0a97fdb7f 79 void set_transfer_sck(uint32_t sck) { _transfer_sck = sck; }
dkato 9:c7c0a97fdb7f 80 uint32_t _init_sck;
dkato 9:c7c0a97fdb7f 81 uint32_t _transfer_sck;
dkato 9:c7c0a97fdb7f 82
dkato 9:c7c0a97fdb7f 83 SPI _spi;
dkato 9:c7c0a97fdb7f 84 DigitalOut _cs;
dkato 9:c7c0a97fdb7f 85 int cdv;
dkato 9:c7c0a97fdb7f 86 int _is_initialized;
dkato 9:c7c0a97fdb7f 87 };
dkato 9:c7c0a97fdb7f 88
dkato 9:c7c0a97fdb7f 89 #endif