Output the audio signal (*.bin) with filtering by IIR filter in the SD card using onboard CODEC. For *.wav file, F746_SD_WavPlayer and F746_SD_GraphicEqualiser are published on mbed. SD カードのオーディオ信号 (*.bin) を遮断周波数可変の IIR フィルタを通して,ボードに搭載されているCODEC で出力する.*.wav 形式のファイル用には,F746_SD_WavPlayer と F746_SD_GraphicEqualiser を mbed で公開している.

Dependencies:   BSP_DISCO_F746NG_patch_fixed F746_GUI LCD_DISCO_F746NG SDFileSystem_Warning_Fixed TS_DISCO_F746NG mbed

Committer:
MikamiUitOpen
Date:
Fri Apr 08 13:11:53 2016 +0000
Revision:
0:6748e3332e85
Child:
1:e891c9b4f980
1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 0:6748e3332e85 1 //--------------------------------------------------------------
MikamiUitOpen 0:6748e3332e85 2 // FileSelector class
MikamiUitOpen 0:6748e3332e85 3 // SD カード内のファイル名の一覧を表示し,ファイルを選択する
MikamiUitOpen 0:6748e3332e85 4 //
MikamiUitOpen 0:6748e3332e85 5 // 2016/04/05, Copyright (c) 2016 MIKAMI, Naoki
MikamiUitOpen 0:6748e3332e85 6 //--------------------------------------------------------------
MikamiUitOpen 0:6748e3332e85 7
MikamiUitOpen 0:6748e3332e85 8 #ifndef FILE_SELECTOR_HPP
MikamiUitOpen 0:6748e3332e85 9 #define FILE_SELECTOR_HPP
MikamiUitOpen 0:6748e3332e85 10
MikamiUitOpen 0:6748e3332e85 11 #include "mbed.h"
MikamiUitOpen 0:6748e3332e85 12 #include "Label.hpp"
MikamiUitOpen 0:6748e3332e85 13 #include "ButtonGroup.hpp"
MikamiUitOpen 0:6748e3332e85 14 #include "SD_BinaryReader.hpp"
MikamiUitOpen 0:6748e3332e85 15 #include "SDFileSystem.h"
MikamiUitOpen 0:6748e3332e85 16
MikamiUitOpen 0:6748e3332e85 17 namespace Mikami
MikamiUitOpen 0:6748e3332e85 18 {
MikamiUitOpen 0:6748e3332e85 19 class FileSelector
MikamiUitOpen 0:6748e3332e85 20 {
MikamiUitOpen 0:6748e3332e85 21 public:
MikamiUitOpen 0:6748e3332e85 22 FileSelector(uint8_t x0, uint8_t y0, int maxFiles,
MikamiUitOpen 0:6748e3332e85 23 int maxNameLength, SD_BinaryReader &reader)
MikamiUitOpen 0:6748e3332e85 24 : X_(x0), Y_(y0), W_H_(24), V_L_(36),
MikamiUitOpen 0:6748e3332e85 25 MAX_FILES_(maxFiles), MAX_NAME_LENGTH_(maxNameLength),
MikamiUitOpen 0:6748e3332e85 26 BASE_COLOR_(0xFF80FFA0), TOUCHED_COLOR_(0xFF80FFFF),
MikamiUitOpen 0:6748e3332e85 27 fileNames_(new string[maxFiles]),
MikamiUitOpen 0:6748e3332e85 28 lcd_(GuiBase::GetLcdPtr()),
MikamiUitOpen 0:6748e3332e85 29 sdReader_(reader), prev_(-1) {}
MikamiUitOpen 0:6748e3332e85 30
MikamiUitOpen 0:6748e3332e85 31 bool CreateTable()
MikamiUitOpen 0:6748e3332e85 32 {
MikamiUitOpen 0:6748e3332e85 33 DIR* dp = opendir("/sd");
MikamiUitOpen 0:6748e3332e85 34 fileCount_ = 0;
MikamiUitOpen 0:6748e3332e85 35 if (dp != NULL)
MikamiUitOpen 0:6748e3332e85 36 {
MikamiUitOpen 0:6748e3332e85 37 dirent* entry;
MikamiUitOpen 0:6748e3332e85 38 for (int n=0; n<256; n++)
MikamiUitOpen 0:6748e3332e85 39 {
MikamiUitOpen 0:6748e3332e85 40 entry = readdir(dp);
MikamiUitOpen 0:6748e3332e85 41 if (entry == NULL) break;
MikamiUitOpen 0:6748e3332e85 42
MikamiUitOpen 0:6748e3332e85 43 string strName = entry->d_name;
MikamiUitOpen 0:6748e3332e85 44 if ( (strName.find(".bin") != string::npos) ||
MikamiUitOpen 0:6748e3332e85 45 (strName.find(".BIN") != string::npos) )
MikamiUitOpen 0:6748e3332e85 46 {
MikamiUitOpen 0:6748e3332e85 47 sdReader_.Open(strName); // ファイルオープン
MikamiUitOpen 0:6748e3332e85 48 // 小さすぎるファイルは除外
MikamiUitOpen 0:6748e3332e85 49 if ((sdReader_.ReadSize()) > 4096)
MikamiUitOpen 0:6748e3332e85 50 {
MikamiUitOpen 0:6748e3332e85 51 fileNames_[fileCount_] = strName;
MikamiUitOpen 0:6748e3332e85 52 fileCount_++;
MikamiUitOpen 0:6748e3332e85 53 }
MikamiUitOpen 0:6748e3332e85 54 sdReader_.Close();
MikamiUitOpen 0:6748e3332e85 55 }
MikamiUitOpen 0:6748e3332e85 56 if (fileCount_ >= MAX_FILES_) break;
MikamiUitOpen 0:6748e3332e85 57 }
MikamiUitOpen 0:6748e3332e85 58 closedir(dp);
MikamiUitOpen 0:6748e3332e85 59 }
MikamiUitOpen 0:6748e3332e85 60 else
MikamiUitOpen 0:6748e3332e85 61 return false;
MikamiUitOpen 0:6748e3332e85 62
MikamiUitOpen 0:6748e3332e85 63 if (fileCount_ == 0) return false;
MikamiUitOpen 0:6748e3332e85 64
MikamiUitOpen 0:6748e3332e85 65 nonString_ = new string[fileCount_];
MikamiUitOpen 0:6748e3332e85 66 for (int n=0; n<fileCount_; n++) nonString_[n] = "";
MikamiUitOpen 0:6748e3332e85 67 rect_ = new ButtonGroup(X_, Y_, W_H_, W_H_, fileCount_,
MikamiUitOpen 0:6748e3332e85 68 nonString_, 0, V_L_-W_H_, 1,
MikamiUitOpen 0:6748e3332e85 69 -1, Font12, 0, GuiBase::ENUM_BACK,
MikamiUitOpen 0:6748e3332e85 70 BASE_COLOR_, TOUCHED_COLOR_);
MikamiUitOpen 0:6748e3332e85 71 for (int n=0; n<fileCount_; n++) rect_->Erase(n);
MikamiUitOpen 0:6748e3332e85 72 CreateLabels();
MikamiUitOpen 0:6748e3332e85 73
MikamiUitOpen 0:6748e3332e85 74 return true;
MikamiUitOpen 0:6748e3332e85 75 }
MikamiUitOpen 0:6748e3332e85 76
MikamiUitOpen 0:6748e3332e85 77 // ファイルを選択する
MikamiUitOpen 0:6748e3332e85 78 bool Select(string &fileName)
MikamiUitOpen 0:6748e3332e85 79 {
MikamiUitOpen 0:6748e3332e85 80 int n;
MikamiUitOpen 0:6748e3332e85 81 if (rect_->GetTouchedNumber(n))
MikamiUitOpen 0:6748e3332e85 82 {
MikamiUitOpen 0:6748e3332e85 83 fileNameLabels_[n]->Draw(DeleteBin(n), TOUCHED_COLOR_);
MikamiUitOpen 0:6748e3332e85 84 if ((prev_ >= 0) && (prev_ != n))
MikamiUitOpen 0:6748e3332e85 85 fileNameLabels_[prev_]->Draw(DeleteBin(prev_));
MikamiUitOpen 0:6748e3332e85 86 prev_ = n;
MikamiUitOpen 0:6748e3332e85 87 fileName = fileNames_[n];
MikamiUitOpen 0:6748e3332e85 88 return true;
MikamiUitOpen 0:6748e3332e85 89 }
MikamiUitOpen 0:6748e3332e85 90 else
MikamiUitOpen 0:6748e3332e85 91 return false;
MikamiUitOpen 0:6748e3332e85 92 }
MikamiUitOpen 0:6748e3332e85 93
MikamiUitOpen 0:6748e3332e85 94 // ファイルの一覧の表示
MikamiUitOpen 0:6748e3332e85 95 void DisplayFileList()
MikamiUitOpen 0:6748e3332e85 96 {
MikamiUitOpen 0:6748e3332e85 97 Erase(MAX_NAME_LENGTH_*((sFONT *)(&Font16))->Width, 270-Y_);
MikamiUitOpen 0:6748e3332e85 98 rect_->DrawAll();
MikamiUitOpen 0:6748e3332e85 99 for (int n=0; n<fileCount_; n++)
MikamiUitOpen 0:6748e3332e85 100 fileNameLabels_[n]->Draw(DeleteBin(n));
MikamiUitOpen 0:6748e3332e85 101 }
MikamiUitOpen 0:6748e3332e85 102
MikamiUitOpen 0:6748e3332e85 103 void Erase(uint16_t width, uint16_t height,
MikamiUitOpen 0:6748e3332e85 104 uint32_t color = GuiBase::ENUM_BACK)
MikamiUitOpen 0:6748e3332e85 105 {
MikamiUitOpen 0:6748e3332e85 106 lcd_->SetTextColor(color);
MikamiUitOpen 0:6748e3332e85 107 lcd_->FillRect(X_, Y_, width, height);
MikamiUitOpen 0:6748e3332e85 108 }
MikamiUitOpen 0:6748e3332e85 109
MikamiUitOpen 0:6748e3332e85 110 private:
MikamiUitOpen 0:6748e3332e85 111 const uint8_t X_, Y_, W_H_, V_L_;
MikamiUitOpen 0:6748e3332e85 112 const int MAX_FILES_;
MikamiUitOpen 0:6748e3332e85 113 const int MAX_NAME_LENGTH_;
MikamiUitOpen 0:6748e3332e85 114 const uint32_t BASE_COLOR_;
MikamiUitOpen 0:6748e3332e85 115 const uint32_t TOUCHED_COLOR_;
MikamiUitOpen 0:6748e3332e85 116
MikamiUitOpen 0:6748e3332e85 117 string *fileNames_;
MikamiUitOpen 0:6748e3332e85 118 string *nonString_;
MikamiUitOpen 0:6748e3332e85 119 ButtonGroup *rect_;
MikamiUitOpen 0:6748e3332e85 120 Label **fileNameLabels_;
MikamiUitOpen 0:6748e3332e85 121 LCD_DISCO_F746NG *lcd_;
MikamiUitOpen 0:6748e3332e85 122 SD_BinaryReader &sdReader_;
MikamiUitOpen 0:6748e3332e85 123 int fileCount_;
MikamiUitOpen 0:6748e3332e85 124 int prev_;
MikamiUitOpen 0:6748e3332e85 125
MikamiUitOpen 0:6748e3332e85 126 // Label を生成
MikamiUitOpen 0:6748e3332e85 127 void CreateLabels()
MikamiUitOpen 0:6748e3332e85 128 {
MikamiUitOpen 0:6748e3332e85 129 fileNameLabels_ = new Label *[fileCount_+1];
MikamiUitOpen 0:6748e3332e85 130 for (int n=0; n<fileCount_; n++)
MikamiUitOpen 0:6748e3332e85 131 fileNameLabels_[n] = new Label(X_+30, Y_+5+V_L_*n, "",
MikamiUitOpen 0:6748e3332e85 132 Label::LEFT, Font16,
MikamiUitOpen 0:6748e3332e85 133 BASE_COLOR_);
MikamiUitOpen 0:6748e3332e85 134 }
MikamiUitOpen 0:6748e3332e85 135
MikamiUitOpen 0:6748e3332e85 136 // 拡張子を削除
MikamiUitOpen 0:6748e3332e85 137 string DeleteBin(int n)
MikamiUitOpen 0:6748e3332e85 138 {
MikamiUitOpen 0:6748e3332e85 139 string name = fileNames_[n];
MikamiUitOpen 0:6748e3332e85 140 name.erase(name.find("."));
MikamiUitOpen 0:6748e3332e85 141 return name.substr(0, MAX_NAME_LENGTH_);
MikamiUitOpen 0:6748e3332e85 142 }
MikamiUitOpen 0:6748e3332e85 143
MikamiUitOpen 0:6748e3332e85 144 // disallow copy constructor and assignment operator
MikamiUitOpen 0:6748e3332e85 145 FileSelector(const FileSelector&);
MikamiUitOpen 0:6748e3332e85 146 FileSelector& operator=(const FileSelector&);
MikamiUitOpen 0:6748e3332e85 147 };
MikamiUitOpen 0:6748e3332e85 148 }
MikamiUitOpen 0:6748e3332e85 149 #endif // FILE_SELECTOR_HPP