GR-MANGO sample using mbed-os library from my repository.
sample_programs/sample_05_spdif_wav_playback.cpp@0:b4c1e32627f2, 2020-10-12 (annotated)
- Committer:
- RyoheiHagimoto
- Date:
- Mon Oct 12 02:25:49 2020 +0000
- Revision:
- 0:b4c1e32627f2
replaced mbed-os library
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| RyoheiHagimoto | 0:b4c1e32627f2 | 1 | /******************************************************************************* |
| RyoheiHagimoto | 0:b4c1e32627f2 | 2 | * DISCLAIMER |
| RyoheiHagimoto | 0:b4c1e32627f2 | 3 | * This software is supplied by Renesas Electronics Corporation and is only |
| RyoheiHagimoto | 0:b4c1e32627f2 | 4 | * intended for use with Renesas products. No other uses are authorized. This |
| RyoheiHagimoto | 0:b4c1e32627f2 | 5 | * software is owned by Renesas Electronics Corporation and is protected under |
| RyoheiHagimoto | 0:b4c1e32627f2 | 6 | * all applicable laws, including copyright laws. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 7 | * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING |
| RyoheiHagimoto | 0:b4c1e32627f2 | 8 | * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT |
| RyoheiHagimoto | 0:b4c1e32627f2 | 9 | * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE |
| RyoheiHagimoto | 0:b4c1e32627f2 | 10 | * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 11 | * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS |
| RyoheiHagimoto | 0:b4c1e32627f2 | 12 | * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE |
| RyoheiHagimoto | 0:b4c1e32627f2 | 13 | * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR |
| RyoheiHagimoto | 0:b4c1e32627f2 | 14 | * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE |
| RyoheiHagimoto | 0:b4c1e32627f2 | 15 | * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 16 | * Renesas reserves the right, without notice, to make changes to this software |
| RyoheiHagimoto | 0:b4c1e32627f2 | 17 | * and to discontinue the availability of this software. By using this software, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 18 | * you agree to the additional terms and conditions found by accessing the |
| RyoheiHagimoto | 0:b4c1e32627f2 | 19 | * following link: |
| RyoheiHagimoto | 0:b4c1e32627f2 | 20 | * http://www.renesas.com/disclaimer |
| RyoheiHagimoto | 0:b4c1e32627f2 | 21 | * |
| RyoheiHagimoto | 0:b4c1e32627f2 | 22 | * Copyright (C) 2019 Renesas Electronics Corporation. All rights reserved. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 23 | *******************************************************************************/ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 24 | #include "sample_select.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 25 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 26 | #if (SAMPLE_PROGRAM_NO == 5) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 27 | // SAMPLE_PROGRAM_NO 5 : SPDIF wav playback sample (use USB memory or SD card) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 28 | // |
| RyoheiHagimoto | 0:b4c1e32627f2 | 29 | // This sample will play a ".wav" file of the SD root folder. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 30 | // Wav file format : RIFF format, 1ch or 2ch, 44.1kHz, 16bits |
| RyoheiHagimoto | 0:b4c1e32627f2 | 31 | // In case of SAMPLE_PROGRAM_NO=5 : |
| RyoheiHagimoto | 0:b4c1e32627f2 | 32 | // Since TARGET_RZ_A2M_EVB has no connector and no suitable AUDIO_CLK has been entered, only pseudo-evaluation is executed. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 33 | // - Audio data is output from the PC_5 terminal. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 34 | // - Since AUDIO_CLK on the board is 11.2896 MHz, it operates at half the actual speed. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 35 | // - The AUDIO_CLK frequency required is 512 times as large as the sample frequency for audio data. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 36 | // (fs=44.1kHz : AUDIO_CLK=22.5792MHz, fs=48kHz : AUDIO_CLK=24.5760MHz) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 37 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 38 | #if !defined(TARGET_RZ_A2M_EVB) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 39 | #error "SPDIF is not supported." |
| RyoheiHagimoto | 0:b4c1e32627f2 | 40 | #endif |
| RyoheiHagimoto | 0:b4c1e32627f2 | 41 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 42 | #include "mbed.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 43 | #include "FATFileSystem.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 44 | #include "SdUsbConnect.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 45 | #include "EasyPlayback.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 46 | #include "EasyDec_WavCnv2ch.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 47 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 48 | static EasyPlayback AudioPlayer(EasyPlayback::AUDIO_TPYE_SPDIF); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 49 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 50 | #define FILE_NAME_LEN (64) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 51 | #define MOUNT_NAME "storage" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 52 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 53 | static InterruptIn skip_btn(USER_BUTTON0); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 54 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 55 | static void skip_btn_fall(void) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 56 | AudioPlayer.skip(); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 57 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 58 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 59 | int main() { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 60 | DIR * d; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 61 | struct dirent * p; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 62 | char file_path[sizeof("/" MOUNT_NAME "/") + FILE_NAME_LEN]; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 63 | SdUsbConnect storage(MOUNT_NAME); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 64 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 65 | // decoder setting |
| RyoheiHagimoto | 0:b4c1e32627f2 | 66 | AudioPlayer.add_decoder<EasyDec_WavCnv2ch>(".wav"); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 67 | AudioPlayer.add_decoder<EasyDec_WavCnv2ch>(".WAV"); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 68 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 69 | // button setting |
| RyoheiHagimoto | 0:b4c1e32627f2 | 70 | skip_btn.fall(&skip_btn_fall); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 71 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 72 | while (1) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 73 | // connect wait |
| RyoheiHagimoto | 0:b4c1e32627f2 | 74 | storage.wait_connect(); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 75 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 76 | // file search |
| RyoheiHagimoto | 0:b4c1e32627f2 | 77 | d = opendir("/" MOUNT_NAME "/"); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 78 | if (d != NULL) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 79 | while ((p = readdir(d)) != NULL) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 80 | size_t len = strlen(p->d_name); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 81 | if (len < FILE_NAME_LEN) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 82 | // make file path |
| RyoheiHagimoto | 0:b4c1e32627f2 | 83 | sprintf(file_path, "/%s/%s", MOUNT_NAME, p->d_name); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 84 | printf("%s\r\n", file_path); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 85 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 86 | // playback |
| RyoheiHagimoto | 0:b4c1e32627f2 | 87 | AudioPlayer.play(file_path); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 88 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 89 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 90 | closedir(d); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 91 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 92 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 93 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 94 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 95 | #endif |