Output the audio signal with filtering by graphic equalizer in the *.wav file on the SD card using onboard CODEC. SD カードの *.wav ファイルのオーディオ信号をグラフィック・イコライザを通して,ボードに搭載されているCODEC で出力する.

Dependencies:   F746_GUI F746_SAI_IO SD_PlayerSkeleton FrequencyResponseDrawer

Committer:
MikamiUitOpen
Date:
Mon Apr 10 04:07:35 2017 +0000
Revision:
24:f78f9d0ac262
Parent:
16:cbb726ac20d8
25

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 16:cbb726ac20d8 1 /* mbed Microcontroller Library
MikamiUitOpen 16:cbb726ac20d8 2 * Copyright (c) 2006-2013 ARM Limited
MikamiUitOpen 16:cbb726ac20d8 3 *
MikamiUitOpen 16:cbb726ac20d8 4 * Licensed under the Apache License, Version 2.0 (the "License");
MikamiUitOpen 16:cbb726ac20d8 5 * you may not use this file except in compliance with the License.
MikamiUitOpen 16:cbb726ac20d8 6 * You may obtain a copy of the License at
MikamiUitOpen 16:cbb726ac20d8 7 *
MikamiUitOpen 16:cbb726ac20d8 8 * http://www.apache.org/licenses/LICENSE-2.0
MikamiUitOpen 16:cbb726ac20d8 9 *
MikamiUitOpen 16:cbb726ac20d8 10 * Unless required by applicable law or agreed to in writing, software
MikamiUitOpen 16:cbb726ac20d8 11 * distributed under the License is distributed on an "AS IS" BASIS,
MikamiUitOpen 16:cbb726ac20d8 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MikamiUitOpen 16:cbb726ac20d8 13 * See the License for the specific language governing permissions and
MikamiUitOpen 16:cbb726ac20d8 14 * limitations under the License.
MikamiUitOpen 16:cbb726ac20d8 15 */
MikamiUitOpen 16:cbb726ac20d8 16 #include "LocalFileSystem.h"
MikamiUitOpen 16:cbb726ac20d8 17
MikamiUitOpen 16:cbb726ac20d8 18 #if DEVICE_LOCALFILESYSTEM
MikamiUitOpen 16:cbb726ac20d8 19
MikamiUitOpen 16:cbb726ac20d8 20 #include "semihost_api.h"
MikamiUitOpen 16:cbb726ac20d8 21 #include <string.h>
MikamiUitOpen 16:cbb726ac20d8 22 #include <stdio.h>
MikamiUitOpen 16:cbb726ac20d8 23
MikamiUitOpen 16:cbb726ac20d8 24 namespace mbed {
MikamiUitOpen 16:cbb726ac20d8 25
MikamiUitOpen 16:cbb726ac20d8 26 /* Extension to FINFO type defined in RTL.h (in Keil RL) - adds 'create time'. */
MikamiUitOpen 16:cbb726ac20d8 27 typedef struct {
MikamiUitOpen 16:cbb726ac20d8 28 unsigned char hr; /* Hours [0..23] */
MikamiUitOpen 16:cbb726ac20d8 29 unsigned char min; /* Minutes [0..59] */
MikamiUitOpen 16:cbb726ac20d8 30 unsigned char sec; /* Seconds [0..59] */
MikamiUitOpen 16:cbb726ac20d8 31 unsigned char day; /* Day [1..31] */
MikamiUitOpen 16:cbb726ac20d8 32 unsigned char mon; /* Month [1..12] */
MikamiUitOpen 16:cbb726ac20d8 33 unsigned short year; /* Year [1980..2107] */
MikamiUitOpen 16:cbb726ac20d8 34 } FTIME;
MikamiUitOpen 16:cbb726ac20d8 35
MikamiUitOpen 16:cbb726ac20d8 36 typedef struct { /* File Search info record */
MikamiUitOpen 16:cbb726ac20d8 37 char name[32]; /* File name */
MikamiUitOpen 16:cbb726ac20d8 38 long size; /* File size in bytes */
MikamiUitOpen 16:cbb726ac20d8 39 int fileID; /* System File Identification */
MikamiUitOpen 16:cbb726ac20d8 40 FTIME create_time; /* Date & time file was created */
MikamiUitOpen 16:cbb726ac20d8 41 FTIME write_time; /* Date & time of last write */
MikamiUitOpen 16:cbb726ac20d8 42 } XFINFO;
MikamiUitOpen 16:cbb726ac20d8 43
MikamiUitOpen 16:cbb726ac20d8 44 #define RESERVED_FOR_USER_APPLICATIONS (0x100) /* 0x100 - 0x1ff */
MikamiUitOpen 16:cbb726ac20d8 45 #define USR_XFFIND (RESERVED_FOR_USER_APPLICATIONS + 0)
MikamiUitOpen 16:cbb726ac20d8 46
MikamiUitOpen 16:cbb726ac20d8 47 static int xffind (const char *pattern, XFINFO *info) {
MikamiUitOpen 16:cbb726ac20d8 48 unsigned param[4];
MikamiUitOpen 16:cbb726ac20d8 49
MikamiUitOpen 16:cbb726ac20d8 50 param[0] = (unsigned long)pattern;
MikamiUitOpen 16:cbb726ac20d8 51 param[1] = (unsigned long)strlen(pattern);
MikamiUitOpen 16:cbb726ac20d8 52 param[2] = (unsigned long)info;
MikamiUitOpen 16:cbb726ac20d8 53 param[3] = (unsigned long)sizeof(XFINFO);
MikamiUitOpen 16:cbb726ac20d8 54
MikamiUitOpen 16:cbb726ac20d8 55 return __semihost(USR_XFFIND, param);
MikamiUitOpen 16:cbb726ac20d8 56 }
MikamiUitOpen 16:cbb726ac20d8 57
MikamiUitOpen 16:cbb726ac20d8 58 #define OPEN_R 0
MikamiUitOpen 16:cbb726ac20d8 59 #define OPEN_B 1
MikamiUitOpen 16:cbb726ac20d8 60 #define OPEN_PLUS 2
MikamiUitOpen 16:cbb726ac20d8 61 #define OPEN_W 4
MikamiUitOpen 16:cbb726ac20d8 62 #define OPEN_A 8
MikamiUitOpen 16:cbb726ac20d8 63 #define OPEN_INVALID -1
MikamiUitOpen 16:cbb726ac20d8 64
MikamiUitOpen 16:cbb726ac20d8 65 int posix_to_semihost_open_flags(int flags) {
MikamiUitOpen 16:cbb726ac20d8 66 /* POSIX flags -> semihosting open mode */
MikamiUitOpen 16:cbb726ac20d8 67 int openmode;
MikamiUitOpen 16:cbb726ac20d8 68 if (flags & O_RDWR) {
MikamiUitOpen 16:cbb726ac20d8 69 /* a plus mode */
MikamiUitOpen 16:cbb726ac20d8 70 openmode = OPEN_PLUS;
MikamiUitOpen 16:cbb726ac20d8 71 if (flags & O_APPEND) {
MikamiUitOpen 16:cbb726ac20d8 72 openmode |= OPEN_A;
MikamiUitOpen 16:cbb726ac20d8 73 } else if (flags & O_TRUNC) {
MikamiUitOpen 16:cbb726ac20d8 74 openmode |= OPEN_W;
MikamiUitOpen 16:cbb726ac20d8 75 } else {
MikamiUitOpen 16:cbb726ac20d8 76 openmode |= OPEN_R;
MikamiUitOpen 16:cbb726ac20d8 77 }
MikamiUitOpen 16:cbb726ac20d8 78 } else if (flags & O_WRONLY) {
MikamiUitOpen 16:cbb726ac20d8 79 /* write or append */
MikamiUitOpen 16:cbb726ac20d8 80 if (flags & O_APPEND) {
MikamiUitOpen 16:cbb726ac20d8 81 openmode = OPEN_A;
MikamiUitOpen 16:cbb726ac20d8 82 } else {
MikamiUitOpen 16:cbb726ac20d8 83 openmode = OPEN_W;
MikamiUitOpen 16:cbb726ac20d8 84 }
MikamiUitOpen 16:cbb726ac20d8 85 } else if (flags == O_RDONLY) {
MikamiUitOpen 16:cbb726ac20d8 86 /* read mode */
MikamiUitOpen 16:cbb726ac20d8 87 openmode = OPEN_R;
MikamiUitOpen 16:cbb726ac20d8 88 } else {
MikamiUitOpen 16:cbb726ac20d8 89 /* invalid flags */
MikamiUitOpen 16:cbb726ac20d8 90 openmode = OPEN_INVALID;
MikamiUitOpen 16:cbb726ac20d8 91 }
MikamiUitOpen 16:cbb726ac20d8 92
MikamiUitOpen 16:cbb726ac20d8 93 return openmode;
MikamiUitOpen 16:cbb726ac20d8 94 }
MikamiUitOpen 16:cbb726ac20d8 95
MikamiUitOpen 16:cbb726ac20d8 96 FILEHANDLE local_file_open(const char* name, int flags) {
MikamiUitOpen 16:cbb726ac20d8 97 int openmode = posix_to_semihost_open_flags(flags);
MikamiUitOpen 16:cbb726ac20d8 98 if (openmode == OPEN_INVALID) {
MikamiUitOpen 16:cbb726ac20d8 99 return (FILEHANDLE)NULL;
MikamiUitOpen 16:cbb726ac20d8 100 }
MikamiUitOpen 16:cbb726ac20d8 101
MikamiUitOpen 16:cbb726ac20d8 102 FILEHANDLE fh = semihost_open(name, openmode);
MikamiUitOpen 16:cbb726ac20d8 103 if (fh == -1) {
MikamiUitOpen 16:cbb726ac20d8 104 return (FILEHANDLE)NULL;
MikamiUitOpen 16:cbb726ac20d8 105 }
MikamiUitOpen 16:cbb726ac20d8 106
MikamiUitOpen 16:cbb726ac20d8 107 return fh;
MikamiUitOpen 16:cbb726ac20d8 108 }
MikamiUitOpen 16:cbb726ac20d8 109
MikamiUitOpen 16:cbb726ac20d8 110 LocalFileHandle::LocalFileHandle(FILEHANDLE fh) : _fh(fh), pos(0) {
MikamiUitOpen 16:cbb726ac20d8 111 }
MikamiUitOpen 16:cbb726ac20d8 112
MikamiUitOpen 16:cbb726ac20d8 113 int LocalFileHandle::close() {
MikamiUitOpen 16:cbb726ac20d8 114 int retval = semihost_close(_fh);
MikamiUitOpen 16:cbb726ac20d8 115 delete this;
MikamiUitOpen 16:cbb726ac20d8 116 return retval;
MikamiUitOpen 16:cbb726ac20d8 117 }
MikamiUitOpen 16:cbb726ac20d8 118
MikamiUitOpen 16:cbb726ac20d8 119 ssize_t LocalFileHandle::write(const void *buffer, size_t length) {
MikamiUitOpen 16:cbb726ac20d8 120 ssize_t n = semihost_write(_fh, (const unsigned char*)buffer, length, 0); // number of characters not written
MikamiUitOpen 16:cbb726ac20d8 121 n = length - n; // number of characters written
MikamiUitOpen 16:cbb726ac20d8 122 pos += n;
MikamiUitOpen 16:cbb726ac20d8 123 return n;
MikamiUitOpen 16:cbb726ac20d8 124 }
MikamiUitOpen 16:cbb726ac20d8 125
MikamiUitOpen 16:cbb726ac20d8 126 ssize_t LocalFileHandle::read(void *buffer, size_t length) {
MikamiUitOpen 16:cbb726ac20d8 127 ssize_t n = semihost_read(_fh, (unsigned char*)buffer, length, 0); // number of characters not read
MikamiUitOpen 16:cbb726ac20d8 128 n = length - n; // number of characters read
MikamiUitOpen 16:cbb726ac20d8 129 pos += n;
MikamiUitOpen 16:cbb726ac20d8 130 return n;
MikamiUitOpen 16:cbb726ac20d8 131 }
MikamiUitOpen 16:cbb726ac20d8 132
MikamiUitOpen 16:cbb726ac20d8 133 int LocalFileHandle::isatty() {
MikamiUitOpen 16:cbb726ac20d8 134 return semihost_istty(_fh);
MikamiUitOpen 16:cbb726ac20d8 135 }
MikamiUitOpen 16:cbb726ac20d8 136
MikamiUitOpen 16:cbb726ac20d8 137 off_t LocalFileHandle::lseek(off_t position, int whence) {
MikamiUitOpen 16:cbb726ac20d8 138 if (whence == SEEK_CUR) {
MikamiUitOpen 16:cbb726ac20d8 139 position += pos;
MikamiUitOpen 16:cbb726ac20d8 140 } else if (whence == SEEK_END) {
MikamiUitOpen 16:cbb726ac20d8 141 position += semihost_flen(_fh);
MikamiUitOpen 16:cbb726ac20d8 142 } /* otherwise SEEK_SET, so position is fine */
MikamiUitOpen 16:cbb726ac20d8 143
MikamiUitOpen 16:cbb726ac20d8 144 /* Always seems to return -1, so just ignore for now. */
MikamiUitOpen 16:cbb726ac20d8 145 semihost_seek(_fh, position);
MikamiUitOpen 16:cbb726ac20d8 146 pos = position;
MikamiUitOpen 16:cbb726ac20d8 147 return position;
MikamiUitOpen 16:cbb726ac20d8 148 }
MikamiUitOpen 16:cbb726ac20d8 149
MikamiUitOpen 16:cbb726ac20d8 150 int LocalFileHandle::fsync() {
MikamiUitOpen 16:cbb726ac20d8 151 return semihost_ensure(_fh);
MikamiUitOpen 16:cbb726ac20d8 152 }
MikamiUitOpen 16:cbb726ac20d8 153
MikamiUitOpen 16:cbb726ac20d8 154 off_t LocalFileHandle::flen() {
MikamiUitOpen 16:cbb726ac20d8 155 return semihost_flen(_fh);
MikamiUitOpen 16:cbb726ac20d8 156 }
MikamiUitOpen 16:cbb726ac20d8 157
MikamiUitOpen 16:cbb726ac20d8 158 class LocalDirHandle : public DirHandle {
MikamiUitOpen 16:cbb726ac20d8 159
MikamiUitOpen 16:cbb726ac20d8 160 public:
MikamiUitOpen 16:cbb726ac20d8 161 struct dirent cur_entry;
MikamiUitOpen 16:cbb726ac20d8 162 XFINFO info;
MikamiUitOpen 16:cbb726ac20d8 163
MikamiUitOpen 16:cbb726ac20d8 164 LocalDirHandle() : cur_entry(), info() {
MikamiUitOpen 16:cbb726ac20d8 165 }
MikamiUitOpen 16:cbb726ac20d8 166
MikamiUitOpen 16:cbb726ac20d8 167 virtual int closedir() {
MikamiUitOpen 16:cbb726ac20d8 168 delete this;
MikamiUitOpen 16:cbb726ac20d8 169 return 0;
MikamiUitOpen 16:cbb726ac20d8 170 }
MikamiUitOpen 16:cbb726ac20d8 171
MikamiUitOpen 16:cbb726ac20d8 172 virtual struct dirent *readdir() {
MikamiUitOpen 16:cbb726ac20d8 173 if (xffind("*", &info)!=0) {
MikamiUitOpen 16:cbb726ac20d8 174 return NULL;
MikamiUitOpen 16:cbb726ac20d8 175 }
MikamiUitOpen 16:cbb726ac20d8 176 memcpy(cur_entry.d_name, info.name, sizeof(info.name));
MikamiUitOpen 16:cbb726ac20d8 177 return &cur_entry;
MikamiUitOpen 16:cbb726ac20d8 178 }
MikamiUitOpen 16:cbb726ac20d8 179
MikamiUitOpen 16:cbb726ac20d8 180 virtual void rewinddir() {
MikamiUitOpen 16:cbb726ac20d8 181 info.fileID = 0;
MikamiUitOpen 16:cbb726ac20d8 182 }
MikamiUitOpen 16:cbb726ac20d8 183
MikamiUitOpen 16:cbb726ac20d8 184 virtual off_t telldir() {
MikamiUitOpen 16:cbb726ac20d8 185 return info.fileID;
MikamiUitOpen 16:cbb726ac20d8 186 }
MikamiUitOpen 16:cbb726ac20d8 187
MikamiUitOpen 16:cbb726ac20d8 188 virtual void seekdir(off_t offset) {
MikamiUitOpen 16:cbb726ac20d8 189 info.fileID = offset;
MikamiUitOpen 16:cbb726ac20d8 190 }
MikamiUitOpen 16:cbb726ac20d8 191 };
MikamiUitOpen 16:cbb726ac20d8 192
MikamiUitOpen 16:cbb726ac20d8 193 FileHandle *LocalFileSystem::open(const char* name, int flags) {
MikamiUitOpen 16:cbb726ac20d8 194 /* reject filenames with / in them */
MikamiUitOpen 16:cbb726ac20d8 195 for (const char *tmp = name; *tmp; tmp++) {
MikamiUitOpen 16:cbb726ac20d8 196 if (*tmp == '/') {
MikamiUitOpen 16:cbb726ac20d8 197 return NULL;
MikamiUitOpen 16:cbb726ac20d8 198 }
MikamiUitOpen 16:cbb726ac20d8 199 }
MikamiUitOpen 16:cbb726ac20d8 200
MikamiUitOpen 16:cbb726ac20d8 201 int openmode = posix_to_semihost_open_flags(flags);
MikamiUitOpen 16:cbb726ac20d8 202 if (openmode == OPEN_INVALID) {
MikamiUitOpen 16:cbb726ac20d8 203 return NULL;
MikamiUitOpen 16:cbb726ac20d8 204 }
MikamiUitOpen 16:cbb726ac20d8 205
MikamiUitOpen 16:cbb726ac20d8 206 FILEHANDLE fh = semihost_open(name, openmode);
MikamiUitOpen 16:cbb726ac20d8 207 if (fh == -1) {
MikamiUitOpen 16:cbb726ac20d8 208 return NULL;
MikamiUitOpen 16:cbb726ac20d8 209 }
MikamiUitOpen 16:cbb726ac20d8 210 return new LocalFileHandle(fh);
MikamiUitOpen 16:cbb726ac20d8 211 }
MikamiUitOpen 16:cbb726ac20d8 212
MikamiUitOpen 16:cbb726ac20d8 213 int LocalFileSystem::remove(const char *filename) {
MikamiUitOpen 16:cbb726ac20d8 214 return semihost_remove(filename);
MikamiUitOpen 16:cbb726ac20d8 215 }
MikamiUitOpen 16:cbb726ac20d8 216
MikamiUitOpen 16:cbb726ac20d8 217 DirHandle *LocalFileSystem::opendir(const char *name) {
MikamiUitOpen 16:cbb726ac20d8 218 return new LocalDirHandle();
MikamiUitOpen 16:cbb726ac20d8 219 }
MikamiUitOpen 16:cbb726ac20d8 220
MikamiUitOpen 16:cbb726ac20d8 221 } // namespace mbed
MikamiUitOpen 16:cbb726ac20d8 222
MikamiUitOpen 16:cbb726ac20d8 223 #endif