This sample will play a ".wav" file of the USB root folder. Only RIFF format.
Fork of GR-PEACH_Audio_WAV by
Audio sample for GR-PEACH or GR-LYCHEE. This sample will play a ".wav" file in the root of USB memory or SD card. If the USER_BUTTON0 is pressed, the next song is played.
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
Please refer to following link about Audio/Camera Shield.
https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield
For GR-PEACH:
Format | Wav file (RIFF format) ".wav" |
Channel | 2ch |
Frequencies | 32kHz, 44.1kHz, 48kHz, 88.2kHz and 96kHz |
Quantization bit rate | 16bits, 24bits and 32bits |
For GR-LYCHEE:
Format | Wav file (RIFF format) ".wav" |
Channel | 2ch |
Frequencies | 32kHz, 44.1kHz and 48kHz |
Quantization bit rate | 16bits |
- Use USB0 of PEACH:
If you use the USB0 as USB Host, please close GR-PEACH's JP3.
Please select USB0 connector by the following configuration.
mbed_app.json
{ "config": { "usb-host-ch":{ "help": "(for GR-PEACH) 0:ch0 1:ch1", "value": "0" }, "audio-camera-shield":{ "help": "(for GR-PEACH) 0:not use 1:use", "value": "0" } } }
- Use USB1 of GR-PEACH:
If you use the USB1 as USB Host, please close Audio/Camera Shield's JP1.
Please select Audio/Camera Shield and USB1 connector by the following configuration.
mbed_app.json
{ "config": { "usb-host-ch":{ "help": "(for GR-PEACH) 0:ch0 1:ch1", "value": "1" }, "audio-camera-shield":{ "help": "(for GR-PEACH) 0:not use 1:use", "value": "1" } } }
main.cpp@0:a24aaf3a41b1, 2015-06-01 (annotated)
- Committer:
- dkato
- Date:
- Mon Jun 01 08:56:23 2015 +0000
- Revision:
- 0:a24aaf3a41b1
- Child:
- 1:967144cffd53
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dkato | 0:a24aaf3a41b1 | 1 | #include "mbed.h" |
dkato | 0:a24aaf3a41b1 | 2 | #include "TLV320_RBSP.h" |
dkato | 0:a24aaf3a41b1 | 3 | #include "USBHostMSD.h" |
dkato | 0:a24aaf3a41b1 | 4 | #if defined(TARGET_RZ_A1H) |
dkato | 0:a24aaf3a41b1 | 5 | #include "usb_host_setting.h" |
dkato | 0:a24aaf3a41b1 | 6 | #else |
dkato | 0:a24aaf3a41b1 | 7 | #define USB_HOST_CH 0 |
dkato | 0:a24aaf3a41b1 | 8 | #endif |
dkato | 0:a24aaf3a41b1 | 9 | |
dkato | 0:a24aaf3a41b1 | 10 | #if (USB_HOST_CH == 1) //Audio Shield USB1 |
dkato | 0:a24aaf3a41b1 | 11 | DigitalOut usb1en(P3_8); |
dkato | 0:a24aaf3a41b1 | 12 | #endif |
dkato | 0:a24aaf3a41b1 | 13 | DigitalIn button(USER_BUTTON0); |
dkato | 0:a24aaf3a41b1 | 14 | |
dkato | 0:a24aaf3a41b1 | 15 | #define READ_BUFF_SIZE (4096) |
dkato | 0:a24aaf3a41b1 | 16 | #define READ_BUFF_NUM (16) |
dkato | 0:a24aaf3a41b1 | 17 | #define MAIL_QUEUE_SIZE (READ_BUFF_NUM) |
dkato | 0:a24aaf3a41b1 | 18 | #define FILE_NAME_LEN (64) |
dkato | 0:a24aaf3a41b1 | 19 | #define INFO_TYPE_WRITE_END (0) |
dkato | 0:a24aaf3a41b1 | 20 | #define TEXT_SIZE (64) |
dkato | 0:a24aaf3a41b1 | 21 | |
dkato | 0:a24aaf3a41b1 | 22 | typedef struct { |
dkato | 0:a24aaf3a41b1 | 23 | void * p_data; |
dkato | 0:a24aaf3a41b1 | 24 | int32_t result; |
dkato | 0:a24aaf3a41b1 | 25 | } mail_t; |
dkato | 0:a24aaf3a41b1 | 26 | Mail<mail_t, MAIL_QUEUE_SIZE> mail_box; |
dkato | 0:a24aaf3a41b1 | 27 | |
dkato | 0:a24aaf3a41b1 | 28 | static uint8_t read_buff[READ_BUFF_NUM][READ_BUFF_SIZE] __attribute((section("NC_BSS"),aligned(4))); //4 bytes aligned! No cache memory |
dkato | 0:a24aaf3a41b1 | 29 | static uint8_t title_buf[TEXT_SIZE + 1]; |
dkato | 0:a24aaf3a41b1 | 30 | static uint8_t artist_buf[TEXT_SIZE + 1]; |
dkato | 0:a24aaf3a41b1 | 31 | static uint8_t album_buf[TEXT_SIZE + 1]; |
dkato | 0:a24aaf3a41b1 | 32 | static uint32_t music_data_size; |
dkato | 0:a24aaf3a41b1 | 33 | static uint32_t music_data_index; |
dkato | 0:a24aaf3a41b1 | 34 | |
dkato | 0:a24aaf3a41b1 | 35 | #define WRITE_BUFF_NUM (READ_BUFF_NUM) |
dkato | 0:a24aaf3a41b1 | 36 | #define FLD_PATH "/usb/" |
dkato | 0:a24aaf3a41b1 | 37 | |
dkato | 0:a24aaf3a41b1 | 38 | TLV320_RBSP audio(P3_13, P10_13, I2C_SDA, I2C_SCL, P4_4, P4_5, P4_7, P4_6, 0x80, WRITE_BUFF_NUM, READ_BUFF_NUM); // I2S Codec |
dkato | 0:a24aaf3a41b1 | 39 | |
dkato | 0:a24aaf3a41b1 | 40 | static void callback_audio_tans_end(void * p_data, int32_t result, void * p_app_data) { |
dkato | 0:a24aaf3a41b1 | 41 | mail_t *mail = mail_box.alloc(); |
dkato | 0:a24aaf3a41b1 | 42 | |
dkato | 0:a24aaf3a41b1 | 43 | if (result < 0) { |
dkato | 0:a24aaf3a41b1 | 44 | printf("error %d\n", result); |
dkato | 0:a24aaf3a41b1 | 45 | } |
dkato | 0:a24aaf3a41b1 | 46 | if (mail == NULL) { |
dkato | 0:a24aaf3a41b1 | 47 | printf("error mail alloc\n"); |
dkato | 0:a24aaf3a41b1 | 48 | } else { |
dkato | 0:a24aaf3a41b1 | 49 | mail->p_data = p_data; |
dkato | 0:a24aaf3a41b1 | 50 | mail->result = result; |
dkato | 0:a24aaf3a41b1 | 51 | mail_box.put(mail); |
dkato | 0:a24aaf3a41b1 | 52 | } |
dkato | 0:a24aaf3a41b1 | 53 | } |
dkato | 0:a24aaf3a41b1 | 54 | |
dkato | 0:a24aaf3a41b1 | 55 | static bool analyze_wav_heder(FILE * fp) { |
dkato | 0:a24aaf3a41b1 | 56 | bool result = false; |
dkato | 0:a24aaf3a41b1 | 57 | size_t read_size; |
dkato | 0:a24aaf3a41b1 | 58 | uint8_t wk_read_buff[36]; |
dkato | 0:a24aaf3a41b1 | 59 | uint8_t *data; |
dkato | 0:a24aaf3a41b1 | 60 | uint32_t chunk_size; |
dkato | 0:a24aaf3a41b1 | 61 | uint32_t sub_chunk_size; |
dkato | 0:a24aaf3a41b1 | 62 | uint32_t list_index_max; |
dkato | 0:a24aaf3a41b1 | 63 | bool list_ok = false; |
dkato | 0:a24aaf3a41b1 | 64 | uint32_t read_index = 0; |
dkato | 0:a24aaf3a41b1 | 65 | uint32_t data_index = 0; |
dkato | 0:a24aaf3a41b1 | 66 | int16_t wk_len; |
dkato | 0:a24aaf3a41b1 | 67 | uint16_t ch; |
dkato | 0:a24aaf3a41b1 | 68 | uint32_t sampling_rate; |
dkato | 0:a24aaf3a41b1 | 69 | uint16_t block_size; |
dkato | 0:a24aaf3a41b1 | 70 | |
dkato | 0:a24aaf3a41b1 | 71 | music_data_size = 0; |
dkato | 0:a24aaf3a41b1 | 72 | music_data_index = 0; |
dkato | 0:a24aaf3a41b1 | 73 | title_buf[0] = '\0'; |
dkato | 0:a24aaf3a41b1 | 74 | artist_buf[0] = '\0'; |
dkato | 0:a24aaf3a41b1 | 75 | album_buf[0] = '\0'; |
dkato | 0:a24aaf3a41b1 | 76 | |
dkato | 0:a24aaf3a41b1 | 77 | read_size = fread(&wk_read_buff[0], sizeof(char), 36, fp); |
dkato | 0:a24aaf3a41b1 | 78 | if (read_size < 36) { |
dkato | 0:a24aaf3a41b1 | 79 | // do nothing |
dkato | 0:a24aaf3a41b1 | 80 | } else if (memcmp(&wk_read_buff[0], "RIFF", 4) != 0) { |
dkato | 0:a24aaf3a41b1 | 81 | // do nothing |
dkato | 0:a24aaf3a41b1 | 82 | } else if (memcmp(&wk_read_buff[8], "WAVE", 4) != 0) { |
dkato | 0:a24aaf3a41b1 | 83 | // do nothing |
dkato | 0:a24aaf3a41b1 | 84 | } else if (memcmp(&wk_read_buff[12], "fmt ", 4) != 0) { |
dkato | 0:a24aaf3a41b1 | 85 | // do nothing |
dkato | 0:a24aaf3a41b1 | 86 | } else { |
dkato | 0:a24aaf3a41b1 | 87 | read_index += 36; |
dkato | 0:a24aaf3a41b1 | 88 | ch = ((uint32_t)wk_read_buff[22] << 0) + ((uint32_t)wk_read_buff[23] << 8); |
dkato | 0:a24aaf3a41b1 | 89 | sampling_rate = ((uint32_t)wk_read_buff[24] << 0) |
dkato | 0:a24aaf3a41b1 | 90 | + ((uint32_t)wk_read_buff[25] << 8) |
dkato | 0:a24aaf3a41b1 | 91 | + ((uint32_t)wk_read_buff[26] << 16) |
dkato | 0:a24aaf3a41b1 | 92 | + ((uint32_t)wk_read_buff[27] << 24); |
dkato | 0:a24aaf3a41b1 | 93 | block_size = ((uint32_t)wk_read_buff[34] << 0) + ((uint32_t)wk_read_buff[35] << 8); |
dkato | 0:a24aaf3a41b1 | 94 | if ((ch != 2) || (block_size != 16) || (sampling_rate != 44100)) { |
dkato | 0:a24aaf3a41b1 | 95 | return false; |
dkato | 0:a24aaf3a41b1 | 96 | } |
dkato | 0:a24aaf3a41b1 | 97 | while (1) { |
dkato | 0:a24aaf3a41b1 | 98 | read_size = fread(&wk_read_buff[0], sizeof(char), 8, fp); |
dkato | 0:a24aaf3a41b1 | 99 | read_index += 8; |
dkato | 0:a24aaf3a41b1 | 100 | if (read_size < 8) { |
dkato | 0:a24aaf3a41b1 | 101 | break; |
dkato | 0:a24aaf3a41b1 | 102 | } else { |
dkato | 0:a24aaf3a41b1 | 103 | chunk_size = ((uint32_t)wk_read_buff[4] << 0) |
dkato | 0:a24aaf3a41b1 | 104 | + ((uint32_t)wk_read_buff[5] << 8) |
dkato | 0:a24aaf3a41b1 | 105 | + ((uint32_t)wk_read_buff[6] << 16) |
dkato | 0:a24aaf3a41b1 | 106 | + ((uint32_t)wk_read_buff[7] << 24); |
dkato | 0:a24aaf3a41b1 | 107 | if (memcmp(&wk_read_buff[0], "data", 4) == 0) { |
dkato | 0:a24aaf3a41b1 | 108 | result = true; |
dkato | 0:a24aaf3a41b1 | 109 | music_data_size = chunk_size; |
dkato | 0:a24aaf3a41b1 | 110 | if (list_ok == true) { |
dkato | 0:a24aaf3a41b1 | 111 | break; |
dkato | 0:a24aaf3a41b1 | 112 | } else { |
dkato | 0:a24aaf3a41b1 | 113 | data_index = read_index; |
dkato | 0:a24aaf3a41b1 | 114 | fseek(fp, chunk_size, SEEK_CUR); |
dkato | 0:a24aaf3a41b1 | 115 | read_index += chunk_size; |
dkato | 0:a24aaf3a41b1 | 116 | } |
dkato | 0:a24aaf3a41b1 | 117 | } else if (memcmp(&wk_read_buff[0], "LIST", 4) == 0) { |
dkato | 0:a24aaf3a41b1 | 118 | list_ok = true; |
dkato | 0:a24aaf3a41b1 | 119 | list_index_max = read_index + chunk_size; |
dkato | 0:a24aaf3a41b1 | 120 | read_size = fread(&wk_read_buff[0], sizeof(char), 4, fp); |
dkato | 0:a24aaf3a41b1 | 121 | read_index += 4; |
dkato | 0:a24aaf3a41b1 | 122 | while (read_index < list_index_max) { |
dkato | 0:a24aaf3a41b1 | 123 | read_size = fread(&wk_read_buff[0], sizeof(char), 8, fp); |
dkato | 0:a24aaf3a41b1 | 124 | read_index += 8; |
dkato | 0:a24aaf3a41b1 | 125 | if (read_size < 8) { |
dkato | 0:a24aaf3a41b1 | 126 | break; |
dkato | 0:a24aaf3a41b1 | 127 | } else if (memcmp(&wk_read_buff[0], "INAM", 4) == 0) { |
dkato | 0:a24aaf3a41b1 | 128 | data = title_buf; |
dkato | 0:a24aaf3a41b1 | 129 | } else if (memcmp(&wk_read_buff[0], "IART", 4) == 0) { |
dkato | 0:a24aaf3a41b1 | 130 | data = artist_buf; |
dkato | 0:a24aaf3a41b1 | 131 | } else if (memcmp(&wk_read_buff[0], "IPRD", 4) == 0) { |
dkato | 0:a24aaf3a41b1 | 132 | data = album_buf; |
dkato | 0:a24aaf3a41b1 | 133 | } else { |
dkato | 0:a24aaf3a41b1 | 134 | data = NULL; |
dkato | 0:a24aaf3a41b1 | 135 | } |
dkato | 0:a24aaf3a41b1 | 136 | if (data != NULL) { |
dkato | 0:a24aaf3a41b1 | 137 | sub_chunk_size = ((uint32_t)wk_read_buff[4] << 0) |
dkato | 0:a24aaf3a41b1 | 138 | + ((uint32_t)wk_read_buff[5] << 8) |
dkato | 0:a24aaf3a41b1 | 139 | + ((uint32_t)wk_read_buff[6] << 16) |
dkato | 0:a24aaf3a41b1 | 140 | + ((uint32_t)wk_read_buff[7] << 24); |
dkato | 0:a24aaf3a41b1 | 141 | if (sub_chunk_size > TEXT_SIZE) { |
dkato | 0:a24aaf3a41b1 | 142 | wk_len = TEXT_SIZE; |
dkato | 0:a24aaf3a41b1 | 143 | } else { |
dkato | 0:a24aaf3a41b1 | 144 | wk_len = sub_chunk_size; |
dkato | 0:a24aaf3a41b1 | 145 | } |
dkato | 0:a24aaf3a41b1 | 146 | read_size = fread(data, sizeof(char), wk_len, fp); |
dkato | 0:a24aaf3a41b1 | 147 | read_index += sub_chunk_size; |
dkato | 0:a24aaf3a41b1 | 148 | fseek(fp, read_index, SEEK_SET); |
dkato | 0:a24aaf3a41b1 | 149 | data[wk_len] = '\0'; |
dkato | 0:a24aaf3a41b1 | 150 | } |
dkato | 0:a24aaf3a41b1 | 151 | } |
dkato | 0:a24aaf3a41b1 | 152 | if (data_index != 0) { |
dkato | 0:a24aaf3a41b1 | 153 | break; |
dkato | 0:a24aaf3a41b1 | 154 | } else { |
dkato | 0:a24aaf3a41b1 | 155 | fseek(fp, list_index_max, SEEK_SET); |
dkato | 0:a24aaf3a41b1 | 156 | } |
dkato | 0:a24aaf3a41b1 | 157 | } else { |
dkato | 0:a24aaf3a41b1 | 158 | fseek(fp, chunk_size, SEEK_CUR); |
dkato | 0:a24aaf3a41b1 | 159 | read_index += chunk_size; |
dkato | 0:a24aaf3a41b1 | 160 | } |
dkato | 0:a24aaf3a41b1 | 161 | } |
dkato | 0:a24aaf3a41b1 | 162 | } |
dkato | 0:a24aaf3a41b1 | 163 | |
dkato | 0:a24aaf3a41b1 | 164 | if (data_index != 0) { |
dkato | 0:a24aaf3a41b1 | 165 | fseek(fp, data_index, SEEK_SET); |
dkato | 0:a24aaf3a41b1 | 166 | } |
dkato | 0:a24aaf3a41b1 | 167 | } |
dkato | 0:a24aaf3a41b1 | 168 | |
dkato | 0:a24aaf3a41b1 | 169 | return result; |
dkato | 0:a24aaf3a41b1 | 170 | } |
dkato | 0:a24aaf3a41b1 | 171 | |
dkato | 0:a24aaf3a41b1 | 172 | static size_t get_audio_data(void *buf, size_t len, FILE * fp) { |
dkato | 0:a24aaf3a41b1 | 173 | if ((music_data_index + len) > music_data_size) { |
dkato | 0:a24aaf3a41b1 | 174 | len = music_data_size - music_data_index; |
dkato | 0:a24aaf3a41b1 | 175 | } |
dkato | 0:a24aaf3a41b1 | 176 | music_data_index += len; |
dkato | 0:a24aaf3a41b1 | 177 | |
dkato | 0:a24aaf3a41b1 | 178 | return fread(buf, sizeof(char), len, fp); |
dkato | 0:a24aaf3a41b1 | 179 | } |
dkato | 0:a24aaf3a41b1 | 180 | |
dkato | 0:a24aaf3a41b1 | 181 | void msd_task(void const *) { |
dkato | 0:a24aaf3a41b1 | 182 | FILE * fp = NULL; |
dkato | 0:a24aaf3a41b1 | 183 | DIR * d = NULL; |
dkato | 0:a24aaf3a41b1 | 184 | char file_path[sizeof(FLD_PATH) + FILE_NAME_LEN]; |
dkato | 0:a24aaf3a41b1 | 185 | rbsp_data_conf_t audio_write_data = {&callback_audio_tans_end, NULL}; |
dkato | 0:a24aaf3a41b1 | 186 | int cnt; |
dkato | 0:a24aaf3a41b1 | 187 | size_t read_size; |
dkato | 0:a24aaf3a41b1 | 188 | |
dkato | 0:a24aaf3a41b1 | 189 | #if (USB_HOST_CH == 1) //Audio Shield USB1 |
dkato | 0:a24aaf3a41b1 | 190 | //Audio Shield USB1 enable |
dkato | 0:a24aaf3a41b1 | 191 | usb1en = 1; //Outputs high level |
dkato | 0:a24aaf3a41b1 | 192 | Thread::wait(5); |
dkato | 0:a24aaf3a41b1 | 193 | usb1en = 0; //Outputs low level |
dkato | 0:a24aaf3a41b1 | 194 | #endif |
dkato | 0:a24aaf3a41b1 | 195 | |
dkato | 0:a24aaf3a41b1 | 196 | audio.power(0x02); // mic off |
dkato | 0:a24aaf3a41b1 | 197 | audio.inputVolume(0.7, 0.7); |
dkato | 0:a24aaf3a41b1 | 198 | |
dkato | 0:a24aaf3a41b1 | 199 | for (cnt = 0; cnt < READ_BUFF_NUM; cnt++) { |
dkato | 0:a24aaf3a41b1 | 200 | mail_t *mail = mail_box.alloc(); |
dkato | 0:a24aaf3a41b1 | 201 | |
dkato | 0:a24aaf3a41b1 | 202 | if (mail == NULL) { |
dkato | 0:a24aaf3a41b1 | 203 | printf("error mail alloc\n"); |
dkato | 0:a24aaf3a41b1 | 204 | } else { |
dkato | 0:a24aaf3a41b1 | 205 | mail->p_data = read_buff[cnt]; |
dkato | 0:a24aaf3a41b1 | 206 | mail->result = 0; |
dkato | 0:a24aaf3a41b1 | 207 | mail_box.put(mail); |
dkato | 0:a24aaf3a41b1 | 208 | } |
dkato | 0:a24aaf3a41b1 | 209 | } |
dkato | 0:a24aaf3a41b1 | 210 | |
dkato | 0:a24aaf3a41b1 | 211 | USBHostMSD msd("usb"); |
dkato | 0:a24aaf3a41b1 | 212 | |
dkato | 0:a24aaf3a41b1 | 213 | while(1) { |
dkato | 0:a24aaf3a41b1 | 214 | // try to connect a MSD device |
dkato | 0:a24aaf3a41b1 | 215 | while(!msd.connect()) { |
dkato | 0:a24aaf3a41b1 | 216 | Thread::wait(500); |
dkato | 0:a24aaf3a41b1 | 217 | } |
dkato | 0:a24aaf3a41b1 | 218 | |
dkato | 0:a24aaf3a41b1 | 219 | // in a loop, append a file |
dkato | 0:a24aaf3a41b1 | 220 | // if the device is disconnected, we try to connect it again |
dkato | 0:a24aaf3a41b1 | 221 | while(1) { |
dkato | 0:a24aaf3a41b1 | 222 | // if device disconnected, try to connect again |
dkato | 0:a24aaf3a41b1 | 223 | if (!msd.connected()) { |
dkato | 0:a24aaf3a41b1 | 224 | break; |
dkato | 0:a24aaf3a41b1 | 225 | } |
dkato | 0:a24aaf3a41b1 | 226 | if (fp == NULL) { |
dkato | 0:a24aaf3a41b1 | 227 | // file search |
dkato | 0:a24aaf3a41b1 | 228 | if (d == NULL) { |
dkato | 0:a24aaf3a41b1 | 229 | d = opendir(FLD_PATH); |
dkato | 0:a24aaf3a41b1 | 230 | } |
dkato | 0:a24aaf3a41b1 | 231 | struct dirent * p; |
dkato | 0:a24aaf3a41b1 | 232 | while ((p = readdir(d)) != NULL) { |
dkato | 0:a24aaf3a41b1 | 233 | size_t len = strlen(p->d_name); |
dkato | 0:a24aaf3a41b1 | 234 | if ((len > 4) && (len < FILE_NAME_LEN) && (memcmp(&p->d_name[len - 4], ".wav", 4) == 0)) { |
dkato | 0:a24aaf3a41b1 | 235 | strcpy(file_path, FLD_PATH); |
dkato | 0:a24aaf3a41b1 | 236 | strcat(file_path, p->d_name); |
dkato | 0:a24aaf3a41b1 | 237 | fp = fopen(file_path, "r"); |
dkato | 0:a24aaf3a41b1 | 238 | if (analyze_wav_heder(fp) == false) { |
dkato | 0:a24aaf3a41b1 | 239 | fclose(fp); |
dkato | 0:a24aaf3a41b1 | 240 | fp = NULL; |
dkato | 0:a24aaf3a41b1 | 241 | } else { |
dkato | 0:a24aaf3a41b1 | 242 | printf("File :%s\n", p->d_name); |
dkato | 0:a24aaf3a41b1 | 243 | printf("Title :%s\n", title_buf); |
dkato | 0:a24aaf3a41b1 | 244 | printf("Artist:%s\n", artist_buf); |
dkato | 0:a24aaf3a41b1 | 245 | printf("Album :%s\n", album_buf); |
dkato | 0:a24aaf3a41b1 | 246 | printf("\n"); |
dkato | 0:a24aaf3a41b1 | 247 | break; |
dkato | 0:a24aaf3a41b1 | 248 | } |
dkato | 0:a24aaf3a41b1 | 249 | } |
dkato | 0:a24aaf3a41b1 | 250 | } |
dkato | 0:a24aaf3a41b1 | 251 | if (p == NULL) { |
dkato | 0:a24aaf3a41b1 | 252 | closedir(d); |
dkato | 0:a24aaf3a41b1 | 253 | d = NULL; |
dkato | 0:a24aaf3a41b1 | 254 | } |
dkato | 0:a24aaf3a41b1 | 255 | } else { |
dkato | 0:a24aaf3a41b1 | 256 | // file read |
dkato | 0:a24aaf3a41b1 | 257 | osEvent evt = mail_box.get(); |
dkato | 0:a24aaf3a41b1 | 258 | if (evt.status == osEventMail) { |
dkato | 0:a24aaf3a41b1 | 259 | mail_t *mail = (mail_t *)evt.value.p; |
dkato | 0:a24aaf3a41b1 | 260 | |
dkato | 0:a24aaf3a41b1 | 261 | read_size = get_audio_data(mail->p_data, READ_BUFF_SIZE, fp); |
dkato | 0:a24aaf3a41b1 | 262 | if (read_size > 0) { |
dkato | 0:a24aaf3a41b1 | 263 | audio.write(mail->p_data, read_size, &audio_write_data); |
dkato | 0:a24aaf3a41b1 | 264 | mail_box.free(mail); |
dkato | 0:a24aaf3a41b1 | 265 | } else { |
dkato | 0:a24aaf3a41b1 | 266 | mail_box.put(mail); |
dkato | 0:a24aaf3a41b1 | 267 | } |
dkato | 0:a24aaf3a41b1 | 268 | } else { |
dkato | 0:a24aaf3a41b1 | 269 | read_size = 0; |
dkato | 0:a24aaf3a41b1 | 270 | } |
dkato | 0:a24aaf3a41b1 | 271 | |
dkato | 0:a24aaf3a41b1 | 272 | // file close |
dkato | 0:a24aaf3a41b1 | 273 | if ((read_size < READ_BUFF_SIZE) || (button == 0)) { |
dkato | 0:a24aaf3a41b1 | 274 | fclose(fp); |
dkato | 0:a24aaf3a41b1 | 275 | fp = NULL; |
dkato | 0:a24aaf3a41b1 | 276 | Thread::wait(500); |
dkato | 0:a24aaf3a41b1 | 277 | } |
dkato | 0:a24aaf3a41b1 | 278 | } |
dkato | 0:a24aaf3a41b1 | 279 | } |
dkato | 0:a24aaf3a41b1 | 280 | |
dkato | 0:a24aaf3a41b1 | 281 | // close check |
dkato | 0:a24aaf3a41b1 | 282 | if (fp != NULL) { |
dkato | 0:a24aaf3a41b1 | 283 | fclose(fp); |
dkato | 0:a24aaf3a41b1 | 284 | fp = NULL; |
dkato | 0:a24aaf3a41b1 | 285 | } |
dkato | 0:a24aaf3a41b1 | 286 | if (d != NULL) { |
dkato | 0:a24aaf3a41b1 | 287 | closedir(d); |
dkato | 0:a24aaf3a41b1 | 288 | d = NULL; |
dkato | 0:a24aaf3a41b1 | 289 | } |
dkato | 0:a24aaf3a41b1 | 290 | } |
dkato | 0:a24aaf3a41b1 | 291 | } |
dkato | 0:a24aaf3a41b1 | 292 | |
dkato | 0:a24aaf3a41b1 | 293 | int main() { |
dkato | 0:a24aaf3a41b1 | 294 | Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 8); |
dkato | 0:a24aaf3a41b1 | 295 | |
dkato | 0:a24aaf3a41b1 | 296 | while(1) { |
dkato | 0:a24aaf3a41b1 | 297 | Thread::wait(500); |
dkato | 0:a24aaf3a41b1 | 298 | } |
dkato | 0:a24aaf3a41b1 | 299 | } |